我需要检测形状并计算图像中每个形状的出现.我最初检测到轮廓并对它们进行近似,并计算每个轮廓中的顶点.我的代码如下所示:
import cv2 import numpy as np import collections import sys img = cv2.imread(str(sys.argv[1]),0) ret,thresh = cv2.threshold(img,127,255,0) contours,hierarchy = cv2.findContours(thresh,1,2) no_of_vertices = [] i = 0 mask = np.zeros(img.shape,np.uint8) for contour in contours: cnt = contour area = cv2.contourArea(cnt) if area>150: epsilon = 0.02*cv2.arcLength(cnt,True) approx = cv2.approxPolyDP(cnt,epsilon,True) no_of_vertices.append(len(approx)) counter = collections.Counter(no_of_vertices) a,b = counter.keys(),counter.values() i=0 while i我的代码不能用于检测此图像中的星星:
我应该在代码中做出哪些更改?