#include "cameraconfig.h"
#include <mil.h>
#include <stdlib.h>
#include "mil3dcam_pfocus.h"
#include "pfocuscamera.h"
void PrintHeader()
{
MosPrintf(MIL_TEXT("[EXAMPLE NAME]\n")
MIL_TEXT("PhotonFocus_MV_D1024E_3D01_160_CL\n\n")
MIL_TEXT("[SYNOPSIS]\n")
MIL_TEXT("This program calibrates a 3d reconstruction setup with a PhotonFocus\n")
MIL_TEXT("3d camera and scans an object to generate its depth map.\n\n")
MIL_TEXT("[MODULES USED]\n")
MIL_TEXT("Modules used: application, system, display, digitizer, buffer, graphic,\n")
MIL_TEXT(" image processing, calibration, 3d reconstruction.\n\n")
MIL_TEXT("Press <Enter> to start.\n\n"));
MosGetch();
}
#define NB_DIG_PROCESS_BUFFERS 2
#define NB_GRABS 300
#define NUMBER_OF_CALIBRATION_DEPTHS 5
static const double CORRECTED_DEPTHS[NUMBER_OF_CALIBRATION_DEPTHS] =
{0.0, 12.0, 24.0, 36.0, 48.0};
#define SCALE_FACTOR 1000.0
#define GRID_NB_ROWS 12
#define GRID_NB_COLS 13
#define GRID_ROW_SPACING 10.0
#define GRID_COL_SPACING 10.0
#define DEPTH_MAP_SIZE_X 512
#define DEPTH_MAP_SIZE_Y 240
#define GAP_DEPTH 1.5
#define CONVEYOR_SPEED 20000.0
#if !USE_REAL_CAMERA
#define EXAMPLE_IMAGE_PATH M_IMAGE_PATH MIL_TEXT("PhotonFocus_MV_D1024E_3D01_160_CL/")
static const MIL_TEXT_CHAR* RefPlaneFilenames[NUMBER_OF_CALIBRATION_DEPTHS] =
{
EXAMPLE_IMAGE_PATH MIL_TEXT("calibplane0.mim"),
EXAMPLE_IMAGE_PATH MIL_TEXT("calibplane1.mim"),
EXAMPLE_IMAGE_PATH MIL_TEXT("calibplane2.mim"),
EXAMPLE_IMAGE_PATH MIL_TEXT("calibplane3.mim"),
EXAMPLE_IMAGE_PATH MIL_TEXT("calibplane4.mim")
};
static const MIL_TEXT_CHAR* CalibGridFilename = EXAMPLE_IMAGE_PATH MIL_TEXT("CalibGrid.mim");
static const MIL_TEXT_CHAR* CalibLineFilename = EXAMPLE_IMAGE_PATH MIL_TEXT("CalibLine.mim");
static const MIL_TEXT_CHAR* ScanPosFilename = EXAMPLE_IMAGE_PATH MIL_TEXT("ScanPosition.mim");
static const MIL_TEXT_CHAR* ScanIntFilename = EXAMPLE_IMAGE_PATH MIL_TEXT("ScanIntensity.mim");
#endif
void PFocusExample(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_INT ContextType);
void FatalError(const MIL_TEXT_CHAR* pMsg);
void SwitchToMeasure(int CameraPort, MIL_ID MilDigitizer);
void SwitchToImage(int CameraPort, MIL_ID MilDigitizer);
void DisplayLaserLine(MIL_ID MilDisplay,
MIL_ID MilPositionLine,
MIL_ID MilIntensityLine,
MIL_ID MilMeasImage);
void DisplayCalibrationPoints(MIL_ID MilDisplay,
MIL_ID MilCalGridImage,
MIL_ID MilCalibration);
MIL_INT MFTYPE AddScanProcFct(MIL_INT HookType, MIL_ID MilEvent, void* UserDataPtr);
struct AddScanProcFctDataStruct
{
MIL_ID MilLaser;
MIL_ID MilScan;
MIL_INT PointCloudLabel;
MIL_ID MilPositionImage;
MIL_ID MilIntensityImage;
PFocusParams* ConvParamsPtr;
};
int MosMain(void)
{
PrintHeader();
#if USE_REAL_CAMERA
MIL_CONST_TEXT_PTR SystemDescriptor = M_SYSTEM_DEFAULT;
#else
MIL_CONST_TEXT_PTR SystemDescriptor = M_SYSTEM_HOST;
#endif
MIL_ID MilApplication = MappAlloc(M_NULL, M_DEFAULT, M_NULL);
MIL_ID MilSystem = MsysAlloc(M_DEFAULT, SystemDescriptor, M_DEFAULT, M_DEFAULT, M_NULL);
MIL_ID MilDisplay = MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, M_NULL);
PFocusExample(MilSystem, MilDisplay, M_DEPTH_CORRECTION);
PFocusExample(MilSystem, MilDisplay, M_CALIBRATED_CAMERA_LINEAR_MOTION);
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);
return 0;
}
void PFocusExample(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_INT ContextType)
{
MIL_ID MilDigitizer,
MilImage,
MilMeasImage,
MilCalGridImage,
MilPeakImage[NB_DIG_PROCESS_BUFFERS],
MilPositionLine,
MilIntensityLine,
MilCalibration,
MilDepthMap,
MilIntensityMap,
MilLaser,
MilCalibScan,
MilScan;
MIL_INT n,
Ret,
SizeBit;
MosPrintf(MIL_TEXT("\n3D RECONSTRUCTION USING PHOTONFOCUS 3D CAMERA:\n"));
MosPrintf(MIL_TEXT("----------------------------------------------\n\n"));
MosPrintf(MIL_TEXT("This program calibrates a 3d reconstruction setup with a\n"));
MosPrintf(MIL_TEXT("PhotonFocus 3d camera and scans an object to generate its\n"));
MosPrintf(MIL_TEXT("depth map.\n\n"));
if (ContextType == M_DEPTH_CORRECTION)
MosPrintf(MIL_TEXT("3dmap M_DEPTH_CORRECTION mode is used.\n\n"));
else
MosPrintf(MIL_TEXT("3dmap M_CALIBRATED_CAMERA_LINEAR_MOTION mode is used.\n\n"));
Ret = InitCamera(CAMERA_COM_PORT);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to initialize camera.\n"));
Ret = SwitchCameraToMeasure(CAMERA_COM_PORT,
PFOCUS_MEAS_OFFSET_X,
PFOCUS_MEAS_OFFSET_Y,
PFOCUS_MEAS_SIZE_X,
PFOCUS_MEAS_SIZE_Y);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to set camera parameters.\n"));
PFocusParams ConvParams;
Ret = FillParams(CAMERA_COM_PORT, &ConvParams);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to inquire camera parameters.\n"));
SizeBit = (ConvParams.DataResolution == 8 ? 8 : 16);
#if USE_REAL_CAMERA
MIL_INT GrabAttr = M_GRAB;
#else
MIL_INT GrabAttr = 0;
#endif
for (n = 0; n < NB_DIG_PROCESS_BUFFERS; ++n)
{
MbufAlloc2d(MilSystem, PFOCUS_MEAS_SIZE_X+PFOCUS_3D_DATA_WIDTH, PFOCUS_MEAS_SIZE_Y,
SizeBit+M_UNSIGNED, M_IMAGE+M_PROC+GrabAttr, &MilPeakImage[n]);
}
MbufAlloc2d(MilSystem, PFOCUS_IMAGE_SIZE_X, PFOCUS_IMAGE_SIZE_Y,
SizeBit+M_UNSIGNED, M_IMAGE+M_PROC+GrabAttr+M_DISP, &MilImage);
MbufAlloc2d(MilSystem, PFOCUS_IMAGE_SIZE_X, PFOCUS_IMAGE_SIZE_Y,
SizeBit+M_UNSIGNED, M_IMAGE+M_PROC+GrabAttr+M_DISP, &MilCalGridImage);
MIL_INT NbDetectedLaserPixels = PFOCUS_MEAS_SIZE_Y;
if (ConvParams.StatusLine == STATUS_LINE_ENABLED)
NbDetectedLaserPixels -= 1;
MbufAlloc2d(MilSystem, PFOCUS_MEAS_SIZE_X, NbDetectedLaserPixels,
SizeBit+M_UNSIGNED, M_IMAGE+M_PROC+GrabAttr+M_DISP,
&MilMeasImage);
MbufAlloc2d(M_DEFAULT_HOST, NbDetectedLaserPixels, 1,
PFOCUS_DEPTH_SIZEBIT+M_UNSIGNED, M_IMAGE+M_PROC, &MilPositionLine);
MbufAlloc2d(M_DEFAULT_HOST, NbDetectedLaserPixels, 1,
SizeBit+M_UNSIGNED, M_IMAGE+M_PROC, &MilIntensityLine);
M3dmapAlloc(MilSystem, M_LASER, ContextType, &MilLaser);
M3dmapControl(MilLaser, M_CONTEXT, M_EXTRACTION_FIXED_POINT, PFOCUS_FIXED_POINT);
MIL_ID LocatePeakContextId;
M3dmapInquire(MilLaser, M_CONTEXT, M_LOCATE_PEAK_1D_CONTEXT_ID+M_TYPE_MIL_ID, &LocatePeakContextId);
MimControl(LocatePeakContextId, M_SCAN_LANE_DIRECTION, M_HORIZONTAL);
if (ContextType == M_CALIBRATED_CAMERA_LINEAR_MOTION)
{
double ConveyorSpeed = 1.0e-9 * ConvParams.CycleTimeMicroseconds * CONVEYOR_SPEED;
M3dmapControl(MilLaser, M_DEFAULT, M_EXTRACTION_CHILD_OFFSET_X,
PFOCUS_MEAS_OFFSET_X-PFOCUS_IMAGE_OFFSET_X);
M3dmapControl(MilLaser, M_DEFAULT, M_EXTRACTION_CHILD_OFFSET_Y,
PFOCUS_MEAS_OFFSET_Y-PFOCUS_IMAGE_OFFSET_Y);
M3dmapControl(MilLaser, M_DEFAULT, M_SCAN_SPEED, ConveyorSpeed);
}
M3dmapAllocResult(MilSystem, M_LASER_CALIBRATION_DATA, M_DEFAULT, &MilCalibScan);
#if USE_REAL_CAMERA
switch(ConvParams.DataResolution)
{
case 8:
MdigAlloc(MilSystem, M_DEFAULT, PFOCUS_8BITS_DCF , M_DEFAULT, &MilDigitizer);
break;
case 10:
MdigAlloc(MilSystem, M_DEFAULT, PFOCUS_10BITS_DCF, M_DEFAULT, &MilDigitizer);
break;
case 12:
MdigAlloc(MilSystem, M_DEFAULT, PFOCUS_12BITS_DCF, M_DEFAULT, &MilDigitizer);
break;
default:
FatalError(MIL_TEXT("Unexpected camera resolution.\n"));
}
MosPrintf(MIL_TEXT("Adjust camera and laser position for calibration.\n\n"));
SwitchToImage(CAMERA_COM_PORT, MilDigitizer);
#else
MilDigitizer = M_NULL;
#endif
MbufClear(MilImage, 0.0);
if (SizeBit != 8)
MdispControl(MilDisplay, M_VIEW_MODE, M_AUTO_SCALE);
else
MdispControl(MilDisplay, M_VIEW_MODE, M_DEFAULT);
MdispSelect(MilDisplay, MilImage);
if (ContextType == M_CALIBRATED_CAMERA_LINEAR_MOTION)
{
#if USE_REAL_CAMERA
MdigGrabContinuous(MilDigitizer, MilImage);
MosPrintf(MIL_TEXT("Place calibration grid, switch laser OFF.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to grab.\n\n"));
MosGetch();
MdigHalt(MilDigitizer);
MbufCopy(MilImage, MilCalGridImage);
MdigGrabContinuous(MilDigitizer, MilImage);
MosPrintf(MIL_TEXT("Switch laser ON.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to grab.\n\n"));
MosGetch();
MdigHalt(MilDigitizer);
SwitchToMeasure(CAMERA_COM_PORT, MilDigitizer);
MdigGrab(MilDigitizer, MilPeakImage[0]);
SwitchToImage(CAMERA_COM_PORT, MilDigitizer);
#else
MbufLoad(CalibGridFilename, MilCalGridImage);
MbufLoad(CalibLineFilename, MilPeakImage[0]);
#endif
McalAlloc(MilSystem, M_TSAI_BASED, M_DEFAULT, &MilCalibration);
McalControl(MilCalibration, M_GRID_CORNER_HINT_X, PFOCUS_IMAGE_SIZE_X-1);
McalControl(MilCalibration, M_GRID_CORNER_HINT_Y, 0);
McalGrid(MilCalibration, MilCalGridImage, 0.0, 0.0, 0.0, GRID_NB_ROWS, GRID_NB_COLS,
GRID_ROW_SPACING, GRID_COL_SPACING, M_DEFAULT, M_DEFAULT);
if (McalInquire(MilCalibration, M_CALIBRATION_STATUS, M_NULL) != M_CALIBRATED)
FatalError(MIL_TEXT("Camera calibration failed.\n"));
DisplayCalibrationPoints(MilDisplay, MilCalGridImage, MilCalibration);
Ret = M3dcamPFocusToMIL(MilPeakImage[0], MilPositionLine, MilIntensityLine, M_NULL, &ConvParams);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to convert image to MIL format.\n"));
DisplayLaserLine(MilDisplay, MilPositionLine, MilIntensityLine, MilMeasImage);
M3dmapAddScan(MilLaser, MilCalibScan, MilPositionLine, MilIntensityLine,
M_NULL, M_DEFAULT, M_LINE_ALREADY_EXTRACTED);
}
else
{
MilCalibration = M_NULL;
for (n = 0; n < NUMBER_OF_CALIBRATION_DEPTHS; n++)
{
MosPrintf(MIL_TEXT("Current plane: %d (%4.2f mm).\n"), (int)n, CORRECTED_DEPTHS[n]);
#if USE_REAL_CAMERA
MdigGrabContinuous(MilDigitizer, MilImage);
MosPrintf(MIL_TEXT("Press <Enter> to grab.\n\n"));
MosGetch();
MdigHalt(MilDigitizer);
SwitchToMeasure(CAMERA_COM_PORT, MilDigitizer);
MdigGrab(MilDigitizer, MilPeakImage[0]);
SwitchToImage(CAMERA_COM_PORT, MilDigitizer);
#else
MbufLoad(RefPlaneFilenames[n], MilPeakImage[0]);
#endif
M3dmapControl(MilLaser, M_DEFAULT, M_CORRECTED_DEPTH,
CORRECTED_DEPTHS[n]*SCALE_FACTOR);
Ret = M3dcamPFocusToMIL(MilPeakImage[0], MilPositionLine, MilIntensityLine, M_NULL, &ConvParams);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to convert image to MIL format.\n"));
DisplayLaserLine(MilDisplay, MilPositionLine, MilIntensityLine, MilMeasImage);
M3dmapAddScan(MilLaser, MilCalibScan, MilPositionLine, MilIntensityLine,
M_NULL, M_DEFAULT, M_LINE_ALREADY_EXTRACTED);
}
}
M3dmapCalibrate(MilLaser, MilCalibScan, MilCalibration, M_DEFAULT);
if (M3dmapInquire(MilLaser, M_DEFAULT, M_CALIBRATION_STATUS, M_NULL) != M_CALIBRATED)
FatalError(MIL_TEXT("Laser calibration failed.\n"));
MosPrintf(MIL_TEXT("The 3d reconstruction setup has been calibrated.\n\n"));
M3dmapFree(MilCalibScan);
MilCalibScan = M_NULL;
MIL_INT ScanObjType = M_NULL;
MIL_INT PointCloudLabel = M_NULL;
if(ContextType == M_DEPTH_CORRECTION)
{
ScanObjType = M_DEPTH_CORRECTED_DATA;
PointCloudLabel = M_DEFAULT;
}
else
{
ScanObjType = M_POINT_CLOUD_CONTAINER;
PointCloudLabel = M_POINT_CLOUD_LABEL(1);
}
M3dmapAllocResult(MilSystem, ScanObjType, M_DEFAULT, &MilScan);
M3dmapControl(MilScan, M_DEFAULT, M_MAX_FRAMES, NB_GRABS);
#if USE_REAL_CAMERA
MdigGrabContinuous(MilDigitizer, MilImage);
MosPrintf(MIL_TEXT("Adjust object position for scanning.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to grab.\n\n"));
MosGetch();
MdigHalt(MilDigitizer);
MosPrintf(MIL_TEXT("The object is being scanned.\n\n"));
SwitchToMeasure(CAMERA_COM_PORT, MilDigitizer);
AddScanProcFctDataStruct AddScanProcFctData;
AddScanProcFctData.MilLaser = MilLaser;
AddScanProcFctData.MilScan = MilScan;
AddScanProcFctData.PointCloudLabel = PointCloudLabel;
AddScanProcFctData.MilPositionImage = MilPositionLine;
AddScanProcFctData.MilIntensityImage = MilIntensityLine;
AddScanProcFctData.ConvParamsPtr = &ConvParams;
MdigProcess(MilDigitizer,
MilPeakImage,
NB_DIG_PROCESS_BUFFERS,
M_SEQUENCE+M_COUNT(NB_GRABS),
M_SYNCHRONOUS,
&AddScanProcFct,
&AddScanProcFctData);
#else
MIL_ID MilScanPosition, MilScanIntensity;
MbufRestore(ScanPosFilename, M_DEFAULT_HOST, &MilScanPosition );
MbufRestore(ScanIntFilename, M_DEFAULT_HOST, &MilScanIntensity);
for (n = 0; n < NB_GRABS; ++n)
{
MbufCopyColor2d(MilScanPosition , MilPositionLine , 0, 0, n, 0, 0, 0,
NbDetectedLaserPixels, 1);
MbufCopyColor2d(MilScanIntensity, MilIntensityLine, 0, 0, n, 0, 0, 0,
NbDetectedLaserPixels, 1);
M3dmapAddScan(MilLaser,
MilScan,
MilPositionLine,
MilIntensityLine,
M_NULL,
PointCloudLabel,
M_LINE_ALREADY_EXTRACTED);
}
MbufFree(MilScanIntensity);
MbufFree(MilScanPosition );
#endif
MIL_INT DepthMapSizeX, DepthMapSizeY, DepthMapType, IntensityMapType;
M3dmapControl(MilScan, M_DEFAULT, M_FILL_MODE , M_X_THEN_Y);
M3dmapControl(MilScan, M_DEFAULT, M_FILL_SHARP_ELEVATION , M_MIN );
M3dmapControl(MilScan, M_DEFAULT, M_FILL_SHARP_ELEVATION_DEPTH, GAP_DEPTH );
if (ContextType == M_CALIBRATED_CAMERA_LINEAR_MOTION)
{
M3dmapControl(MilScan, M_DEFAULT, M_BOUNDING_BOX_ALGORITHM, M_ROBUST);
M3dmapControl(MilScan, M_DEFAULT, M_AUTO_SCALE_XY, M_CLIP);
M3dmapSetBox(MilScan, M_EXTRACTION_BOX, M_BOUNDING_BOX,
M_ALL, M_DEFAULT, M_DEFAULT,
M_DEFAULT, M_DEFAULT, M_DEFAULT);
DepthMapSizeX = DEPTH_MAP_SIZE_X;
DepthMapSizeY = DEPTH_MAP_SIZE_Y;
DepthMapType = 16+M_UNSIGNED;
}
else
{
M3dmapGetResult(MilScan, M_DEFAULT, M_CORRECTED_DEPTH_MAP_SIZE_X +M_TYPE_MIL_INT,
&DepthMapSizeX );
M3dmapGetResult(MilScan, M_DEFAULT, M_CORRECTED_DEPTH_MAP_SIZE_Y +M_TYPE_MIL_INT,
&DepthMapSizeY );
M3dmapGetResult(MilScan, M_DEFAULT, M_CORRECTED_DEPTH_MAP_BUFFER_TYPE+M_TYPE_MIL_INT,
&DepthMapType );
}
MbufAlloc2d(MilSystem, DepthMapSizeX, DepthMapSizeY, DepthMapType ,
M_IMAGE+M_PROC+M_DISP, &MilDepthMap );
M3dmapGetResult(MilScan, PointCloudLabel, M_INTENSITY_MAP_BUFFER_TYPE + M_TYPE_MIL_INT,
&IntensityMapType);
MbufAlloc2d(MilSystem, DepthMapSizeX, DepthMapSizeY, IntensityMapType,
M_IMAGE+M_PROC+M_DISP, &MilIntensityMap);
M3dmapExtract(MilScan, MilDepthMap, MilIntensityMap, M_CORRECTED_DEPTH_MAP,
M_DEFAULT, M_DEFAULT);
MdispControl(MilDisplay, M_VIEW_MODE, M_AUTO_SCALE);
MdispSelect(MilDisplay, MilDepthMap);
MosPrintf(MIL_TEXT("The corrected depth map of the object is being displayed.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispSelect(MilDisplay, M_NULL);
CloseDown(CAMERA_COM_PORT);
MbufFree(MilIntensityMap);
MbufFree(MilDepthMap);
if (MilCalibration != M_NULL)
McalFree(MilCalibration);
M3dmapFree(MilScan);
M3dmapFree(MilLaser);
MbufFree(MilIntensityLine);
MbufFree(MilPositionLine);
MbufFree(MilMeasImage);
MbufFree(MilCalGridImage);
MbufFree(MilImage);
for (n = 0; n < NB_DIG_PROCESS_BUFFERS; ++n)
MbufFree(MilPeakImage[n]);
if (MilDigitizer != M_NULL)
MdigFree(MilDigitizer);
}
MIL_INT MFTYPE AddScanProcFct(MIL_INT HookType, MIL_ID MilEvent, void* UserDataPtr)
{
MIL_ID MilModifiedBuffer;
AddScanProcFctDataStruct* pAddScanProcFctData =
static_cast<AddScanProcFctDataStruct*>(UserDataPtr);
MdigGetHookInfo(MilEvent, M_MODIFIED_BUFFER+M_BUFFER_ID, &MilModifiedBuffer);
MIL_INT Ret = M3dcamPFocusToMIL(MilModifiedBuffer,
pAddScanProcFctData->MilPositionImage,
pAddScanProcFctData->MilIntensityImage,
M_NULL,
pAddScanProcFctData->ConvParamsPtr);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to convert image to MIL format.\n"));
M3dmapAddScan(pAddScanProcFctData->MilLaser,
pAddScanProcFctData->MilScan,
pAddScanProcFctData->MilPositionImage,
pAddScanProcFctData->MilIntensityImage,
M_NULL,
pAddScanProcFctData->PointCloudLabel,
M_LINE_ALREADY_EXTRACTED);
return M_NULL;
}
void SwitchToMeasure(int CameraPort, MIL_ID MilDigitizer)
{
MIL_INT Ret;
Ret = SwitchCameraToMeasure(CameraPort,
PFOCUS_MEAS_OFFSET_X,
PFOCUS_MEAS_OFFSET_Y,
PFOCUS_MEAS_SIZE_X,
PFOCUS_MEAS_SIZE_Y);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to switch camera to measurement mode.\n"));
MdigControl(MilDigitizer, M_SOURCE_SIZE_X, PFOCUS_MEAS_SIZE_X+PFOCUS_3D_DATA_WIDTH);
MdigControl(MilDigitizer, M_SOURCE_SIZE_Y, PFOCUS_MEAS_SIZE_Y );
}
void SwitchToImage(int CameraPort, MIL_ID MilDigitizer)
{
MIL_INT Ret;
Ret = SwitchCameraToImage(CameraPort,
PFOCUS_IMAGE_OFFSET_X,
PFOCUS_IMAGE_OFFSET_Y,
PFOCUS_IMAGE_SIZE_X,
PFOCUS_IMAGE_SIZE_Y);
if (Ret != PFOCUS_CAMERA_OK)
FatalError(MIL_TEXT("Unable to switch camera to image mode.\n"));
MdigControl(MilDigitizer, M_SOURCE_SIZE_X, PFOCUS_IMAGE_SIZE_X);
MdigControl(MilDigitizer, M_SOURCE_SIZE_Y, PFOCUS_IMAGE_SIZE_Y);
}
void DisplayLaserLine(MIL_ID MilDisplay,
MIL_ID MilPositionLine,
MIL_ID MilIntensityLine,
MIL_ID MilMeasImage)
{
MIL_ID MilPreviousImage;
MIL_INT PreviousViewMode;
MdispInquire(MilDisplay, M_SELECTED, &MilPreviousImage);
MdispInquire(MilDisplay, M_VIEW_MODE, &PreviousViewMode);
MbufClear(MilMeasImage, 0.0);
MimDraw(M_DEFAULT, MilPositionLine, MilIntensityLine, MilMeasImage,
M_DRAW_PEAKS+M_1D_ROWS+M_LINES, 0, 2.0, M_FIXED_POINT+PFOCUS_FIXED_POINT);
MdispControl(MilDisplay, M_VIEW_MODE, M_AUTO_SCALE);
MdispSelect(MilDisplay, MilMeasImage);
MosPrintf(MIL_TEXT("The extracted laser line is displayed.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MdispControl(MilDisplay, M_VIEW_MODE, PreviousViewMode);
MdispSelect(MilDisplay, MilPreviousImage);
}
void DisplayCalibrationPoints(MIL_ID MilDisplay,
MIL_ID MilCalGridImage,
MIL_ID MilCalibration)
{
MIL_ID MilPreviousImage;
MIL_DOUBLE PreviousColor;
MdispInquire(MilDisplay, M_SELECTED, &MilPreviousImage);
MgraInquire(M_DEFAULT, M_COLOR, &PreviousColor);
MIL_ID MilOverlay;
MdispSelect(MilDisplay, MilCalGridImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlay);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MgraColor(M_DEFAULT, M_COLOR_GREEN);
McalDraw(M_DEFAULT, MilCalibration, MilOverlay, M_DRAW_WORLD_POINTS,
M_DEFAULT, M_DEFAULT);
MosPrintf(MIL_TEXT("Camera calibration points are being displayed.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MgraColor(M_DEFAULT, PreviousColor);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MdispControl(MilDisplay, M_OVERLAY, M_DISABLE);
MdispSelect(MilDisplay, MilPreviousImage);
}
void FatalError(const MIL_TEXT_CHAR* pMsg)
{
MosPrintf(pMsg);
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n"));
MosGetch();
exit(-1);
}