Esempio n. 1
0
def user_test_cam_sync_yolo(dev_idx, _user_id, test_loop):
    """User test cam yolo."""
    image_source_w = 640
    image_source_h = 480
    image_size = image_source_w * image_source_h * 2
    frames = []

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, ISI_YOLO_ID, image_source_w,
                             image_source_h):
        return -1

    # Fill up the image buffers.
    img_id_tx = 0
    start_time = time.time()
    while (img_id_tx != test_loop):
        kdp_wrapper.sync_inference(dev_idx, ISI_YOLO_ID, image_size, capture,
                                   img_id_tx, frames, handle_result)
        img_id_tx += 1
    end_time = time.time()
    diff = end_time - start_time
    estimate_runtime = float(diff / test_loop)
    fps = float(1 / estimate_runtime)
    print("Sync inference average estimate runtime is ", estimate_runtime)
    print("Average FPS is ", fps)

    return 0
Esempio n. 2
0
def user_test_cam_ssd_fd(dev_idx, _user_id, test_loop):
    """User test cam yolo."""
    image_source_h = 480
    image_source_w = 640
    app_id = constants.APP_FD_LM
    image_size = image_source_w * image_source_h * 2
    frames = []

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, app_id, image_source_w, image_source_h):
        return -1

    # Fill up the image buffers.
    ret, img_id_tx, img_left, buffer_depth = kdp_wrapper.fill_buffer(
        dev_idx, capture, image_size, frames)
    if ret:
        return -1

    # Send the rest and get result in loop, with 2 images alternatively
    print("Companion image buffer depth = ", buffer_depth)
    return kdp_wrapper.pipeline_inference(dev_idx, app_id, test_loop,
                                          image_size, capture, img_id_tx,
                                          img_left, buffer_depth, frames,
                                          handle_result)
Esempio n. 3
0
def detect_image(dev_idx, user_id):

    # Initialize image capture parameters
    frames      = []
    img_id_tx   = 0

    # Setup image path
    data_path = os.path.join(os.getcwd(), 'images')

    # Read input image
    image_name = input('Input image file: ')
    image_path = os.path.join(data_path, image_name)
    image_flag = os.path.isfile(image_path)

    # Start ISI mode
    if (kdp_wrapper.start_isi(dev_idx, ISI_YOLO_ID, IMG_SRC_WIDTH, IMG_SRC_HEIGHT)):
        return -1

    # Perform image inference
    while image_flag:
        image = cv2.imread(image_path)
        kdp_examples.image_inference(dev_idx, ISI_YOLO_ID, image_size, image, img_id_tx, frames)
        img_id_tx += 1
        image_name = input('Input image file: ')
        image_path = os.path.join(data_path, image_name)
        image_flag = os.path.isfile(image_path)

    cv2.destroyAllWindows()
Esempio n. 4
0
def user_test_cam_yolo(dev_idx, _user_id, test_loop):
    """User test cam yolo."""
    image_source_h = 480
    image_source_w = 640
    app_id = constants.APP_TINY_YOLO3
    image_size = image_source_w * image_source_h * 2
    frames = []

    # Setup video capture device.
    capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
    if capture is None:
        return -1

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, app_id, image_source_w, image_source_h):
        return -1

    start_time = time.time()
    # Fill up the image buffers.
    ret, img_id_tx, img_left, buffer_depth = kdp_wrapper.fill_buffer(
        dev_idx, capture, image_size, frames)
    if ret:
        return -1

    # Send the rest and get result in loop, with 2 images alternatively
    print("Companion image buffer depth = ", buffer_depth)
    kdp_wrapper.pipeline_inference(dev_idx, app_id, test_loop - buffer_depth,
                                   image_size, capture, img_id_tx, img_left,
                                   buffer_depth, frames, handle_result)

    end_time = time.time()
    diff = end_time - start_time
    estimate_runtime = float(diff / test_loop)
    fps = float(1 / estimate_runtime)
    print("Pipeline inference average estimate runtime is ", estimate_runtime)
    print("Average FPS is ", fps)

    return 0
Esempio n. 5
0
def detect_camera(dev_idx, user_id):

    # Initialize camera capture parameters
    frames      = []
    img_id_tx   = 0

    # Setup webcam capture
    capture     = kdp_wrapper.setup_capture(0, IMG_SRC_WIDTH, IMG_SRC_HEIGHT)
    if capture is None:
        print("Can't open webcam")
        return -1

    # Start ISI mode
    if (kdp_wrapper.start_isi(dev_idx, ISI_YOLO_ID, IMG_SRC_WIDTH, IMG_SRC_HEIGHT)):
        return -1

    # Perform video inference
    while True:
        kdp_examples.camera_inference(dev_idx, ISI_YOLO_ID, image_size, capture, img_id_tx, frames)
        img_id_tx += 1

    capture.release()
    cv2.destroyAllWindows()
Esempio n. 6
0
print("Start kdp host lib ....\n")
if (kdp_lib_start() < 0):
    print("Start kdp host lib failure")

print("Start kdp task: ", args.task_name)

# Setup video capture device.
capture = kdp_wrapper.setup_capture(0, image_source_w, image_source_h)
if capture is None:
    exit()

if (args.task_name == "serial"):

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, app_id, image_source_w, image_source_h):
        exit()

    img_id_tx = 0
    start_time = time.time()
    while (img_id_tx != loop_count):
        kdp_wrapper.sync_inference(dev_idx, app_id, image_size, capture,
                                   img_id_tx, frames, handle_result)
        img_id_tx += 1

elif (args.task_name == "pipeline"):

    # Start ISI mode.
    if kdp_wrapper.start_isi(dev_idx, app_id, image_source_w, image_source_h):
        exit()