使用opencv3和python3对图像中的轮廓进行排序的最佳(最佳)解决方案是什么? 我试试这个。这是最好的解决方案吗?在
_, contours, _ = cv2.findContours(image , cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
areas = list(map(lambda c : cv2.contourArea(c), contours))
contoursWithAreas = zip(contours, areas)
sortedContoursWithArea = sorted(contoursWithAreas, key=lambda s : s[1])
sortedContours ,sortedAreas = zip(*sortedContoursWithArea)
最后,我们在sortedContours
变量中按区域对轮廓进行排序。在
众所周知,等高线是
np.ndarray
的列表。所以我们不能避免使用numpy。那为什么不使用np.argsort()
?在相关问题 更多 >
编程相关推荐