Пример #1
0
    def vdoLoop(self):
        with self.graph.as_default():
            while not self.stopEvent.is_set():
                obj = {}
                frame = cv2.imread(
                    f'/home/palm/PycharmProjects/seven/data1/1/1.jpg')

                draw = frame.copy()
                image = preprocess_image(frame)
                image, scale = resize_image(image, min_side=720, max_side=1280)
                boxes, scores, labels = self.model.predict_on_batch(
                    np.expand_dims(image, axis=0))

                boxes /= scale

                for box, score, label in zip(boxes[0], scores[0], labels[0]):
                    if score < 0.9:
                        break

                    b = box.astype(int)
                    draw = add_bbox(draw, b, label, self.labels_to_names,
                                    score)
                    if label not in obj:
                        obj[label] = 0
                    obj[label] += 1

                blk = ImageTk.PhotoImage(
                    Image.fromarray(cv2.resize(draw, (360, 640))[..., ::-1]))
                if self.weight > 10:
                    color = 'chartreuse3' if abs(
                        self.get_weight(obj) -
                        self.weight) < 20 else 'orangered'
                else:
                    color = 'cornflower blue'
                if self.panel is None:
                    self.panel = tk.Label(image=blk,
                                          borderwidth=0,
                                          highlightthickness=3,
                                          highlightbackground=color)
                    self.panel.image = blk
                    self.panel.grid(row=0, column=1, padx=2, pady=2)
                else:
                    self.panel.configure(image=blk,
                                         highlightthickness=3,
                                         relief="solid",
                                         highlightbackground=color)
                    self.panel.image = blk

                self.predictionLabel.config(state='normal')
                self.predictionLabel.delete(1.0, tk.END)
                self.predictionLabel.insert(
                    tk.END, f"Obj{' ' * 7}Qty{' ' * 7}Ttl wt. \n")
Пример #2
0
                os.makedirs(
                    f'/home/palm/PycharmProjects/seven2/xmls/readjusted/{set_name}/',
                    exist_ok=True)
                shutil.copy(
                    os.path.join(anns_path, i[:-4] + '.xml'),
                    f'/home/palm/PycharmProjects/seven2/xmls/readjusted/{set_name}/'
                    + i[:-4] + '.xml')
                continue
            image = read_image_bgr(os.path.join(folder, i))
            start_time = time.time()
            # copy to draw ong
            draw = image.copy()
            draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)

            # preprocess image for network
            image = preprocess_image(image)
            image, scale = resize_image(image, min_side=720, max_side=1280)

            # process image
            boxes, scores, labels = prediction_model.predict_on_batch(
                np.expand_dims(image, axis=0))

            # correct for image scale
            boxes /= scale

            root = ET.Element('annotation')
            ET.SubElement(root, 'filename').text = i
            ET.SubElement(root, 'path').text = os.path.join(folder, i)
            size = ET.SubElement(root, 'size')
            ET.SubElement(size, 'width').text = str(draw.shape[1])
            ET.SubElement(size, 'height').text = str(draw.shape[0])
Пример #3
0
 def preprocess_image(self, inputs):
     """ Takes as input an image and prepares it for being passed through the network.
     """
     return preprocess_image(inputs, mode='tf')
Пример #4
0
    for file in os.listdir('/media/palm/BiggerData/mine/new/v/'):
        cap = cv2.VideoCapture(
            os.path.join('/media/palm/BiggerData/mine/new/v/', file))
        fourcc = cv2.VideoWriter_fourcc(*'MP4V')
        out = cv2.VideoWriter(f'/media/palm/BiggerData/mine/out/{file}.mp4',
                              fourcc, 20.0, (1333, 750))
        f = 0
        while cap.isOpened():
            ret, frame = cap.read()
            if frame is None:
                break
            frame = cv2.resize(frame, (1333, 750))
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
            image = preprocess_image(frame)
            boxes, scores, labels = prediction_model.predict_on_batch(
                np.expand_dims(image, axis=0))
            for box, score, label in zip(boxes[0], scores[0], labels[0]):
                # scores are sorted so we can break
                if score < 0.5:
                    break
                b = box.astype(int)

                frame = add_bbox(frame, b, label, ['crane', 'car', 'human'],
                                 score)
            out.write(frame)

        cap.release()
        out.release()
    cv2.destroyAllWindows()