devendradhanal

Circle Detection Android Opencv Procedure using JavaCvCamera

Dec 4th, 2013
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. public void SaveImage(Mat mat) {
  2.        
  3.         Imgproc.cvtColor(mat, processingFrame, Imgproc.COLOR_RGBA2BGR, 3);
  4.  
  5.         Imgproc.GaussianBlur(processingFrame, processingFrame, sSize3, 2, 2,
  6.                 Imgproc.BORDER_DEFAULT);
  7.         Imgproc.cvtColor(processingFrame, mGray, Imgproc.COLOR_RGBA2GRAY);
  8.         // / Gradient X //
  9.         Imgproc.Sobel(mGray, grad_x, CvType.CV_16S, 1, 0, 3, scale, delta,
  10.                 Imgproc.BORDER_DEFAULT);
  11.         Imgproc.Sobel(mGray, grad_x, CvType.CV_16S, 1, 0, 3, scale, delta);
  12.         Core.convertScaleAbs(grad_x, abs_grad_x); // / Gradient Y //
  13.         Imgproc.Sobel(mGray, grad_y, CvType.CV_16S, 0, 1, 3, scale, delta,
  14.                 Imgproc.BORDER_DEFAULT);
  15.         Imgproc.Sobel(mGray, grad_y, CvType.CV_16S, 0, 1, 3, scale, delta);
  16.         Core.convertScaleAbs(grad_y, abs_grad_y);
  17.         // / Total Gradient(approximate)
  18.         Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
  19.  
  20.         iCannyUpperThreshold = 100;
  21.         iMinRadius = 0;
  22.         iMaxRadius  = 0;
  23.         radius = 0;
  24.         Imgproc.HoughCircles(grad, mIntermediateMat, Imgproc.CV_HOUGH_GRADIENT,
  25.                 2.0, grad.rows() / 8, iCannyUpperThreshold, iAccumulator,
  26.                 iMinRadius, iMaxRadius);
  27.  
  28.         if (mIntermediateMat.cols() > 0) {
  29.             for (int x = 0; x < Math.min(mIntermediateMat.cols(), 10); x++) {
  30.                 double vCircle[] = mIntermediateMat.get(0, x);
  31.  
  32.                 if (vCircle == null)
  33.                     break;
  34.                 Log.i("Circle :", "Yes ");
  35.                 totalCirclesDetected++;
  36.                 pt.x = Math.round(vCircle[0]);
  37.                 pt.y = Math.round(vCircle[1]);
  38.                 radius = (int) Math.round(vCircle[2]);
  39.                 // draw the found circle
  40.                 Core.circle(processingFrame, pt, radius, colorRed,
  41.                         iLineThickness);
  42.             }
  43.         } else {
  44.             Log.i("Circle :", "No");
  45.         }
  46.  
  47. }
Add Comment
Please, Sign In to add comment