2012-06-24 48 views
1

我發現了一些能夠識別特定圖像中的圓圈的代碼,並且我能夠將其中90%的代碼轉換爲javacv。但不幸的是,我無法將以下行轉換爲javacv。所以請有人幫我把這些行轉換成javacv?請幫助將opencv代碼轉換爲javacv?

CvSeq circles = cvHoughCircles(gry, mem, CV_HOUGH_GRADIENT, 1, 40.0, 100, 100,0,0); 
cvCvtColor(canny, rgbcanny, CV_GRAY2BGR); 

for (int i = 0; i < circles->total; i++) 
{ 
// round the floats to an int 
float* p = (float*)cvGetSeqElem(circles, i); 
cv::Point center(cvRound(p[0]), cvRound(p[1])); 
int radius = cvRound(p[2]); 

// draw the circle center 
cvCircle(img, center, 3, CV_RGB(0,255,0), -1, 8, 0); 

// draw the circle outline 
cvCircle(img, center, radius+1, CV_RGB(0,0,255), 2, 8, 0); 

printf("x: %d y: %d r: %d\n",center.x,center.y, radius); 
} 

我只需要知道如何轉換for循環內的5代碼行。請足夠分享您的經驗。謝謝。

回答

2

好吧,我不打算去了代碼轉換爲你(我不知道JavaCV),但這裏的一些有用的鏈接給你:


// Draw lines on the canny contour image 
val colorDst = cvCreateImage(cvGetSize(src), src.depth(), 3) 
cvCvtColor(src, colorDst, CV_GRAY2BGR) 
for (i <- 0 until circles.total) { 
    val point = new CvPoint3D32f(cvGetSeqElem(circles, i)) 
    val center = cvPointFrom32f(new CvPoint2D32f(point.x, point.y)) 
    val radius = math.round(point.z) 
    cvCircle(colorDst, center, radius, CV_RGB(255, 0, 0), 1, CV_AA, 0) 
    print(point) 
} 
show(colorDst, "Hough Circles") 

這正是你要尋找的。

相關問題