2015-10-20 74 views
1

我正在嘗試使用HoughCircles方法的JavaCV實現,但我遇到了一些參數問題。 這是我的代碼:如何傳遞和使用JavaCV HoughCircles方法的參數

所有的
Mat currentImageGray = tgtFrag.getImage().clone(); 
Mat detectedCircles = new Mat(); 

HoughCircles(currentImageGray, detectedCircles, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows()/4, 0); 

if (detectedCircles != null && !detectedCircles.empty()) { 
    // TO DO: 
    // Print the center and the raidus of the detected circles. 
} 

首先,檢測(該HoughCircles的第二argment)的結果作爲一個墊(detectedCircles)。

我想處理detectedCircles墊,並以某種方式打印控制檯上圓的中心和半徑。到目前爲止,我的嘗試失敗了:我一直試圖使用FloatBufferIndexer迭代detectedCircles,這可能是正確的方向,但我還沒有成功,任何人都可以提供幫助?

請注意以下幾點:

  • 我使用JavaCV,不OpenCV的。
  • 我使用的是JavaCV HoughCircles,而不是cvHoughCircles(使用cvHoughCircles的解決方案也可以)。
  • 我使用的是最新版本的JavaCV,即1.0(2015年7月)。

回答

1

我只能使用JavaCV cvHoughCircles方法,不知道如何使用HoughCircles方法。這是我對你的代碼的改編。

// Get the source Mat. 
Mat myImage = tgtFrag.getImage(); 
IplImage currentImageGray = new IplImage(myImage); 
CvMemStorage mStorage = CvMemStorage.create(); 

CvSeq detectedCircles = cvHoughCircles(currentImageGray, mStorage, CV_HOUGH_GRADIENT, 1, 2, 254, 25, tgtFrag.getImage().rows()/4, 0); 

if (detectedCircles != null && detectedCircles.total() > 0) { 

    for (int i = 0; i < detectedCircles.total(); i++) { 
     CvPoint3D32f curCircle = new CvPoint3D32f(cvGetSeqElem(detectedCircles, i)); 

     int curRadius = Math.round(curCircle.z()); 
     Point curCenter = new Point(Math.round(curCircle.x()), Math.round(curCircle.y())); 

     System.out.println(curCenter); 
     System.out.println(curRadius);  
    } 

} 

即使這並不直接解決您的問題,我希望這可能有所幫助。

+1

謝謝@Tzeencth,這確實可以解決我的問題,甚至很難我想看到使用HoughCircle方法,而不是cvHoughCircles。我將等待一段時間,然後將其標記爲我的問題的答案。 – INElutTabile