如何根据Python OpenCV中的坐标来裁剪图像
我正在使用以下行绘制CV2矩形
cv2.rectangle(rightImg, (x, y), (x + w, y + h), (0, 0, 255), 2)
,现在
x = 93
y = 62
w = 6
h = 3
我想裁剪矩形的那一部分。在下面的代码线上确实有意义:
cropImg = rightImg[y:x, y+h:x+w]
或者
cropImg = rightImg[y+h:x+w, y:x]
我尝试了以上两者,但这并没有裁剪确切的区域。接下来我可以尝试什么?
I am drawing a cv2 rectangle by using below line
cv2.rectangle(rightImg, (x, y), (x + w, y + h), (0, 0, 255), 2)
Now values are
x = 93
y = 62
w = 6
h = 3
Now I want to crop that part of the rectangle. Does below line of code make sense:
cropImg = rightImg[y:x, y+h:x+w]
or
cropImg = rightImg[y+h:x+w, y:x]
I have tried both of the above but it's not cropping the exact area. What can I try next?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你应该尝试
you should try
这已经在这里得到回答:
如何使用 Python 在 OpenCV 中裁剪图像
小心标记为重复项。
This is already answered here:
How to crop an image in OpenCV using Python
Be careful of marked as duplicates.
它可能看起来有点奇怪,但你必须先写出 y 坐标。
它将在矩形所在的位置裁剪图像。
It may look a bit weird but you have to write the y coordinates first.
It will crop the image at where the rectangle is.