[
后轮廓图](https://i.sstatic.net/v82nadjo.png)
获得Mark Locaitons:
首先预处理图像检测图像 以(x,y)获取轮廓及其中心位置
用坐标决定选择为a,b,c或d我可以解释如何正确过滤图像以及如何获取轮廓。您首先需要采用开放操作
这是完整的代码,我相信您可以使用theese坐标来确定每个标记的选定选项。
import cv2
import numpy
#Read the image and convert it to black-white the binary image
test_image = cv2.imread('test_result.png')
h,w,c = test_image.shape
gray_image = cv2.cvtColor(test_image,cv2.COLOR_BGR2GRAY)
lvl, thresholded_image = cv2.threshold(gray_image,150,255,cv2.THRESH_BINARY)
#Make opening on the image to remove the samaller white blobs
opened = cv2.morphologyEx(thresholded_image,cv2.MORPH_OPEN,cv2.getStructuringElement(cv2.MORPH_RECT,(11,11)))
#Make the contour detection on the image and get their coordinates
contours,hierarchy = cv2.findContours(opened,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
cv2.drawContours(test_image,[cnt],-1,(0,255,0),2)
# compute the center of the contour
M = cv2.moments(cnt)
cx = int(M["m10"] / M["m00"])
cy = int(M["m01"] / M["m00"])
cv2.circle(test_image,(cx,cy),7,(255,0,0),-1)
#Show the results
cv2.imshow('Thresh',cv2.resize(thresholded_image,(int(w*720/h),720)))
cv2.imshow('Original',cv2.resize(test_image,(int(w*720/h),720)))
cv2.imshow('Opened',cv2.resize(opened,(int(w*720/h),720)))
cv2.waitKey()`