Esempio n. 1
0
    def get_scores_new(self, pos_x, pos_y, scaled_search_area, template_z,
                       filename, design, final_score_sz):
        image = Image.open(filename).convert('RGB')
        # avg_chan = ImageStat.Stat(image).mean
        # frame_padded_x, npad_x = pad_frame(image, image.size, pos_x, pos_y, scaled_search_area[2], avg_chan)
        # x_crops = extract_crops_x(frame_padded_x, npad_x, pos_x, pos_y, scaled_search_area[0], scaled_search_area[1], scaled_search_area[2], design.search_sz)
        txs = []
        for scale in scaled_search_area:
            x = gen_xz(image, Rectangle(pos_x, pos_y, scale, scale), to='x')

            tx = Image_to_Tensor(x).unsqueeze(0)
            txs.append(tx.squeeze(0))
        x_crops = torch.stack(txs)
        # print Rectangle(pos_x, pos_y,scale,scale)
        template_x = self.branch(Variable(x_crops).cuda())

        template_z = template_z.repeat(template_x.size(0), 1, 1, 1)

        scores = self.model.head(template_z, template_x)

        # scores = self.bn_adjust(scores)
        # TODO: any elegant alternator?
        scores = scores.squeeze().permute(1, 2, 0).data.cpu().numpy()
        scores_up = cv2.resize(scores, (final_score_sz, final_score_sz),
                               interpolation=cv2.INTER_CUBIC)
        scores_up = scores_up.transpose((2, 0, 1))
        return image, scores_up
Esempio n. 2
0
    def get_template_z_new(self, pos_x, pos_y, z_sz, image, design):
        if isinstance(image, six.string_types):
            image = Image.open(image).convert('RGB')
        # avg_chan = ImageStat.Stat(image).mean
        # frame_padded_z, npad_z = pad_frame(image, image.size, pos_x, pos_y, z_sz, avg_chan)
        # z_crops = extract_crops_z(frame_padded_z, npad_z, pos_x, pos_y, z_sz, design.exemplar_sz)
        z = gen_xz(image, Rectangle(pos_x, pos_y, z_sz, z_sz), to='z')
        # cv2.imshow('z', np.array(z))
        tz = Image_to_Tensor(z).unsqueeze(0)
        template_z = self.branch(Variable(tz).cuda())

        # print template_z same
        return image, template_z