我在将文字放入图片时遇到问题。
cvPutText (img, text, cvPoint(pos.x,pos.y), &font, cvScalar(255,255,0));
我不知道为什么,但上面的代码中的img是带下划线的,它说没有合适的转换cv :: Mat到cv :: Arr。这是我的程序的精简版。谢谢你的任何建议。我把笔记巢放到代码中。
//function
double getOrientation(vector<Point> &pts, Mat &img)
{
//this works, no problem with img matrix
circle(img, pos, 3, CV_RGB(255, 0, 255), 2);
//i copied next 9 lines from another working program
char text[255];
sprintf(text, "%d", (int)angle);
CvFont font;
int fontface;
double hScale=1.0;
double vScale=1.0;
int lineWidth=1;
cvInitFont(&font,CV_FONT_HERSHEY_PLAIN, hScale,vScale,0,lineWidth);
//here's my problem. if I erase this line, no bugs. Again, img is underlined
//I've tried using &img, and I get a "bad argument (unknown array type) in unknown function. c:\slave\builds\winstallermegapack\src\opencv.... \matrix.cpp
cvPutText (img, text, cvPoint(pos.x,pos.y), &font, cvScalar(255,255,0)); }
int main()
{
Mat img = imread("c:\\picture.jpg"); // here i read jpg and store into img
getOrientation(contours[i], img); // function
}
imshow("Image", img);
char key;
while (true)
答案 0 :(得分:2)
看起来你正在混合传统的cv函数和clases。
如果您使用的是OpenCV 2.x,请致电putText:
putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )
例如,我的代码中的随机复制粘贴:
putText(Image,
text,
Point(a,b),
FONT_HERSHEY_COMPLEX_SMALL,
1,
cvScalar(0,0,0),
1,
CV_AA);