I figured out how to detect the orientation of a semicircle. When my program gets the contours, I want it to retrieve them from left to right, however, OpenCV recognizes the semicircles on the bottom as a separate row, and counts the semicircles on the top first then the semicircles on the bottom (shown in the picture).
EDIT
lower = np.array([0, 0, 0])
upper = np.array([15, 15, 15])
shapeMask = cv2.inRange(img, lower, upper)
_, contours, _ = cv2.findContours(shapeMask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours.reverse()
for cnt in contours:
if len(approx)== 4 or len(approx) == 8:
if(np.array_equal(img[midpoint[1],midpoint[0]],[0, 0, 0])):
#unshaded square
elif(np.array_equal(img[midpoint[1],midpoint[0]],[0, 255, 255])):
#shaded square
elif len(approx) == 3 or (len(approx) >= 14 and len(approx) <= 17):
if(np.array_equal(img[midpoint[1],midpoint[0]],[0, 0, 0])):
#unshaded triangle
elif(np.array_equal(img[midpoint[1],midpoint[0]],[0, 255, 255])):
#shaded triangle
elif len(approx) >= 9 and len(approx) <= 13:
#semicircle
elif len(approx) > 18:
if(np.array_equal(img[midpoint[1],midpoint[0]],[0, 0, 0])):
#shaded circle
elif(np.array_equal(img[midpoint[1],midpoint[0]],[0, 255, 255])):
#unshaded circle
Here is the image I want to be able to differentiate between the semicircle on the top and the semicircle on the bottom, and count the bottom first as it is before the one on the top