繁体   English   中英

如何获取图像中每个检测到的 object 的像素值?

[英]How to get the pixel values for each detected object in the image?

我对图像数据集进行了 object 检测,并将每个检测到的 object 的 bbox 坐标保存在 CSV 文件中,格式如下:xcenter、ycenter、宽度、高度。

我想获取每个检测到的像素值 object? 例如,在下图中,我想要每个边界框(汽车、自行车、狗)的像素值

在此处输入图像描述

我的代码:

imgs = PIL.Image.open(img_path).convert('RGB')
image_width, image_height = imgs.size
imgArrays = np.array(imgs)

X = (xCenter*image_width)          
Y = (yCenter*image_height)        
W = (Width*image_width)          
H = (Height*image_height)         
cropped_image = np.zeros((image_height, image_width, 3))
                         
for i in range(len(X)):
          x1, y1, w, h = X[i], Y[i], W[i], H[i]
          x_start = int(x1 - (w/2))
          y_start = int(y1 - (h/2))
          x_end = int(x_start + w)
          y_end = int(y_start + h)
                              
          temp = imgArrays[y_start: y_end, x_start: x_end]
          
          cropped_imagesList.append(temp)
          cropped_images = torch.as_tensor(cropped_imagesList)

我收到此错误:

<ipython-input-97-eb6b0d9d0073> in __getitem__(self, idx)
     75 
     76                  cropped_imagesList.append(temp)
---> 77                  cropped_images =torch.as_tensor(cropped_imagesList)
     78                 
      

ValueError: expected sequence of length 631 at dim 1 (got 284)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM