2

I am trying to detect bubbles on an OMR sheet which looks something like this:

Raw image

My code for edge detection and contour display is referenced from here. However, before finding the actual contours, I am trying to detect the edges but somehow not able to set the correct values of parameters. This is what I get:

edged

Code:

from imutils.perspective import four_point_transform
from imutils import contours
import numpy as np
import argparse
import imutils
import cv2

def auto_canny(image, sigma=0.50):
    # compute the median of the single channel pixel intensities
    v = np.median(image)

    # apply automatic Canny edge detection using the computed median
    lower = int(max(0, (1.0 - sigma) * v))
    upper = int(min(255, (1.0 + sigma) * v))
    edged = cv2.Canny(image, lower, upper)


# return the edged image
return edged

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
    help="path to the input image")
args = vars(ap.parse_args())
image = cv2.imread(args["image"])

r = 500.0 / image.shape[1]
dim = (500, int(image.shape[0] * r))

# perform the actual resizing of the image and show it
image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
equalized_img =  cv2.equalizeHist(gray)
cv2.imshow('Equalized', equalized_img)
# cv2.waitKey(0)
blurred = cv2.GaussianBlur(equalized_img, (7, 7), 0)
# edged =cv2.Canny(equalized_img, 30, 160)
edged = auto_canny(blurred)

cv2.imshow('edged', edged)
cv2.waitKey(0)

How can I get all the 90*4 circles?

3
  • you can extrapolate the direction and distance between circles from the detected ones, so you can get the coordinates of the missing ones. Commented Mar 12, 2018 at 13:41
  • Have you tried Otsu binarization? Commented Mar 12, 2018 at 17:38
  • hi Akhilesh, any of the answers below was of any help? Sorry to resume it late. Commented Aug 11, 2020 at 12:40

2 Answers 2

1

You should be using Hough to search for circles. This method project every single white pixel as a circle, and tries to get as many overlapping pixels possible. You'll have to specify the predicted radiuses of circles to be found within image.

Hough projects every white pixel on circles within specified radi

  • Left - original image
  • Top-right - each white pixel is projected as red circle - they are too small to find intersecting point
  • Bottom-right - green circle is larger, and all the intersecting points meet exactly at the middle of the circle! Both radius and position is returned by cvHoughCircles

This person dealt with blob detection (that's what finding circles is called I think) using cvHoughCircles with cvCanny-ized image (read OPs update).

OpenCV: Error in cvHoughCircles usage

Sign up to request clarification or add additional context in comments.

Comments

0

You need to improve your contour detection. Eventually by not changing it, but by better pre-processing the earlier stage. Contour detection works better with more contrast and color separation in image. If you don´t have yet need to threshold you image with techniques like Simple Threshold, Adaptive or more smart techniques like Otsu's. Check Open CV document here.

Besides that, for your case eventually need more advanced techniques like "Adaptive Thresholding Using the Integral Image", described here.

1 Comment

Link only answers are not acceptable. Please provide context in your answer so that it's self-contained.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.