Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void SaveImage(Mat mat) {
- Imgproc.cvtColor(mat, processingFrame, Imgproc.COLOR_RGBA2BGR, 3);
- Imgproc.GaussianBlur(processingFrame, processingFrame, sSize3, 2, 2,
- Imgproc.BORDER_DEFAULT);
- Imgproc.cvtColor(processingFrame, mGray, Imgproc.COLOR_RGBA2GRAY);
- // / Gradient X //
- Imgproc.Sobel(mGray, grad_x, CvType.CV_16S, 1, 0, 3, scale, delta,
- Imgproc.BORDER_DEFAULT);
- Imgproc.Sobel(mGray, grad_x, CvType.CV_16S, 1, 0, 3, scale, delta);
- Core.convertScaleAbs(grad_x, abs_grad_x); // / Gradient Y //
- Imgproc.Sobel(mGray, grad_y, CvType.CV_16S, 0, 1, 3, scale, delta,
- Imgproc.BORDER_DEFAULT);
- Imgproc.Sobel(mGray, grad_y, CvType.CV_16S, 0, 1, 3, scale, delta);
- Core.convertScaleAbs(grad_y, abs_grad_y);
- // / Total Gradient(approximate)
- Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
- iCannyUpperThreshold = 100;
- iMinRadius = 0;
- iMaxRadius = 0;
- radius = 0;
- Imgproc.HoughCircles(grad, mIntermediateMat, Imgproc.CV_HOUGH_GRADIENT,
- 2.0, grad.rows() / 8, iCannyUpperThreshold, iAccumulator,
- iMinRadius, iMaxRadius);
- if (mIntermediateMat.cols() > 0) {
- for (int x = 0; x < Math.min(mIntermediateMat.cols(), 10); x++) {
- double vCircle[] = mIntermediateMat.get(0, x);
- if (vCircle == null)
- break;
- Log.i("Circle :", "Yes ");
- totalCirclesDetected++;
- pt.x = Math.round(vCircle[0]);
- pt.y = Math.round(vCircle[1]);
- radius = (int) Math.round(vCircle[2]);
- // draw the found circle
- Core.circle(processingFrame, pt, radius, colorRed,
- iLineThickness);
- }
- } else {
- Log.i("Circle :", "No");
- }
- }
Add Comment
Please, Sign In to add comment