Esempio n. 1
0
def visualization(val_data, idx, grasps_pre, grasps_true):
    #最开始的几个迭代过程中不会有q_img值足够大的预测出现,所以,此时提出不出有效的抓取,进而是不会有visuaization出现的
    img = Image.from_file(val_data.dataset.rgbf[idx])
    left = val_data.dataset._get_crop_attrs(idx)[1]
    top = val_data.dataset._get_crop_attrs(idx)[2]
    img.crop((left, top), (left + 300, top + 300))

    a = img.img

    a_points = grasps_pre[0].as_gr.points.astype(np.uint8)  #预测出的抓取
    b_points = grasps_true.points
    color1 = (255, 255, 0)
    color2 = (255, 0, 0)
    for i in range(3):
        img = cv2.line(a, tuple(a_points[i]), tuple(a_points[i + 1]),
                       color1 if i % 2 == 0 else color2, 1)
    img = cv2.line(a, tuple(a_points[3]), tuple(a_points[0]), color2, 1)

    color1 = (0, 0, 0)
    color2 = (0, 255, 0)

    for b_point in b_points:
        for i in range(3):
            img = cv2.line(a, tuple(b_point[i]), tuple(b_point[i + 1]),
                           color1 if i % 2 == 0 else color2, 1)
        img = cv2.line(a, tuple(b_point[3]), tuple(b_point[0]), color2, 1)
    #cv2.imshow('img',a)
    cv2.imwrite('img.png', a)
 def get_rgb(self, idx):
     '''
     :功能     :读取返回指定id的rgb图像
     :参数 idx :int,要读取的数据id
     :返回     :ndarray,处理好后的rgb图像
     '''
     rgb_img = Image.from_file(self.rgbf[idx])
     rgb_img.normalize()
     center, left, top = self._get_crop_attrs(idx)
     rgb_img.crop((left, top),
                  (left + self.output_size, top + self.output_size))
     return rgb_img.img
    def get_rgb(self, idx, rot=0, zoom=1.0, normalize=True):
        rgb_img = Image.from_file(self.rgbf[idx])
        center, left, top = self._get_crop_attrs(idx)
        #先旋转后裁剪再缩放最后resize
        rgb_img.rotate(rot, center)
        rgb_img.crop((top, left), (min(
            480, top + self.output_size), min(640, left + self.output_size)))
        rgb_img.zoom(zoom)
        rgb_img.resize((self.output_size, self.output_size))
        if normalize:
            rgb_img.normalize()
            rgb_img.img = rgb_img.img.transpose((2, 0, 1))

        return rgb_img.img
Esempio n. 4
0
 def get_rgb(self,idx,rot = 0,zoom = 1.0,normalize = True):
     '''
     :功能     :读取返回指定id的rgb图像
     :参数 idx :int,要读取的数据id
     :返回     :ndarray,处理好后的rgb图像
     '''
     rgb_img = Image.from_file(self.rgbf[idx])
     rgb_img.rotate(rot)
     rgb_img.zoom(zoom)
     #注意,这里暂且不论是否zoom,图像是直接由(1024X1024)resize成为了(300X300)的,相应的抓取框标注也必须进行同样程度的“resize”或者说缩放(scale)才行
     rgb_img.resize((self.output_size, self.output_size))
     if normalize:
         rgb_img.normalize()
         rgb_img.img = rgb_img.img.transpose((2, 0, 1))
         #这里还有一句transpose没写,先不管
     return rgb_img.img
Esempio n. 5
0
 def get_rgb(self,idx,rot=0, zoom=1.0):
     '''
     :功能     :读取返回指定id的rgb图像
     :参数 idx :int,要读取的数据id
     :返回     :ndarray,处理好后的rgb图像
     '''
     rgb_img = Image.from_file(self.rgbf[idx])
     rgb_img.normalize()
     center,left,top = self._get_crop_attrs(idx)
     #先旋转后裁剪再缩放最后resize
     rgb_img.rotate(rot,center)
     rgb_img.crop((left,top),(left+self.output_size,top+self.output_size))
     rgb_img.zoom(zoom)
     rgb_img.resize((self.output_size, self.output_size))
     
     return rgb_img.img