我正在使用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 无法执行或被覆盖...所以我只能看到空白的窗口,其灰色为灰色
最佳答案
每次对图像进行更改并想要显示时,都应放置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时,它将图像的副本发送到窗口。如果您在代码中更改图像,则该图像将不会在窗口中更改,因为它只是旧图像的副本。
关于c++ - 为什么在这种情况下cvPutText不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9654962/