Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void takePhoto() {
- PictureCallback pictureCB = new PictureCallback() {
- public void onPictureTaken(byte[] data, Camera cam) {
- byte[] photoData = data;
- try {
- } finally {
- Bitmap photo = (Bitmap) BitmapFactory.decodeByteArray(
- photoData, 0, photoData.length);
- Mat mat = new Mat();
- mat = new Mat(photo.getHeight(), photo.getWidth(),
- CvType.CV_8UC4);
- Utils.bitmapToMat(photo, mat);
- // Procedure using sobel derivative
- 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);
- // Procedure using sobel derivative End
- iMinRadius = 0;
- iMaxRadius = 0;
- iCannyUpperThreshold = 100;
- iAccumulator = 300;
- Imgproc.HoughCircles(grad, mIntermediateMat, Imgproc.CV_HOUGH_GRADIENT,
- 2.0, 10, iCannyUpperThreshold, iAccumulator,
- iMinRadius, iMaxRadius);
- radius = 0;
- 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");
- }
- }
- }
- };
- mCamera.takePicture(null, null, pictureCB);
- }
Add Comment
Please, Sign In to add comment