我正在编辑一些同事编写的一个相对较大的基于 OpenCV 的程序。我面临的问题是程序不区分大小写击键(即击键'd'和'D'都被视为0x65)我的同事告诉我,他通过编译解决了他机器上的问题他机器上的 OpenCV 库直接来自源代码。
我是一个新手,但也很好奇为什么会发生这种事情以及它与 OpenCV 安装有什么关系!
我的机器上仍然有问题,但我还没有尝试重新安装 openCV。
编辑:OS Linux-Ubuntu 12.10 64bit 这些字母是来自键盘的击键,它们用于 switch 语句。
static int process_key(struct cam_segment* cs, int key){
int res = 0;
double pdist;
struct stat sb;
char fn[4096];
static int out_id = 0;
fprintf( stderr, "%d\n", key&0xff );
switch (key & 0xff) {
case 'm':
show_merged = !show_merged;
res = 1;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
cam_id = (key & 0xff) - '1';
res = 1;
break;
case 'D':
ocv_mgrid_set_distortion( cs->mg, 0 );
res = 1;
break;
case 'd':
ocv_mgrid_set_distortion( cs->mg, 1 );
res = 1;
break;
case 'n':
res = 1;
break;
case 'C':
init_calibration(cs);
calibrate_camera_distortion(cs->mg);
output_calibration_results(cs);
cs->calib_mode = 1;
res = 1;
break;
case 'c':
init_calibration(cs);
fprintf(stderr,"searching.....");
calibrate_camera_rotation(cs->mg);
output_calibration_results(cs);
fprintf(stderr,"e1 %f\n",water_error(cs->mg));
cs->calib_mode = 1;
res = 1;
break;
case 'M':
init_calibration(cs);
fprintf(stderr,"searching pricipal point.....");
calibrate_camera_center(cs->mg);
output_calibration_results(cs);
cs->calib_mode = 1;
res = 1;
break;
case 'a':
init_calibration(cs);
int misscnt;
double e,en;
en = e = HUGE;
misscnt = 0;
for(int i=0;i<20;i++) {
e = water_error(cs->mg);
fprintf(stderr,"e1 %f %d \n",e,misscnt);
calibrate_camera_rotation(cs->mg);
output_calibration_results(cs);
en = water_error(cs->mg);
fprintf(stderr,"en1 %f\n",en);
if (en >= e)
misscnt++;
else
misscnt = 0;
if (misscnt > 3)
break;
e = water_error(cs->mg);
fprintf(stderr,"e %f %d\n",e,misscnt);
calibrate_coupled_focal_length(cs->mg);
output_calibration_results(cs);
en = water_error(cs->mg);
fprintf(stderr,"en %f\n",en);
if (en >= e)
misscnt++;
else
misscnt = 0;
if (misscnt > 3)
break;
e = water_error(cs->mg);
if (e > 100)
continue;
fprintf(stderr,"e %f %d\n",e,misscnt);
calibrate_camera_distortion(cs->mg);
output_calibration_results(cs);
en = water_error(cs->mg);
fprintf(stderr,"en %f\n",en);
if (en >= e)
misscnt++;
else
misscnt = 0;
if (misscnt > 3)
break;
}
cs->calib_mode = 1;
res = 1;
break;
case 'p':
init_calibration(cs);
calibrate_coupled_focal_length(cs->mg);
output_calibration_results(cs);
cs->calib_mode = 1;
res = 1;
break;
case 'F':
init_calibration(cs);
calibrate_focal_lengths(cs->mg);
output_calibration_results(cs);
cs->calib_mode = 1;
res = 1;
break;
case 't':
init_calibration(cs);
calibrate_target(cs->mg);
output_calibration_results(cs);
cs->calib_mode = 1;
res = 1;
break;
case 'e':
sprintf(fn, "%s_%03d.png",cs->inp_prefix, cs->inp_id);
if (!(input = cvLoadImage(fn, CV_LOAD_IMAGE_COLOR))) {
fprintf(stderr,"error calc: loading input failed\n");
} else if (!(ocv_mgrid_set_input(cs->mg, input))) {
fprintf(stderr,"error calc error 1\n");
}
pdist = water_error(cs->mg);
fprintf(stderr,"watererror: %f\n",pdist);
break;
case 'N':
res = 1;
cs->inp_id++;
cerr << "inp_id=" << cs->inp_id << "\n";
break;
case 'P':
res = 1;
cs->inp_id--;
cerr << "inp_id=" << cs->inp_id << "\n";
break;
case 'z':
cs->color_mode = OCV_MGRID_CMODE_THETA;
res = 1;
break;
case 'Z':
cs->color_mode = OCV_MGRID_CMODE_THETA_CHECK;
res = 1;
break;
case 'l':
cs->draw_legend = !(cs->draw_legend);
res = 1;
break;
case 'x':
cs->color_mode = OCV_MGRID_CMODE_X;
res = 1;
break;
case 'y':
cs->color_mode = OCV_MGRID_CMODE_Y;
res = 1;
break;
case 'X':
cs->color_mode = OCV_MGRID_CMODE_X_CHECK;
res = 1;
break;
case 'Y':
cs->color_mode = OCV_MGRID_CMODE_Y_CHECK;
res = 1;
break;
case 'o':
cs->color_mode = OCV_MGRID_CMODE_NONE;
res = 1;
break;
case 's':
sprintf(fn, "input_%03d.png",out_id);
while(stat(fn, &sb) != -1) {
out_id++;
sprintf(fn, "input_%03d.png",out_id);
}
fprintf(stderr,"saving %s \n",fn);
cvSaveImage(fn,OCV_MGRID_GET_INPUT(cs->mg));
break;
case 'r':
if (projection)
cvResetImageROI(projection);
if (merged_projection)
cvResetImageROI(merged_projection);
if (merged_grid)
cvResetImageROI(merged_grid);
if (output)
cvResetImageROI(output);
break;
case 'R':
reset_defaults();
reset_trackbars();
break;
case 'f':
ocv_mgrid_get_best_projection_distance(cs->mg, &pdist);
fprintf(stderr,"best match %f\n",pdist);
tb_pdist = (int) pdist;
cvSetTrackbarPos("proj_distance", "tbars", tb_pdist);
res = 1;
break;
case 'w':
if (use_camera)
if (!(ocv_ueye_whitebalance(cs->ueye)))
return 1;
break;
case 'W':
save_params(cs);
break;
default:
break;
}
return res;
}