Opencv找到roi图像的坐标

问题描述 投票:1回答:2

我有这个图像,需要头部起点和终点的坐标(直到颈部)。

enter image description here

我使用下面的代码裁剪图像,但得到以下错误: -

import cv2
img = cv2.imread("/Users/pr/images/dog.jpg")
print img.shape
crop_img = img[400:500, 500:400] # Crop from x, y, w, h -> 100, 200, 300, 400
# NOTE: its img[y: y + h, x: x + w] and *not* img[x: x + w, y: y + h]
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)

错误:-

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 325

题:-

  1. 如何找到感兴趣区域项的坐标?
opencv
2个回答
1
投票

如果你想选择矩形:x = 100, y =200, w = 300, h = 400,你应该使用代码:

crop_img = img[200:600, 100:300]

如果你想要切狗的头,你需要:

crop_img = img[0:230, 250:550]

0
投票

如果您试图找到必须在img []中使用的图像的像素坐标,您可以简单地使用ms绘制来查找像素位置。例如

img [y1:y2,x1:x2],在这里找到x1,x2,y1和y2的值,你可以用ms绘画打开图像,并将光标放在你需要坐标的位置。 Paint将在mspaint窗口的左下角显示该像素的坐标。将此位置视为(x,y)。

Screenshot of using MSpaint for getting pixel location.

© www.soinside.com 2019 - 2024. All rights reserved.