Opencv找到roi图像的坐标

时间:2017-10-16 18:09:02

标签: opencv

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

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. 如何找到感兴趣区域项的坐标?

2 个答案:

答案 0 :(得分:1)

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

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

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

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

答案 1 :(得分: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.

相关问题