2012-02-25 42 views
6

Tôi đang cố gắng phát hiện vòng kết nối bằng android. Tôi đã thành công để thực hiện thuật toán phát hiện đường nhưng không có gì được hiển thị khi cố gắng vẽ vòng tròn hough algoritm.Phát hiện vòng kết nối hough android

Đây là mã của tôi:

Mat thresholdImage = new Mat(getFrameHeight() + getFrameHeight()/2, getFrameWidth(), CvType.CV_8UC1); 
      mYuv.put(0, 0, data); 
      Imgproc.cvtColor(mYuv, destination, Imgproc.COLOR_YUV420sp2RGB, 4); 
      Imgproc.cvtColor(destination, thresholdImage, Imgproc.COLOR_RGB2GRAY, 4); 
      Imgproc.GaussianBlur(thresholdImage, thresholdImage, new Size(9, 9), 2, 2); 

     Mat circles = new Mat(); 


     Imgproc.HoughCircles(thresholdImage, circles, Imgproc.CV_HOUGH_GRADIENT, 1d, (double)thresholdImage.height()/70, 200d, 100d); 

     Log.w("circles", circles.cols()+""); 
     for (int x = 0; x < circles.cols(); x++) 
     { 
       double vCircle[]=circles.get(0,x); 

       Point center=new Point(Math.round(vCircle[0]), Math.round(vCircle[1])); 
       int radius = (int)Math.round(vCircle[2]); 
       // draw the circle center 
       Core.circle(destination, center, 3,new Scalar(0,255,0), -1, 8, 0); 
       // draw the circle outline 
       Core.circle(destination, center, radius, new Scalar(0,0,255), 3, 8, 0); 

     } 

Trả lời

6

Bạn có thể đã nhận được điều này sắp xếp theo, nhưng một vài điều. Tôi muốn kiểm tra mat vòng tròn của bạn thực sự có một số kết quả; đôi khi vCircle dường như trở lại null; thử một trong những phiên bản khác của HoughCircles:

iCannyUpperThreshold = 100; 
iMinRadius = 20; 
iMaxRadius = 400; 
iAccumulator = 300; 

Imgproc.HoughCircles(thresholdImage, circles, Imgproc.CV_HOUGH_GRADIENT, 
     2.0, thresholdImage.rows()/8, iCannyUpperThreshold, iAccumulator, 
     iMinRadius, iMaxRadius); 

if (circles.cols() > 0) 
    for (int x = 0; x < circles.cols(); x++) 
     { 
     double vCircle[] = circles.get(0,x); 

     if (vCircle == null) 
      break; 

     Point pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1])); 
     int radius = (int)Math.round(vCircle[2]); 

     // draw the found circle 
     Core.circle(destination, pt, radius, new Scalar(0,255,0), iLineThickness); 
     Core.circle(destination, pt, 3, new Scalar(0,0,255), iLineThickness); 
     } 

(tôi trao đổi mã của bạn vào tôi, đổi tên một số công cụ và đổi nó trở lại, tôi nghĩ Tôi đã có nó trở lại để nó hoạt động ...)

B.

Các vấn đề liên quan