gpt4 book ai didi

python - 使用Python将OpenCV cv.Rectangle(img,pt1,pt2)转换为NumPy数组

转载 作者:行者123 更新时间:2023-12-02 16:20:55 24 4
gpt4 key购买 nike

我知道Rectange(x1,y1,x2,y2)的坐标,我想裁剪矩形部分

我尝试了与绘制矩形进行裁剪相同的坐标参数。

black = np.zeros((1080, 720, 3), dtype = "uint8")
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
cv2.rectangle(black, (80,500), (150, 600), (0,255,0), 1, 8, 0)
crop = frame[80:500,150:600]
cv2.imshow("Black", black)
cv2.imshow("crop", crop)
cv2.imshow("Orginal", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

选择的输出不是黑色绘制的矩形。

最佳答案

Numpy索引的工作方式如下:

crop = frame[y1:y2, x1:x2]

因此,您需要:
crop = frame[80:150, 500:600]

而不是:
crop = frame[80:500, 150:600]

或许:
crop = frame[500:600, 80:150]

但是我没有安装OpenCV进行检查。

关于python - 使用Python将OpenCV cv.Rectangle(img,pt1,pt2)转换为NumPy数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56649730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com