Exemplo n.º 1
0
def contour_area_sort(contours, area_threshold):
    contours.sort(key=cv2.contourArea, reverse=True)
    cnts = [c for c in contours if cv2.contourArea(c) > area_threshold]
    return cnts
Exemplo n.º 2
0
# cv2.drawContours(image, [screenCnt], -1, color, 2)

# ! Code to detect circles using the houghcircles.
lower_bound = np.array([0,0,10])
upper_bound = np.array([255,255,195])

mask = cv2.inRange(image,lower_bound,upper_bound)

kernel = np.ones((3,3), np.uint8)
#! use erosion and dilation combination to eliminate false positives.

mask = cv2.erode(mask,kernel,iterations=6)
mask = cv2.dilate(mask,kernel,iterations=3)

closing = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)[1]
contours.sort(key=lambda x:cv2.boundingRect(x)[0])

array = []
ii = 1
print(len(contours))
for c in contours:
	(x,y),r = cv2.minEnclosingCircle(c)
	center = (int(x),int(y))
	if r >= 6 and r <= 10:
		cv2.circles(image,center,r,(0,255,0),2)
		array.append(center)

cv2.imshow("preprocessed", image)
cv2.waitkey()

#! Run the server, python3 scanner.py --image sheet.jpg