示例#1
0
    def run(self):
        detector = ObjectDetection(
        ) if self.type_file == "img" else VideoObjectDetection()

        settings = QSettings(CONFIG_FILE_NAME, QSettings.IniFormat)
        model = settings.value(KEY_SAVE_MODEL, MODELS[0], type=str)

        if model == MODELS[0]:
            detector.setModelTypeAsRetinaNet()
            file = MODEL_RETINA_NET
        elif model == MODELS[1]:
            detector.setModelTypeAsYOLOv3()
            file = MODEL_YOLOv3
        else:
            detector.setModelTypeAsTinyYOLOv3()
            file = MODEL_TINY_YOLOv3

        detector.setModelPath(file)
        detector.loadModel(self.window.detection_speed)

        if self.type_file == "img":
            detections = detector.detectObjectsFromImage(
                input_image=self.new_file,
                output_image_path=self.output_file,
                **self.window.getFunctionArg())

            self._print_table_txt({
                name: len(
                    list(
                        filter(
                            lambda elem: True
                            if elem["name"] == name else False, detections)))
                for name in set([obj["name"] for obj in detections])
            })

        elif self.type_file == "video":
            detector.detectObjectsFromVideo(
                input_file_path=self.new_file,
                output_file_path=self.output_file,
                video_complete_function=self.forFull,
                **self.window.getFunctionArg())
        else:
            camera = cv2.VideoCapture(self.window.index)

            detector.detectObjectsFromVideo(
                camera_input=camera,
                output_file_path=self.output_file,
                video_complete_function=self.forFull,
                **self.window.getFunctionArg())
示例#2
0
exec_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(exec_path, "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()

list = detector.detectCustomObjectsFromImage(
    input_image=os.path.join(exec_path, "objects.jpg"),
    output_image_path=os.path.join(exec_path, "new_objects.jpg"),
    minimum_percentage_probability=70,
    display_percentage_probability=True,
    display_object_name=False)

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "traffic.mp4"),
    output_file_path=os.path.join(execution_path, "traffic_detected"),
    frames_per_second=20,
    log_progress=True)

print(video_path)