Exemple #1
0
def main(args):
    """ Show detected objects with boxes, lables and prediction scores in a vide stream
    """
    # Load yolo model with pretrained weights
    print("Create YoloV3 model")
    config_parser = ConfigParser(args.config)
    model = config_parser.create_model(skip_detect_layer=False)
    detector = config_parser.create_detector(model)

    # Open video stream
    cap = cv2.VideoCapture(args.camera)
    if (cap.isOpened() == False):
        print("(Error) Could not open video stream")
        exit()

    # Detect objects in stream
    times = []
    detect = 0
    while True:

        # Capture every nth frame only because we are too slow
        # to capture every frame...
        ret, image = cap.read()

        #image, _ = resize_image(image, None, config_parser.get_net_size(), keep_ratio=True)
        if not ret:
            print("(Error) Lost connection to video stream")
            break

        # Detect objects and measure timing
        if detect <= 0:
            t1 = time.time()
            min_prob = 0.90
            boxes, labels, probs = detector.detect(image, min_prob)
            t2 = time.time()
            times.append(t2 - t1)
            times = times[-20:]
            detect = 50
        detect -= 1

        # Display detected objects
        visualize_boxes(image, boxes, labels, probs,
                        config_parser.get_labels())
        image = cv2.putText(
            image, "Time: {:.2f}ms".format(sum(times) / len(times) * 1000),
            (0, 30), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 2)
        cv2.imshow('Frame', image)

        # Exit with 'q'
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
Exemple #2
0
def main():
    args = argparser.parse_args()

    # 1. create yolo model & load weights
    config_parser = ConfigParser(args.config)
    model = config_parser.create_model(skip_detect_layer=False)
    detector = config_parser.create_detector(model)
    labels = config_parser.get_labels()

    for image in args.images:
        predictImage(image, detector, labels)

    saveResults()
    return 0
Exemple #3
0
    help='path to image file')


if __name__ == '__main__':
    args = argparser.parse_args()
    image_path   = args.image
    
    # 1. create yolo model & load weights
    config_parser = ConfigParser(args.config)
    model = config_parser.create_model(skip_detect_layer=False)
    detector = config_parser.create_detector(model)
    
    # 2. Load image
    image = cv2.imread(image_path)
    image = image[:,:,::-1]
    
    # 3. Run detection
    boxes, labels, probs = detector.detect(image, 0.5)
    print(probs)
    
    # 4. draw detected boxes
    visualize_boxes(image, boxes, labels, probs, config_parser.get_labels())

    # 5. plot    
    plt.imshow(image)
    plt.show()

 


    # 3. Run detection
    boxes, labels, probs = detector.detect(image, 0.5)

    # print(list(zip(labels, probs)))

    if len(labels) == 0:
        print(image_path, "nothing found")

    for (l, p) in zip(labels, probs):
        print(image_path, class_labels[l], p)

    # # 4. draw detected boxes
    # visualize_boxes(image, boxes, labels, probs, config_parser.get_labels())
    #
    # # 5. plot
    # plt.imshow(image)
    # plt.show()


if __name__ == '__main__':
    args = argparser.parse_args()

    # 1. create yolo model & load weights
    config_parser = ConfigParser(args.config)
    model = config_parser.create_model(skip_detect_layer=False)
    detector = config_parser.create_detector(model)
    labels = config_parser.get_labels()

    for image in args.images:
        predictImage(image, detector, labels)
            counting += 1

            if (log_progress == True):
                print("Processing Frame : ", str(counting))

            check_frame_interval = counting % frame_detection_interval

            if (counting == 1 or check_frame_interval == 0):
                try:
                    # detected_frame, output_objects_array = self.__detector.detectObjectsFromImage(
                    #     input_image=frame, input_type="array", output_type="array",
                    #     minimum_percentage_probability=minimum_percentage_probability,
                    #     display_percentage_probability=display_percentage_probability,
                    #     display_object_name=display_object_name)
                    detected_frame_pre, output_objects_array, pred = detector.detect(frame, 0.2)
                    visualize_boxes(frame, detected_frame_pre, output_objects_array, pred, config_parser.get_labels())
                    detected_frame = frame

                    # plt.imshow(detected_frame)
                    # plt.show()
                except:
                    print('none')
                    None


            output_frames_dict[counting] = output_objects_array

            output_objects_count = {}
            for eachItem in output_objects_array:
                eachItemName = eachItem
                try: