Beispiel #1
0
    def processImages(self):
        imagePaths = list(paths.list_images(config.ORIG_IMAGES))
        for (i, imagePath) in enumerate(imagePaths):
            print("[+] processing image {}/{}...".format(
                i + 1, len(imagePaths)))
            fname = imagePath.split(os.path.sep)[-1]
            fname = fname[:fname.rfind(".")]
            annotPath = os.path.sep.join([config.ORIG_ANNOTS, f"{fname}.xml"])
            gtBoxes = self.parseXMLAnnotations(annotPath)

            image = cv2.imread(imagePath)
            proposedRects = self.runSS(image)
            positiveROIs = 0
            negativeROIs = 0

            if len(gtBoxes) == 0:
                filename = f"{self.counters[self.get_counter_index('nothing')]['counter']}.png"
                outputPath = os.path.sep.join([
                    config.LABELS_PATH[self.get_counter_index('nothing')],
                    filename
                ])
                roi = cv2.resize(image,
                                 config.INPUT_DIMS,
                                 interpolation=cv2.INTER_CUBIC)
                cv2.imwrite(outputPath, roi)
                self.counters[self.get_counter_index(
                    'nothing')]['counter'] += 1
            else:
                for proposedRect in proposedRects:
                    (propStartX, propStartY, propEndX, propEndY) = proposedRect

                    for gtBox in gtBoxes:
                        iou = compute_iou(gtBox[1:], proposedRect)
                        (label, gtStartX, gtStartY, gtEndX, gtEndY) = gtBox
                        #filename = f"{self.counters[self.get_counter_index('nothing')]['counter']}.png"
                        #negativeROIs += 1

                        roi = None
                        outputPath = None

                        if iou > 0.7 and positiveROIs <= config.MAX_POSITIVE and label == "stop_sign":
                            roi = image[propStartY:propEndY,
                                        propStartX:propEndX]
                            filename = f"{self.counters[self.get_counter_index(label)]['counter']}.png"
                            outputPath = os.path.sep.join([
                                config.LABELS_PATH[self.get_counter_index(
                                    label)], filename
                            ])
                            positiveROIs += 1
                            self.counters[self.get_counter_index(
                                label)]['counter'] += 1

                        if not self.isFullOverlap(
                                gtBox, proposedRect
                        ) and iou < 0.05 and negativeROIs <= config.MAX_NEGATIVE:
                            roi = image[propStartY:propEndY,
                                        propStartX:propEndX]
                            filename = f"{self.counters[self.get_counter_index('nothing')]['counter']}.png"
                            outputPath = os.path.sep.join([
                                config.LABELS_PATH[self.get_counter_index(
                                    label)], filename
                            ])
                            negativeROIs += 1

                        if roi is not None and outputPath is not None:
                            roi = cv2.resize(roi,
                                             config.INPUT_DIMS,
                                             interpolation=cv2.INTER_CUBIC)
                            cv2.imwrite(outputPath, roi)
Beispiel #2
0
    # loop over the maximum number of region proposals
    for proposedRect in proposedRects[:config.MAX_PROPOSALS]:
        # unpack the proposed rectangle bounding box
        (propStartX, propStartY, propEndX, propEndY) = proposedRect

        # loop over the ground-truth bounding boxes
        for label, gtBox in gtBoxes:

            # compute the intersection over union between the two
            # boxes and unpack the ground-truth bounding box
            (gtStartX, gtStartY, gtEndX, gtEndY) = gtBox
            (gtStartX, gtStartY, gtEndX,
             gtEndY) = (int(gtStartX / w_fact), int(gtStartY / h_fact),
                        int(gtEndX / w_fact), int(gtEndY / h_fact))
            gtBox = (gtStartX, gtStartY, gtEndX, gtEndY)
            iou = compute_iou(gtBox, proposedRect)
            # (gtStartX, gtStartY, gtEndX, gtEndY) = gtBox
            # print((gtStartX, gtStartY, gtEndX, gtEndY))
            # (gtStartX, gtStartY, gtEndX, gtEndY) = (int(gtStartX/w_fact), int(gtStartY/h_fact), int(gtEndX/w_fact), int(gtEndY/h_fact))
            # print((gtStartX, gtStartY, gtEndX, gtEndY))

            # initialize the ROI and output path
            roi = None
            outputPath = None

            # check to see if the IOU is greater than 70% *and* that
            # we have not hit our positive count limit
            if iou > 0.7 and positiveROIs <= config.MAX_POSITIVE:
                # extract the ROI and then derive the output path to
                # the positive instance
                print("positiveROIs", positiveROIs, config.MAX_POSITIVE)