简体   繁体   English

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

[英]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.我对图像数据集进行了 object 检测,并将每个检测到的 object 的 bbox 坐标保存在 CSV 文件中,格式如下:xcenter、ycenter、宽度、高度。

I want to get the pixel values for each detected object?我想获取每个检测到的像素值 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)

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

相关问题 获取图像中每个像素的坐标 - get coordinate of each pixel in an image 如何用图像的每个像素的值绘制3d图形? - How to plot 3d graphics with the values of each pixel of the image? 如何获取图像内矩形内的像素值 - How to get pixel values inside of a rectangle within an image 在pyrender中将场景渲染为图像后如何获取对象的像素坐标? - How to get pixel coordinates of object after rendering the scene as image in pyrender? 如何在python中找到yolo检测到的物体的像素值? - How to find the pixel values of objects detected from yolo in python? 如何使用图像中每个像素的颜色绘制图形? - How to plot graphics with the colors of each pixel in the image? 如何在python中更改图像中每个像素的值? - How to change the value of each pixel in an image in python? 如何为图像中的每个像素分配特定颜色 - How to assign particular color to each pixel in image 如何对图像张量进行装箱,以便将每个像素值装箱/存储为张量流中10个值中的1个 - How to bin an image tensor so that each pixel value is binned/bucketed into 1 of 10 values in tensorflow Object 使用 YOLO 检测:获取每个检测到的 object 的计数 - Object Detection using YOLO : get count of each detected object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM