我正在编辑一个由一些同事编写的相对较大的基于OpenCV的程序。我面临的问题是程序无法区分大小写键击(即键击"d"one_answers"d"都被视为0x65)我的同事告诉我,他通过直接从源代码编译机器上的OpenCV库,解决了机器上的问题。
我是一个新手,但也很好奇为什么会发生这样的事情,以及它与OpenCV安装有什么关系!
我的机器上仍然有问题,但我没有尝试重新安装openCV。
编辑:操作系统Linux Ubuntu 12.1064位字母是键盘上的按键,它们用于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, "%dn", 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 %fn",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 %fn",en);
if (en >= e)
misscnt++;
else
misscnt = 0;
if (misscnt > 3)
break;
e = water_error(cs->mg);
fprintf(stderr,"e %f %dn",e,misscnt);
calibrate_coupled_focal_length(cs->mg);
output_calibration_results(cs);
en = water_error(cs->mg);
fprintf(stderr,"en %fn",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 %dn",e,misscnt);
calibrate_camera_distortion(cs->mg);
output_calibration_results(cs);
en = water_error(cs->mg);
fprintf(stderr,"en %fn",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 failedn");
} else if (!(ocv_mgrid_set_input(cs->mg, input))) {
fprintf(stderr,"error calc error 1n");
}
pdist = water_error(cs->mg);
fprintf(stderr,"watererror: %fn",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 %fn",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;
}
直到现在我都不知道为什么!但我已经删除了旧的OpenCV库,并编译了最新版本。现在它确实区分了大写字母和小写字母。
新版本有一些细微的差异,这些差异不一定是好的,例如轨迹栏的值不能再通过点击来编辑了。此外(@kebs)关键笔划现在必须用0xff屏蔽!
我不知道也许我一直都有一个奇怪的OpenCV版本!