简体   繁体   中英

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

I did object detection for the image dataset and I saved the bbox coordinates for each detected object in a CSV file like this format: xcenter, ycenter, width, height.

I want to get the pixel values for each detected object? For example, at the image below, I want the pixel values for each bounding boxes (car, bicycle, dog)

在此处输入图像描述

my code:

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)

I got this error:

<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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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