【发布时间】:2021-11-27 08:58:13
【问题描述】:
我在原始图像中绘制了一个旋转的矩形。是否可以仅在旋转的矩形框中进行图像处理而不将其从原始图像中裁剪出来?
original = cv2.imread(r'image.jpg')
ori_img = original.copy()
img = cv2.cvtColor(ori_img, cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img,(5,5),0)
_, thresh = cv2.threshold(img, 130, 255, cv2.THRESH_BINARY_INV)
contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for cnt in contours:
[x, y, w, h] = cv2.boundingRect(cnt)
if (w*h) >= 10000:
box = cv2.minAreaRect(np.asarray(cnt))
pts = cv2.boxPoints(box)
pts = np.int0(pts)
cv2.drawContours(ori_img, [pts], 0, (0,255,0), 3)
cv2.namedWindow('Frame', cv2.WINDOW_NORMAL)
cv2.imshow('Frame',ori_img)
k = cv2.waitKey(0)
【问题讨论】:
-
你想做什么图像处理?
-
@Abhi25t 模糊、阈值、canny 等
-
你说的是什么意思:没有从原始图像中裁剪出来你的绘图也不是矩形
标签: python numpy opencv image-processing opencv-python