【发布时间】:2021-02-24 19:05:08
【问题描述】:
我正在使用 OpenCV 来完成这个特定的任务。我有一张图像,我正在尝试识别并删除所有纵横比高于 3:1 的对象。但由于某种原因,我根本无法在它们周围绘制边界框。这是我到目前为止的代码:
import cv
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('Shapes-blurred.png', 0)
ret, binary_img = cv2.threshold(img, 70, 255, cv2.THRESH_BINARY)
contours, _ = cv2.findContours(binary_img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.boundingRect(c)
if int(rect[3]/rect[2]) < 3: continue
x,y,w,h = rect
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow("Show",img)
cv2.waitKey()
cv2.destroyAllWindows()
【问题讨论】:
-
嗨@atomheartmommy 将您的输入图像放到您的问题中。
标签: python opencv computer-vision