示例#1
0
                    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])
示例#2
0
        anns_path = f'/home/palm/PycharmProjects/seven2/xmls/revised/{set_name}'
        exiting_anns = [os.path.basename(x) for x in os.listdir(anns_path)]
        for i in os.listdir(folder):
            if i[:-4] + '.xml' in exiting_anns:
                continue
            if 'txt' in i:
                continue
            image = read_image_bgr(os.path.join(folder, i))

            # 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=800, max_side=1333)

            # process image
            start = time.time()
            boxes, scores, labels = prediction_model.predict_on_batch(np.expand_dims(image, axis=0))
            print("processing time: ", time.time() - start)

            # 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 resize_image(self, image):
     """ Resize an image using image_min_side and image_max_side.
     """
     return resize_image(image,
                         min_side=self.image_min_side,
                         max_side=self.image_max_side)
示例#4
0
            continue
        found.append(p)
        image = read_image_bgr(p)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = np.concatenate((np.expand_dims(
            image, 2), np.expand_dims(image, 2), np.expand_dims(image, 2)), 2)
        # copy raw image for license plate ocr
        raw_im = image.copy()

        # copy to draw on
        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=smin, max_side=smax)

        # process image
        start = time.time()
        boxes, scores, labels = model.predict_on_batch(
            np.expand_dims(image, axis=0))
        ptime = time.time() - start

        # correct for image scale
        boxes /= scale

        # visualize detections
        wrong_labels = []
        right_label = []
        for box, score, label in zip(boxes[0], scores[0], labels[0]):
            # scores are sorted so we can break