Ask Your Question
0

Can't get Canny Edge Treshold right

asked 2018-06-10 09:53:28 -0500

Jérémy K gravatar image

updated 2018-06-10 09:53:57 -0500

I'm trying to extract digits from an analog electricity meter.

I have for example following picture: image description

I know that the lightning on this picture isn't equal everywhere, but it's really hard to get this equal due to reflection and etc.

When I'm performing Grayscale, Gaussian Blur & Canny Edge on this image, I can't get a decent result. The issue is that I either have to put the Canny Edge treshold too high which causes some digits unreadable or either have to put the Canny Edge treshold too low which causes too much details to be included in the image.

Example of too high treshold: image description

Code: Imgproc.Canny(image, imgCanny, 60, 60/3);

Example of too low treshold: image description

Code: Imgproc.Canny(image, imgCanny, 35, 35/3);

Is there any way to perform some kind of 'Adaptive Treshold Canny Edge' on this? Thanks!

edit retag flag offensive close merge delete

Comments

Have you try in NiBlackThreshold opencv_contrib?

LBerger gravatar imageLBerger ( 2018-06-10 11:28:44 -0500 )edit

Thanks for this suggestion @LBerger, but I can't find the XImgProc in my jar or .so and it's a real pain to build these again.. Any suggestion that doesn't require the extra modules? Thanks!

Jérémy K gravatar imageJérémy K ( 2018-06-10 12:12:43 -0500 )edit

In canny you can use function with your gradient x and y

LBerger gravatar imageLBerger ( 2018-06-10 12:21:06 -0500 )edit

Thanks for this suggestion. Can you please give me some more resources or info on the gradient x and y usage? Or how it would help me out with this? I btw enabled the L2gradient flag, which already makes it a little bit better.

Jérémy K gravatar imageJérémy K ( 2018-06-10 13:12:16 -0500 )edit

int t = threshold(...,THRESH_OTSU) is quite often used for this. (you would throw away the result image, and only keep the threshold number for Canny later)

berak gravatar imageberak ( 2018-06-11 02:17:46 -0500 )edit

Thanks for your suggestion @berak ! I tried to use: Imgproc.threshold(image, imgCanny, 0, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU); , but it doesn't really give a nice result. (You can see the result here).

Jérémy K gravatar imageJérémy K ( 2018-06-11 05:02:30 -0500 )edit
1

@berak , tried to keep the treshold number, but I get 116 as treshold which is way too high..

Jérémy K gravatar imageJérémy K ( 2018-06-11 06:42:52 -0500 )edit

Using paillou filter (in opencv_contrib) with canny I can get :

r

Now It's take time to get this result

LBerger gravatar imageLBerger ( 2018-06-11 08:38:27 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2018-06-17 11:41:40 -0500

Jérémy K gravatar image

Couldn't get it fixed with the Canny algorithm. Needed to fix the picture quality and light.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-06-10 09:53:28 -0500

Seen: 191 times

Last updated: Jun 17 '18