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 1
- Imgproc.cvtColor(mat, processingFrame, Imgproc.COLOR_RGBA2BGR, 3);
- Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGBA2BGR, 3);
- Imgproc.cvtColor(processingFrame, processingFrame, Imgproc.COLOR_RGBA2GRAY);
- // doing a gaussian blur prevents getting a lot of false hits
- Imgproc.GaussianBlur(processingFrame, grad, new Size(5,5), 2, 2);
- // Procedure 1 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