我正在使用openCV函数cvPutText,但似乎它不会执行或很快被覆盖。这是我的代码块:
...
if(showResult==1){
cvNamedWindow("Znak", CV_WINDOW_AUTOSIZE);
cvShowImage("Znak", znak);
if(result == 0){
ascii_result = "A";
cvSet(znak, cvScalar(26,26,26));
cvPutText(znak, "A", cvPoint(13, 185), &font, cvScalar(255, 166, 44, 0));
printf("A working");
}
if(result == 1){
ascii_result = "B";
cvSet(znak, cvScalar(26,26,26));
cvPutText(znak, "B", cvPoint(13, 185), &font, cvScalar(255, 166, 44, 0));
printf("B working");
}
...
它不在任何循环中。问题是,创建了“Znak”窗口,但 cvSet()和 cvPutText 将不会执行或被覆盖...所以我只看到空白窗口它黯淡的灰色
答案 0 :(得分:2)
每次对图像进行更改并希望显示时,都应放置CvShowImage。
...
if(showResult==1){
cvNamedWindow("Znak", CV_WINDOW_AUTOSIZE);
cvShowImage("Znak", znak);
if(result == 0){
ascii_result = "A";
cvSet(znak, cvScalar(26,26,26));
cvPutText(znak, "A", cvPoint(13, 185), &font, cvScalar(255, 166, 44, 0));
cvShowImage("Znak", znak);
printf("A working");
}
if(result == 1){
ascii_result = "B";
cvSet(znak, cvScalar(26,26,26));
cvPutText(znak, "B", cvPoint(13, 185), &font, cvScalar(255, 166, 44, 0));
cvShowImage("Znak", znak);
printf("B working");
}
...
当您调用cvShowImage时,它会将图像的副本发送到窗口。如果您更改代码中的图像,它将不会在窗口中更改,因为它只是旧图像的副本。