Ask Your Question

Canny Edge Detector doesn't return filtered image

asked 2018-12-03 07:18:10 -0500

aLx gravatar image

I building an APK that receive the image from my android device camera and process with OpenCV library. Just want to convert the image to Gray scale, apply Gaussian Blur filter and run Canny Edge Detector.

My APK runs properly on android device, with no error instead. But it's don't return processed image, just the original.

Here's my onCameraFrame class with image processing code:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

Mat mRgba = new Mat();
Mat imgGray = new Mat();

Imgproc.cvtColor(inputFrame.rgba(), imgGray, Imgproc.COLOR_RGBA2GRAY);
Imgproc.GaussianBlur(imgGray, imgGray, new Size(5, 5), 2, 2);
Imgproc.Canny(imgGray, imgGray, 35, 75);

return imgGray;

I think my code isn't wrong, but i don't know how to return the edge detection image.

Someone knows how to help me?


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-04 01:40:23 -0500

Akhil Patel gravatar image

Here following code is working perfectly for display filtered image. Please use this code.

   public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)

         Mat rgba = inputFrame.rgba();
         Mat cannyedges = new Mat(rgba.size(), CV_8UC1);
         Imgproc.cvtColor(rgba, cannyedges , Imgproc.COLOR_RGB2GRAY, 4);
         Canny(cannyedges , cannyedges , 80, 100);
         return cannyedges ; 
edit flag offensive delete link more


Thanks for answering me. Same as my old code, just doesn't return a filtered image. I find some errors in logcat, maybe you know how to fix?

E/SurfaceHolder: Exception locking surface
    at android.view.Surface.nativeLockCanvas(Native Method)
    at android.view.Surface.lockCanvas(
    at android.view.SurfaceView$3.internalLockCanvas(
    at android.view.SurfaceView$3.lockCanvas(


aLx gravatar imageaLx ( 2018-12-04 04:19:15 -0500 )edit

can you please post your code?

Akhil Patel gravatar imageAkhil Patel ( 2018-12-04 04:24:18 -0500 )edit

Yes, here is my full MainActivity code:

aLx gravatar imageaLx ( 2018-12-04 10:22:12 -0500 )edit

Here is my full demo code please download it and run it in your android studio it's working fine.

Canny Edge Detector

Akhil Patel gravatar imageAkhil Patel ( 2018-12-05 00:22:03 -0500 )edit

Thanks, help me a lot!!

aLx gravatar imageaLx ( 2018-12-05 05:49:13 -0500 )edit


your issue solved or not?

Akhil Patel gravatar imageAkhil Patel ( 2018-12-05 05:52:18 -0500 )edit

Yes, solved. I believe was an error in OpenCV version or like i told you before, a error in Views.


aLx gravatar imageaLx ( 2018-12-05 06:42:48 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-03 07:18:10 -0500

Seen: 40 times

Last updated: Dec 04