Exemplo n.º 1
0
    def updateGUI(self):
        """
        update the GUI based on img_index
        :return:
        """
        row = self.df.iloc[self.img_index]

        # update path
        new_path = "{0}/{1}.jpg".format(row.trial, row.img_id)

        # update path_lbl
        new_lbl = "Path: {0}/{1}.jpg".format(row.trial, row.img_id)
        self.path_lbl.configure(text=new_lbl)

        # update pager
        new_text = "{0}/{1}".format(self.img_index + 1, self.n_img)
        self.pager_lbl.configure(text=new_text)

        # update status
        self.status_lbl.configure(text=str(row.status))

        # update truth and predicted labels
        new_x = "x:\t{0:5.1f}  {1:5.1f}".format(row.xt, row.xp)
        self.x_lbl.configure(text=new_x)

        new_y = "y:\t{0:5.1f}  {1:5.1f}".format(row.yt, row.yp)
        self.y_lbl.configure(text=new_y)

        new_w = "w:\t{0:5.1f}  {1:5.1f}".format(row.wt, row.wp)
        self.w_lbl.configure(text=new_w)

        new_h = "h:\t{0:5.1f}  {1:5.1f}".format(row.ht, row.hp)
        self.h_lbl.configure(text=new_h)

        new_ang = "a:\t{0:5.1f}  {1:5.1f}".format(row.angt, row.angp)
        self.a_lbl.configure(text=new_ang)

        # update image holder
        # load image
        img = cv2.imread(new_path, cv2.IMREAD_GRAYSCALE)
        truth = [row.xt, row.yt, row.wt, row.ht, row.angt]
        pred = [row.xp, row.yp, row.wp, row.hp, row.angp]

        # update thumbnails before manipulation
        s_img = np.asarray(img, dtype=np.uint8)
        s_img = Image.fromarray(s_img, 'L')
        self.photo_s = ImageTk.PhotoImage(image=s_img)
        self.canvas_s.itemconfig(self.image_refs, image=self.photo_s)

        # Update the labeled image
        img = annotator((120, 120, 120), img, *pred)  # gray
        img = annotator((0, 250, 0), img, *truth)  # Green

        img = numpy2pil(img)
        img = img.resize((576, 576), )
        self.photo = ImageTk.PhotoImage(image=img)
        self.canvas.itemconfig(self.image_ref, image=self.photo)
Exemplo n.º 2
0
    def capture(self):
        row = self.df.iloc[self.img_index]
        new_path = "{0}/{1}.jpg".format(row.trial, row.img_id)

        img = cv2.imread(new_path, cv2.IMREAD_GRAYSCALE)

        truth = [row.xt, row.yt, row.wt, row.ht, row.angt]
        pred = [row.xp, row.yp, row.wp, row.hp, row.angp]

        # Update the labeled image
        img = annotator((120, 120, 120), img, *pred)  # gray
        img = annotator((0, 250, 0), img, *truth)  # Green

        save_path = new_path.replace("/", "-")
        cv2.imwrite("purifier/" + save_path, img)
Exemplo n.º 3
0
def main(m_type, m_name, logger, video_path=None, write_output=True):
    with tf.Session() as sess:

        # load best model
        model = load_model(sess, m_type, m_name, logger)

        # check input source is a file or camera
        if video_path == None:
            video_path = 0

        # load the video or camera
        cap = cv2.VideoCapture(video_path)
        ret = True
        counter = 0
        tic = time.time()
        frames = []
        preds = []

        while ret:
            ret, frame = cap.read()

            if ret:
                # Our operations on the frame come here
                frames.append(frame)
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                f_shape = frame.shape
                if frame.shape[0] != 192:
                    frame = rescale(frame)

                image = gray_normalizer(frame)
                image = change_channel(image, config["input_channel"])
                [p] = model.predict(sess, [image])
                x, y, w = upscale_preds(p, f_shape)

                preds.append([x, y, w])
                # frames.append(gray)
                counter += 1

        toc = time.time()
        print("{0:0.2f} FPS".format(counter / (toc - tic)))

    # get the video size
    video_size = frames[0].shape[0:2]
    if write_output:
        # prepare a video write to show the result
        video = cv2.VideoWriter("predicted_video.avi",
                                cv2.VideoWriter_fourcc(*"XVID"), 15,
                                (video_size[1], video_size[0]))

        for i, img in enumerate(frames):
            labeled_img = annotator((0, 250, 0), img, *preds[i])
            video.write(labeled_img)

        # close the video
        cv2.destroyAllWindows()
        video.release()
    print("Done...")
Exemplo n.º 4
0
    def capture(self):
        row = self.current_df.iloc[self.img_index]

        img = cv2.imread(row.path, cv2.IMREAD_GRAYSCALE)

        truth = [row.xt, row.yt, row.wt, row.ht, row.angt]

        # Update the labeled image
        img = annotator((0, 250, 0), img, *truth)  # Green

        save_path = row.path.replace("/", "-")
        cv2.imwrite("purifier/" + save_path, img)
Exemplo n.º 5
0
def video_creator(video_name, images, labels, fps=15):
    """
    get a list of images and their corresponidng labels and create a labeled video
    :param video_name: the output video name
    :param images: test images with shape (192,192,1) which should squeezed before writing the video
    :param labels: predicted labels with a value between 0-1
    :return: None
    """
    f_size = images[0].shape
    video = cv2.VideoWriter(video_name + " pred.mp4",
                            cv2.VideoWriter_fourcc(*'MP4V'), fps,
                            (f_size[1], f_size[0]))

    for img, lbl in zip(images, labels):
        img = np.squeeze(img)
        # img = gray_denormalizer(img)
        annotated_img = annotator((0, 250, 0), img, *lbl)
        video.write(annotated_img)

    cv2.destroyAllWindows()
    video.release()
    print("{} video has been created successfully".format(video_name))
Exemplo n.º 6
0
    def updateGUI(self):
        """
        update the GUI based on img_index
        :return:
        """
        row = self.current_df.iloc[self.img_index]

        # update pager
        new_text = "{0}/{1}".format(self.img_index + 1, self.n_img)
        self.pager_lbl.configure(text=new_text)

        # update status
        self.status_lbl.configure(text=str(row.status))

        # update image holder
        # load image
        file = row.path.split(".")[0]
        file = file + ".bmp"
        if row.status == 2:
            img = cv2.imread(file, cv2.IMREAD_GRAYSCALE)

        else:
            img = cv2.imread(file, cv2.IMREAD_GRAYSCALE)

        # update thumbnails before manipulation
        s_img = np.asarray(img, dtype=np.uint8)
        s_img = Image.fromarray(s_img, 'L')
        self.photo_s = ImageTk.PhotoImage(image=s_img)
        self.canvas_s.itemconfig(self.image_refs, image=self.photo_s)

        # resize image 3x and put label on it
        img = cv2.resize(img, (576, 576))
        truth = [row.xt * 3, row.yt * 3, row.wt * 3, row.ht * 3, row.angt]
        img = annotator((0, 250, 0), img, *truth)  # Green

        img = numpy2pil(img)
        self.photo = ImageTk.PhotoImage(image=img)
        self.canvas.itemconfig(self.image_ref, image=self.photo)