0
我寫了一段代碼,它可以找到連接的組件,並使用cvPutText用字母「R」標記連接的組件。現在,除了Letter'R'之外,我需要根據連接組件的數量來打印1,2,3等數字。之後,我需要查找區域並將連接組件的區域打印爲文本。誰能幫我這個?在opencv的圖像中標記連接的組件
這裏是我的代碼:
imagelab=cvCreateImage(cvGetSize(mor),IPL_DEPTH_8U,3);
CvMemStorage* contour_storage = cvCreateMemStorage(0);
CvSeq* contours;
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.6f, 0.6f, 0, 2);
cvFindContours(mor, contour_storage, &contours, sizeof (CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
cvZero(imagelab);
for(; contours != NULL; contours = contours->h_next)
{
CvScalar color = CV_RGB(rand()&255, rand()&255, rand()&255);
cvDrawContours(imagelab, contours, color, CV_RGB(255,255,255), -1, CV_FILLED, 8 ,cvPoint(0,0));
CvRect iconBox = cvBoundingRect(contours, 0);
CvPoint center = cvPoint(iconBox.x + (iconBox.width/2), iconBox.y + (iconBox.height/2));
int area = abs(cvContourArea(contours, CV_WHOLE_SEQ));
cvPutText(imagelab,"R", center, &font, CV_RGB(255, 255, 255));
}
感謝名單。
d:\ qtproject \ finalvversion1 \ finalv1.cpp:122:錯誤:C2664: 'cvPutText':不能從 '的std :: basic_string的<_Elem,_Traits,_AX>' 轉換參數2爲 '爲const char *' 與 [ _Elem =炭, _Traits =標準:: char_traits, _AX =標準::分配器 ] 無可用的用戶定義的轉換操作,可以執行這種轉換,或操作員不能被稱爲 –
jagan
我得到了這樣的錯誤,當我試着如你所說 – jagan
我糾正了錯誤,現在我必須打印每個連接組件的區域分別作爲文本。你能給我一些建議嗎? – jagan