1

We have a scanned white page - A4 size that contains multiple thumbnails. The thumbnails are similar but not exactly the same. The thumbnails can be in random order and not in a very clear rows and columns. They are not totally random but they are in rows, however these are not a very accurate rows.

  1. A4 page background color is white.
  2. All thumbnails have black border of 5px and border-radius of 10 px Everyone of the thumbnails contains a green circle (Could be in the center or somewhere close to that).

    1. How can we detect the Hard Edges of every thumbnail and store the coordinates so we can crop the thumbnails for later processing and analyzing colors?

    2. How can we detect the circle in the center. We want to analyze and get all pixels RGB values contained into this circle and then calculate average RGB value.


Update

This is the image:

enter image description here

Thank you

5

1 Answer 1

2

Main idea: As there are enough blank between the regions, so just crop each region by contours. Then for each region, use houghCircle to detect the circle in it.


Your image is this:

enter image description here

After find external contours and calculate the bounding boxes:

enter image description here

For each contour, crop and find hough circle in it.

enter image description here


Notice: I'll not provide my code for this question.

But post some links maybe useful for you. Learn and do by yourself:

  1. Copy shape to blank canvas (OpenCV, Python)
  2. cv2.drawContours() - unfill circles inside characters (Python, OpenCV)
  3. How to detect colored patches in an image using OpenCV?
  4. Edge detection on colored background using OpenCV
  5. How can I get the minimum enclosing circle with OPENCV?
  6. How can I prepare circle path text image for OCR program?

Update:

To detect the circle, you should select the right parameters, depends on your source image.

enter image description here

Try! Try! TRY!

Here is the circle detection I tried:

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT,
                    dp=1, minDist=20, circles=None,
                    param1=200 , param2=50,
                    minRadius=120, maxRadius=150
                )
Sign up to request clarification or add additional context in comments.

13 Comments

I have succeeded to detect external boundaries , and crop them and save them into new folder. Now I need to work on the circles. I want to loop over all of the coped rectangles and detect the circle in everyone of them, and then crop the circles. I want finally to be able to take everyone of the circles and analyze the colors in as many pixles as I can within every circle so I can find the average color value in every circle. Any help? :-)
As the colors of pixels in each circle are almost the same, you don't need to find exact circle. Use hough circle detection (such as in the link 6) to detect circle in each rectangle, the result maybe just like what I posted in this answer. As you can see, the detected circle is not really the same as origin, because of it's black border. Then decrease the radius, make sure the detected circle is in the original circle. Then crop the circle and analysis.
I am lready following the code in link 6. However, I guess there is a problem in circles = np.int0(np.array(circles)) where you are trying to Get the mean of centers and do offset. circles = np.int0(np.array(circles)) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Seems that circles is always equals to None... and that is why I am getting the previous error in previous comment. However I am not sure why I am getting Circles=None. What I am trying to do here and in order to check the circle detection. I am working on only one cropped rectangle thumbnail which contains one circle.
I just give you a link to show there is a way to detect circle. The parameters I used were adjusted for that project. Of course, it was taken the mean of all circles detected. In that situation, it was right. I your image, you should try to adjust your parameter. Such as, taking means is not needed. And the result I posted was ok(Because I set the right parameters)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.