📄 capclassify.cpp
字号:
/* get chosen feature control object */
pControl = theCamera.GetCameraControl(CAMERA_FEATURE(fID));
pControl->GetRange(&aa, &bb);
mexPrintf("%-30s %d, %d\n", "Range (min, max):", aa, bb);
pControl->GetValue(&aa, &bb);
if(bb) {
/* feature with a range */
mexPrintf("%-30s %d, %d\n", "Current values (low, high):", aa, bb);
} else {
/* feature with a single value */
mexPrintf("%-30s %d\n", "Current value:", aa, bb);
}
/* selected attributes */
aa = pControl->HasManualMode();
if(aa == 0) {
mexPrintf("%-30s %d\n", "Attribute 'ManualMode' (!):", aa);
}
aa = pControl->HasAutoMode();
if(aa) {
mexPrintf("%-30s %d\n", "Attribute 'AutoMode':", pControl->StatusAutoMode());
}
aa = pControl->HasOnePush();
if(aa) {
mexPrintf("%-30s %d\n", "Attribute 'OnePush':", pControl->StatusOnePush());
}
aa = pControl->HasOnOff();
if(aa) {
mexPrintf("%-30s %d\n", "Attribute 'OnOff':", pControl->StatusOnOff());
}
// always '1'...
//
//aa = pControl->HasPresence();
//if(aa) {
// mexPrintf("%-30s %d\n", "Attribute 'Presence':", pControl->StatusPresence());
//}
/* absolute control... (scaled) */
if(pControl->HasAbsControl()) {
float faa, fbb;
pControl->GetRangeAbsolute(&faa, &fbb);
mexPrintf("%-30s %g, %g\n", "Scaled range (min, max):", faa, fbb);
pControl->GetValueAbsolute(&faa);
mexPrintf("%-30s %g\n", "Scaled value:", faa);
}
} /* for all features */
}
} /* dumpCameraStats ======================================================= */
/* myConfigCamera =========================================================== */
static void myConfigCamera(void) {
FILE *fp;
/* setup camera(s) */
mexPrintf("\nAdjusting camera settings...\n");
if((fp = fopen("cameraconfig.txt","r")) == NULL) {
mexPrintf("Couldn't find camera configuration file ('cameraconfig.txt') -> using default values, automatic wherever possible.\n");
/* use default camera settings - values found using the control dialog of '1394CameraDemo.exe' */
//mySetFeature("Shutter", 6, 0);
//mySetFeature("Saturation", 90, 0);
//mySetFeature("White Balance", 69, 96);
//mySetFeature("Gain", 87, 0);
//mySetFeature("Auto Exposure", 511, 0);
//mySetFeature("Brightness", 304, 0);
/* negative values -> automatic mode (if possible), otherwise: keep value as is */
mySetFeature("Shutter", -1, 0);
mySetFeature("Saturation", -1, 0);
mySetFeature("White Balance", -1, -1);
mySetFeature("Gain", -1, 0);
mySetFeature("Auto Exposure", -1, 0);
mySetFeature("Brightness", -1, 0);
} else {
/* cameraconfig.txt found -> analyse its contents */
while(!feof(fp)) {
char myStr[30];
int myPara[7];
fscanf(fp, "%s", myStr);
//mexPrintf("Read: >>%s<<\n", myStr);
/* filter out 'Camera_1 (only using 'camera_1' here...) */
if(strcmpi(myStr, "[Camera_1]") == 0) {
/* found definition for 'camera_1' -> read 7 values... */
mexPrintf("Programming camera '1' with: ");
for(int i=0; i<7; i++) {
fscanf(fp, "%d", &myPara[i]);
mexPrintf("%d ", myPara[i]);
}
mexPrintf("\n");
/* reset string */
myStr[0] = 0;
/* use user set of camera settings (file: cameraconfig.txt) */
mySetFeature("Shutter", myPara[0], 0);
mySetFeature("Saturation", myPara[1], 0);
mySetFeature("White Balance", myPara[2], myPara[3]);
mySetFeature("Gain", myPara[4], 0);
mySetFeature("Auto Exposure", myPara[5], 0);
mySetFeature("Brightness", myPara[6], 0);
} /* if(camera_1) */
}
fclose(fp);
}
/* end of 'adjust settings' */
mexPrintf("done.\n");
/* display current settings (for all connected cameras) */
if(verboseFlag) {
dumpCameraStats();
}
} /* myConfigCamera ========================================================== */
/* mySetupCamera ============================================================= */
static void mySetupCamera(myCameraModes mode) {
/* only initialize the camera if no CAMERA_STOP request has been issued */
if(mode != CAMERA_STOP) {
////mexPrintf("Scanning for connected cameras...\n");
if(theCamera.CheckLink() != CAM_SUCCESS)
mexErrMsgTxt("Error while checking for connected cameras.\n");
if(theCamera.InitCamera() != CAM_SUCCESS)
mexErrMsgTxt("Error during initialization of the camera.\n");
////mexPrintf("Camera successfully initialized\n");
/* set image buffer, define pixel format */
// 0: {160 ,120 ,COLOR_CODE_YUV444},
// 1: {320 ,240 ,COLOR_CODE_YUV422},
// 2: {640 ,480 ,COLOR_CODE_YUV411},
// 3: {640 ,480 ,COLOR_CODE_YUV422},
// 4: {640 ,480 ,COLOR_CODE_RGB8},
// 5: {640 ,480 ,COLOR_CODE_Y8},
// 6: {640 ,480 ,COLOR_CODE_Y16}
/* only set up camera, if the requested mode is supported by the connected camera */
if(theCamera.HasVideoMode(0L, mode)) {
/* camera supports the requested mode */
switch(mode) {
case CAMERA_YUV444_160x120:
/* 160x120 YUV444, 30 fps */
//mexPrintf("Mode %d -> Selecting YUV444 sink (30 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(0); /* 0: YUV(4:4:4) */
theCamera.SetVideoFrameRate(4); /* 4: 30 fps */
break;
case CAMERA_YUV422_320x240:
/* 320x240 YUV422, 30 fps */
//mexPrintf("Mode %d -> Selecting YUV422 sink (30 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(1); /* 1: YUV(4:2:2) */
theCamera.SetVideoFrameRate(4); /* 4: 30 fps */
break;
case CAMERA_YUV411_640x480:
default:
/* 640x480 YUV411, 30 fps */
//mexPrintf("Mode: %d -> Selecting YUV411 sink (30 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(2); /* 2: YUV(4:1:1) */
theCamera.SetVideoFrameRate(4); /* 4: 30 fps */
break;
case CAMERA_YUV422_640x480:
/* 640x480 YUV422, 15 fps */
//mexPrintf("Mode %d -> Selecting YUV422 sink (15 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(3); /* 3: YUV(4:2:2) */
theCamera.SetVideoFrameRate(3); /* 3: 15 fps */
break;
case CAMERA_RGB8_640x480:
/* 640x480 RGB, 15 fps */
//mexPrintf("Mode: %d -> Selecting RGB sink (15 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(4); /* 4: RGB8 */
theCamera.SetVideoFrameRate(3); /* 3: 15 fps */
break;
case CAMERA_Y8_640x480:
/* 640x480 B&W, 8 bit per pixel, 30 fps */
//mexPrintf("Mode: %d -> Selecting B&W sink (30 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(5); /* 5: Mono, 8-bit */
theCamera.SetVideoFrameRate(4); /* 4: 30 fps */
break;
case CAMERA_Y16_640x480:
/* 640x480 B&W 16 bit per pixel, 15 fps */
//mexPrintf("Mode: %d -> Selecting B&W sink (15 fps)\n", mode);
theCamera.SetVideoFormat(0);
theCamera.SetVideoMode(6); /* 6: Mono, 16-bit */
theCamera.SetVideoFrameRate(3); /* 3: 15 fps */
break;
} /* switch */
/* get frame size (= default image size) */
theCamera.GetVideoFrameDimensions(&frameWidth, &frameHeight);
//mexPrintf("frameWidth = %d\n", frameWidth);
//mexPrintf("frameHeight = %d\n", frameHeight);
/* fix dimensions */
dims[0] = (unsigned int)frameHeight;
dims[1] = (unsigned int)frameWidth;
dims[2] = 3;
/* total number of bytes kept in the buffer */
nElements = dims[0] * dims[1] * dims[2];
/* start image capture */
if(theCamera.StartImageCapture() != CAM_SUCCESS)
mexErrMsgTxt("Error at attempted start of image capture.\n");
/* load camera settings or use default values (can be found using '1394CameraDemo.exe') */
myConfigCamera();
/* fetch one image to waste some time (camera settles) ... */
for(int ii=0; ii<2; ii++) {
if(theCamera.CaptureImage() != CAM_SUCCESS)
mexErrMsgTxt("Error during image capture.\n");
}
// /* doesn't work... */
// Sleep( 250 );
/* camera initialized -> set 'initFlag' */
initCamera = 1;
/* indicate mode change */
currentMode = mode;
} else {
/* camera does not support the requested mode */
mexErrMsgTxt("Requested mode is not supported by connected camera.\n");
}
}
else {
/* CAMERA_STOP request has been issued */
//mexPrintf("Stopping camera...\n");
/* stop capture - if currently ongoing */
if(initCamera) theCamera.StopImageCapture();
/* indicate that we can free the grabber (in mexFunction) */
initCamera = 0;
/* indicate mode change */
currentMode = mode;
}
} /* mySetupCamera ============================================================ */
/* mySetupVision ============================================================= */
static void mySetupVision(myCameraModes mode, unsigned int Wx, unsigned int Wy) {
/* only (re-)initialize the vision if no CAMERA_STOP request has been issued */
if(mode != CAMERA_STOP) {
/* dynamically allocate memory for conversion buffers (CMVISION) */
yuvBuf = new yuv[Wx*Wy];
//mexPrintf("yuvBuf = %08x\n", yuvBuf);
yuyvBuf = new image_pixel[Wx/2*Wy];
//mexPrintf("yuyvBuf = %08x\n", yuyvBuf);
img = new rgb[Wx*Wy];
//mexPrintf("img = %08x\n", img);
// initialize class 'vision' (CMVision)
if(!vision.initialize(Wx, Wy))
mexErrMsgTxt("Vision init failed.\n");
vision.loadOptions(colourFilename);
vision.enable(CMV_DENSITY_MERGE);
} else {
/* CAMERA_STOP request has been issued */
// destroy class 'vision'
vision.close();
/* destroy dynamically allocated buffer for 'yuv' data */
if(yuvBuf != NULL) {
delete yuvBuf;
yuvBuf = NULL;
//mexPrintf("yuv buffer destroyed.\n");
}
/* destroy dynamically allocated buffer for 'yuyv' data */
if(yuyvBuf != NULL) {
delete yuyvBuf;
yuyvBuf = NULL;
//mexPrintf("yuyv buffer destroyed.\n");
}
/* destroy dynamically allocated buffer for 'img' data (output) */
if(img != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -