我有一个二值图像(numpy数组),它表示一个矩形的近似值:
我试图提取矩形的真实形状,但似乎找不到方法。 预期结果如下:
我正在使用这个代码
contours,_ = cv2.findContours(numpymask.copy(), 1, 1) # not copying here will throw an error
rect = cv2.minAreaRect(contours[0]) # basically you can feed this rect into your classifier
(x,y),(w,h), a = rect # a - angle
box = cv2.boxPoints(rect)
box = np.int0(box) #turn into ints
rect2 = cv2.drawContours(img.copy(),[box],0,(0,0,255),10)
plt.imshow(rect2)
plt.show()
但我得到的结果如下,我并不需要这些:
为此,我将Python与opencv结合使用
这是我以前玩过的东西。它应该适合你的形象
相关问题 更多 >
编程相关推荐