[英]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.