[英]saving the bounding box image
Instead of trying to draw the bounding box over the image, i am trying to save it as a new image. 我没有尝试在图像上绘制边框,而是尝试将其另存为新图像。
When i was getting [ymin, xmax, ymax, xmin] points, i was doing this. 当我获得[ymin,xmax,ymax,xmin]点时,我正在这样做。
import cv2
import numpy as np
image = cv2.imread('ballet_106_0.jpg')
image = np.array(image)
boxes = [21, 511, 41, 420 ]
ymin, xmax , ymax ,xmin = boxes
im2 = image[ymin:ymax,xmin:xmax,:]
cv2.imwrite('bboximage.jpg',im2)
But if i only get the x
and y
points along with the height
and width
. 但是如果我只得到
x
和y
点以及height
和width
。 I'm not sure how i could index the numpy array. 我不确定如何索引numpy数组。
Any suggestions would be really helpful ,Thanks in advance. 任何建议都会非常有帮助,谢谢。
Your code looks ok, though this line: 您的代码看起来不错,尽管以下行:
image = np.array(image)
is not required, as if everything goes well cv2.imread
produce np.array
, however if cv2.imread
fails it returns None
, which might be source of your problem, please add following line below your cv2.imread
: 不是必需的,好像一切都很好
cv2.imread
产生np.array
,但是如果cv2.imread
失败,它将返回None
,这可能是问题的根源,请在cv2.imread
下面添加以下行:
print(type(image))
if it prints None
, it most probably means that there is not ballet_106_0.jpg
image in your directory. 如果显示
None
,则很可能意味着您的目录中没有ballet_106_0.jpg
图像。
EDIT: To convert x,y,height,width
to x/y-min/max
values simply do 编辑:要将
x,y,height,width
转换为x/y-min/max
值,只需执行
ymin = y
ymax = y+height
xmin = x
xmax = x+width
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.