I defined the following function, but encountered a problem type conversion, the picture input for Mat type, but I want to cvPutText function realistic characters in the picture, enter the picture types require this function is CvArr * type, looking on the Internet . this approach has transformed the look of
the previous error code:
void show_dep(Mat a, int dep, int r, int c)
{
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_PLAIN, 1.5f, 1.5f, 0, 2, CV_AA);
CvPoint P1;
P1.x=20;
P1.y=20;
char* depth=(char*)('0'+dep);
const char* depth2=depth;
cvPutText(a,depth2, P1, &font, CV_RGB(255, 0, 0));
}
Following is the correct code following improvements:
middle added two lines marked out.
void show_dep(Mat a, int dep, int r, int c)
{
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_PLAIN, 1.5f, 1.5f, 0, 2, CV_AA);
CvPoint P1;
P1.x=20;
P1.y=20;
char* depth=(char*)('0'+dep);
const char* depth2=depth;
IplImage tmp=IplImage(a);//添加的代码
CvArr* arr = (CvArr*)&tmp;//添加的代码
cvPutText(arr,depth2, P1, &font, CV_RGB(255, 0, 0));