Ask Your Question

findContours() with detailed images

asked 2019-06-16 13:22:22 -0500

Tom Walker gravatar image

updated 2019-06-16 13:36:27 -0500

Hi all,

I am implementing a custom barcode code reader (to read custom codes that look like a QR-code) with openCV on Android. At some point, I am using findContours() with tree hierarchy.

My problem is, that if the image contains a lot of details (like what it does when pointing the camera out of the window), findContours() takes quite a bit of time, because it finds up to 3000+ contours... This eats a lot of battery, while the image does not contain any QR-code...

I have already applied various pre-processing steps (gaussian, morph opening etc.) but the details are big enough to still produce the large number of contours.

I have no idea, how to deal with such a situation... The only way I can think of would be to tell findContours() the maximum number of contours that make sense - and have it return as soon as it reaches the limit...

Does anybody know how to deal with such a situation, when you have no control over the content of the image? Would it be possible to add such an additional parameter to the findContours() function?

  • Tom
edit retag flag offensive close merge delete


berak gravatar imageberak ( 2019-06-16 13:24:31 -0500 )edit

Thanks I have seen that. The problem is, that the QR code I have to read is slightly different (conceptually) but similar... it does not have a name (used internally only) thus I am calling it a QR code for the moment... sorry for the confusion.

Tom Walker gravatar imageTom Walker ( 2019-06-16 13:35:01 -0500 )edit

I edited to question to clarify that I cannot use the existing QR code decoder.

Tom Walker gravatar imageTom Walker ( 2019-06-16 13:37:19 -0500 )edit

could you provide a sample image of your QR code

sturkmen gravatar imagesturkmen ( 2019-06-16 13:52:40 -0500 )edit

sorry I am not allowed to publicly share it. The problem is not so much about the code itself but about the use of findContours(), if the image contains a lot of contours - it is basically an optimization problem to reduce battery consumption... (if findContours() takes a lot of time)

findContours() is basically used to find circles in the image... (the custom code differs in that regard to a classical QR code)

Tom Walker gravatar imageTom Walker ( 2019-06-16 13:57:19 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-06-16 15:09:02 -0500

you can use some part of the screen to detect ( search ) QR code. i think by this way the problems to solve will be easier

image description

edit flag offensive delete link more


Thank you. Thats indeed better - I am already doing that. Nevertheless, nothing stops a user from pointing the phone to a scene that contains a lot of details.... and thus producing a lot of contours.

Tom Walker gravatar imageTom Walker ( 2019-06-16 16:03:12 -0500 )edit

Question Tools

1 follower


Asked: 2019-06-16 13:22:22 -0500

Seen: 212 times

Last updated: Jun 16 '19