我正在编辑一些由同事编写的基于OpenCV的相对较大的程序。 我面临的问题是该程序没有区分大写和小写击键(即击键'd'和'D'都被视为0x65) 我的同事告诉我他通过直接从源代码编译OpenCV库来解决他的机器上的问题。
我是新手,但也很好奇为什么会发生这样的事情以及它与OpenCV的安装有什么关系呢?
我的机器上仍有问题,但我没有尝试重新安装openCV。
编辑: OS Linux-Ubuntu 12.10 64位 这些字母是键盘上的按键,它们用在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;
}
答案 0 :(得分:0)
直到现在我还不知道为什么! 但我删除了旧的OpenCV库并编译了最新版本。现在它确实区分了大写和小写字母。
新版本有一些微妙的差异,但不一定好,例如,无法再点击它们来编辑曲目栏的值。另外(@ kebs)现在必须用0xff屏蔽击键!
我不知道也许我一直都有一个奇怪的OpenCV版本!