我正在尝试在屏幕上打印文本,但一直出现错误。

有人可以帮助我提供代码吗?

cvNamedWindow("Result", CV_NORMAL);
cvMoveWindow("Result", 350,300);
cvRectangle(img, cvPoint(0,0), cvPoint(2600,2000),cvScalarAll(255), CV_FILLED,8,0);
cvShowImage("Result", img);
cvPutText(img, mytext,cvPoint(100,100),CV_FONT_HERSHEY_SIMPLEX,cvScalarAll(0));
cvWaitKey(0);

我得到的错误是
OpenCV Error: Assertion failed (text != 0 && _font != 0) in cvPutText, file /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/drawing.cpp, line 2375
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/drawing.cpp:2375: error: (-215) text != 0 && _font != 0 in function cvPutText
Aborted

最佳答案

试试这个,这是一个有效的例子:

char text = 'World';

char buffer[25];
sprintf(buffer, "Hello  %c", text);
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5);
cvPutText(image, buffer, cvPoint(2, 2), &font, cvScalar(255));

关于c - 使用cvPutText(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20551976/

10-12 22:28