Exemplo n.º 1
0
    def preprocess(self, data):
        preprocessed_data = []
        data_infos = []
        for img in data:
            img = np.array(img)[:, :, ::-1]
            height, width, _ = img.shape
            if self.input_height / self.input_width < height / width:
                scale = self.input_height / height
            else:
                scale = self.input_width / width

            scaled_img = cv2.resize(
                img, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_CUBIC,
            )
            padded_img, pad = pad_img(
                scaled_img, (0, 0, 0), [self.input_height, self.input_width],
            )

            padded_img = padded_img.transpose((2, 0, 1))
            padded_img = padded_img[np.newaxis].astype(np.float32)
            preprocessed_data.append(padded_img)
            data_infos.append(
                DataInfo(
                    scales=(scale, scale),
                    pads=tuple(pad),
                    original_width=width,
                    original_height=height,
                ),
            )

        return [preprocessed_data, data_infos]
Exemplo n.º 2
0
 def forward(self, in_queue, out_queue, data):
     results = []
     if data is not None:
         for sample in data[0]:
             nn_data = dai.NNData()
             nn_data.setLayer("data", sample)
             in_queue.send(nn_data)
             assert wait_for_results(out_queue)
             results.append(out_queue.get())
         data[0] = results
     else:
         assert wait_for_results(out_queue)
         results.append(out_queue.get())
         data = [
             results,
             [
                 DataInfo(
                     scales=(
                         self.input_width / self.video_width,
                         self.input_height / self.video_height,
                     ),
                     pads=(0, 0),
                     original_width=self.video_width,
                     original_height=self.video_height,
                 ),
             ],
         ]
     return data
Exemplo n.º 3
0
 def preprocess(self, data):
     preprocessed_data = []
     data_infos = []
     for img in data:
         img = np.array(img)
         height, width, _ = img.shape
         scale_y = self.input_height / height
         scale_x = self.input_width / width
         resized_image = cv2.resize(
             img,
             (self.input_width, self.input_height),
             interpolation=cv2.INTER_CUBIC,
         )
         self.resized_image = resized_image
         resized_image = resized_image.transpose((2, 0, 1))
         resized_image = resized_image[np.newaxis].astype(np.float32)
         preprocessed_data.append(resized_image)
         data_infos.append(
             DataInfo(
                 scales=(scale_y, scale_x),
                 pads=(0, 0),
                 original_width=width,
                 original_height=height,
             ), )
     return [preprocessed_data, data_infos]
Exemplo n.º 4
0
 def preprocess(self, data):
     preprocessed_data = []
     data_infos = []
     for img in data:
         img = np.array(img)
         height, width, _ = img.shape
         scale_x = self.input_width / width
         scale_y = self.input_height / height
         scaled_img = cv2.resize(img, (self.input_height, self.input_width))
         scaled_img = scaled_img.astype(np.float32)
         scaled_img -= self.mean
         scaled_img = scaled_img.transpose((2, 0, 1))
         scaled_img = scaled_img[np.newaxis]
         data_infos.append(
             DataInfo(
                 scales=(scale_x, scale_y),
                 pads=(0, 0),
                 original_width=width,
                 original_height=height,
             ),
         )
         preprocessed_data.append(scaled_img)
     return [preprocessed_data, data_infos]