×
MENU
@ViewData["CurrentPage"]
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

Python API Reference - BarcodeReader Video Methods


start_video_mode

Starts a new thread to decode barcodes from the inner frame queue.

BarcodeReader.start_video_mode(frame_decoding_parameters, call_back_func, template_name="")

Parameters

[in] frame_decoding_parameters <class FrameDecodingParameters> : The frame decoding parameters. You can get it by using init_frame_decoding_parameters() then modifying its parameters’ value.
[in] text_result_callback_func <function pointer> : Sets callback function to process text results during frame decoding.

  • This callback function pointer must follow the following format: callback_func_name(frameId, results, user_data);
  • Or you can inherit the abstract class TextResultResultCallBack to implement the abstract method text_results_callback_func.
  • If you would like to learn how to use it, please refer to the sample.

[in] template_name (optional)<str> : The template name.
[in] intermediate_result_callback_func (optional)<function pointer> : Sets callback function to process intermediate results during frame decoding.

  • This callback function pointer must follow the following format: callback_func_name(frameId, results, user_data);
  • Or you can inherit the abstract class IntermediateResultCallBack to implement the abstract method intermediate_results_callback_func.
  • If you would like to learn how to use it, please refer to the sample.

[in] error_callback_func (optional)<function pointer> : Sets callback function to process errors during frame decoding.

  • This callback function pointer must follow the following format: callback_func_name(frameId, error, user_data);
  • Or you can inherit the abstract class ErrorCallBack to implement the abstract method error_callback_func.
  • If you would like to learn how to use it, please refer to the sample.

[in] user_data (optional)<object> : Customizes arguments passed to your function.

Exception

BarcodeReaderError : If error happens, this function will throw a BarcodeReaderError exception that can report the detailed error message.

Code Snippet

import cv2
from dbr import *
reader = BarcodeReader()


# The callback function for receiving barcode results
def text_results_callback_func(frame_id, t_results, user_data):
        print(frame_id)
        for result in t_results:
            text_result = TextResult(result)
            print("Barcode Format : ")
            print(text_result.barcode_format_string)
            print("Barcode Text : ")
            print(text_result.barcode_text)
            print("Localization Points : ")
            print(text_result.localization_result.localization_points)
            print("Exception : ")
            print(text_result.exception)
            print("-------------")

def get_time():
    localtime = time.localtime()
    capturetime = time.strftime("%Y%m%d%H%M%S", localtime)
    return capturetime

def read_barcode():
    video_width = 0
    video_height = 0
    
    vc = cv2.VideoCapture(0)
    video_width  = vc.get(cv2.CAP_PROP_FRAME_WIDTH)
    video_height = vc.get(cv2.CAP_PROP_FRAME_HEIGHT)
    vc.set(3, video_width) #set width
    vc.set(4, video_height) #set height

    stride = 0
    if vc.isOpened():  
        rval, frame = vc.read()
        stride = frame.strides[0]
    else:
        return

    windowName = "Barcode Reader"

    parameters = reader.init_frame_decoding_parameters()
    # you can modify these following parameters.
    parameters.max_queue_length = 30
    parameters.max_result_queue_length = 30
    parameters.width = video_width
    parameters.height = video_height
    parameters.stride = stride
    parameters.image_pixel_format = EnumImagePixelFormat.IPF_RGB_888
    parameters.region_top = 0
    parameters.region_bottom = 100
    parameters.region_left = 0
    parameters.region_right = 100
    parameters.region_measured_by_percentage = 1
    parameters.threshold = 0.01
    parameters.fps = 0
    parameters.auto_filter = 1

    reader.start_video_mode(parameters, text_results_callback_func)

    while True:
        cv2.imshow(windowName, frame)
        rval, frame = vc.read()
        if rval == False:
            break
        
        try:
            ret = reader.append_video_frame(frame)
        except:
            pass
        
        # 'ESC' for quit
        key = cv2.waitKey(1)
        if key == 27:
            break

    reader.stop_video_mode()
    cv2.destroyWindow(windowName)


print("-------------------start------------------------")

reader.init_license("t0260NwAAAHV***************")
read_barcode()

print("-------------------over------------------------")

append_video_frame

Appends a frame image buffer to the inner frame queue.

BarcodeReader.append_video_frame(video_frame)

Parameters

[in] video_frame : Gets video frame by opencv.

Return value

The current frame ID.

stop_video_mode

Stop the frame decoding thread created by start_video_mode

BarcodeReader.stop_video_mode()

Exception

BarcodeReaderError : If error happens, this function will throw a BarcodeReaderError exception that can report the detailed error message.

init_frame_decoding_parameters

Initializes frame decoding parameters with default values.

BarcodeReader.init_frame_decoding_parameters()

Return value

frame_decoding_parameters <class FrameDecodingParameters> : The frame decoding parameters.

get_length_of_frame_queue

Gets the current length of the inner frame queue.

BarcodeReader.get_length_of_frame_queue()	

Return value

Returns the length of the inner frame queue.

This page is compatible for:

Version 7.5

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version
    • version 8.0
    • version 7.6
    • version 7.5
    Change +
    © 2003–2020 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support