特别注意IplImage与Mat的转换。
static void draw_count(FrameData* pFrame) { CvSize size; if (!(pFrame->buffer.data)) { return; } size.width = pFrame->size2d.width; size.height= pFrame->size2d.height; IplImage* iplImage = cvCreateImageHeader(size, IPL_DEPTH_8U, SIZE_ARGB); cvSetData(iplImage, pFrame->buffer.data, size.width*SIZE_ARGB); CvScalar color; color.val[0] = 0xFF; color.val[1] = 0; color.val[2] = 0xFF; color.val[3] = 0; cvRectangle(iplImage, cvPoint(200,200), cvPoint(300,400), color, CV_FILLED, 8, 0); cv::Mat m1 = cv::cvarrToMat(iplImage); putText(m1, "Quantum", Point(100,100), FONT_HERSHEY_SIMPLEX, 1, color); }
据说由Mat转换为IplImage,直接使用即可:
Mat mat1; IplImage* ip1= &mat1;