Disclosure of Invention
In order to overcome the above disadvantages and shortcomings of the prior art, the present invention provides a method for generating a control SDK of a binocular USB camera, so that it is more convenient to control the binocular USB camera.
The purpose of the invention is realized by the following technical scheme:
a method for generating a control development kit of a binocular USB camera is provided, which comprises the steps of setting an address and a bit domain value on a register of the binocular USB camera to realize the setting of control parameters of the binocular USB camera; according to the meaning of the address and the bit field value of the register, an external interface is compiled to obtain a control development toolkit;
the external interface comprises a binocular USB camera setting interface, a binocular USB camera state acquisition interface and a binocular USB camera data acquisition interface.
Specifically, the binocular USB camera setting interface comprises a binocular USB camera opening interface, a binocular USB camera closing interface, a binocular USB camera frame rate setting interface, a binocular USB camera exposure time setting interface, a binocular USB camera LED lamp brightness setting interface, a binocular USB camera threshold value setting interface, a binocular USB camera point coordinate data transmission enabling interface, a binocular USB camera image data transmission enabling interface and a binocular USB camera point data mirror image enabling interface.
Specifically, the binocular USB camera state acquisition interface comprises a binocular USB camera open state acquisition interface; whether the binocular USB camera starts a point coordinate transmission acquisition interface or not; whether the binocular USB camera starts an image data transmission acquisition interface or not; whether a binocular USB camera starts a point coordinate mirror image acquisition interface or not; a hardware version information acquisition interface of the binocular USB camera; a resolution acquisition interface of the binocular USB sensor; the binocular USB camera transmits a resolution ratio acquisition interface after image compression; basic parameter acquisition interface of binocular USB camera.
Specifically, the binocular USB camera data acquisition interface includes a left and right point coordinate data acquisition interface of the binocular USB camera and a left and right image data acquisition interface of the binocular USB camera.
Specifically, the basic parameters of the binocular USB camera include exposure time, frame rate, LED brightness, and threshold.
Specifically, the read-write operation of the register is encapsulated into two bottom layer interfaces.
Preferably, the binocular USB camera is an infrared binocular USB camera.
Preferably, the binocular USB camera comprises a left camera, a right camera, an FPGA chip, a register and a USB controller, wherein the left camera and the right camera are respectively connected with the FPGA chip, the USB controller is connected with the FPGA chip, and the register is connected with the FPGA chip.
Another objective of the present invention is to provide a method for controlling a binocular USB camera based on the above SDK, which is implemented by the following technical solutions:
a control development kit generated by the method for generating the control development kit of the binocular USB camera is connected with the binocular USB camera through a USB driver, an FPGA register value of the binocular camera is initialized, point coordinate data and the space size of an image cache are initialized, a data receiving thread is started, received data of the same type of a left camera and a right camera are synchronously stored in the data cache according to a frame number, and an event trigger mechanism is used for ensuring the reading and writing synchronization of the coordinate and the image data.
Preferably, the specific flow of the data receiving thread is as follows:
when the receiving zone bit of the data receiving thread is true, the data are read circularly, the read data are analyzed, whether the received data belong to point coordinates or image data is judged through a header and the zone bit, whether the data belong to the left camera or the right camera of the binocular USB camera is distinguished, the data are filled into a data cache, and after the N frames of data of the left camera and the right camera are transmitted, the data of the left camera and the right camera are subjected to event triggering and are output outwards synchronously; wherein N is a positive integer.
Compared with the prior art, the invention has the following advantages and beneficial effects:
according to the invention, parameter control and data acquisition are carried out on the binocular infrared camera by developing a set of infrared camera control development kit, the external interface of the development kit enables a developer to better call the development kit without understanding the function realization and logic design of the bottom layer, and the current state value of the camera is acquired by setting various parameters of the camera through the interface call, so that the control of the binocular USB camera is more convenient.
Detailed Description
The present invention will be described in further detail with reference to examples, but the embodiments of the present invention are not limited thereto.
Examples
Fig. 1 is a block diagram of an infrared binocular camera according to an embodiment of the present invention, as shown in fig. 1, the infrared binocular camera includes two infrared binocular cameras (a left camera and a right camera, respectively), an FPGA chip, a register, and a USB controller, wherein the left camera and the right camera are electrically connected to the FPGA chip, the USB controller is electrically connected to the FPGA chip, the register is driven by FPGA I2C to communicate with the FPGA chip, and I2C communicates with the FPGA in a 16-bit address mode. The read-write operation of the register is packaged into a first bottom layer interface i2cWrite and a second bottom layer interface i2 cRead; the input parameters are register address, bit field and corresponding value, respectively.
The method for generating the development kit of the infrared binocular camera comprises the following steps: setting addresses and bit domain values on an FPGA register of the infrared binocular USB camera to realize the setting of control parameters of the infrared binocular USB camera; and compiling an external interface according to the meanings of the address and the bit field value of the register to obtain a control development toolkit.
The control parameters of the embodiment of the invention specifically complete the corresponding parameter setting by operating the value on the specific address on the FPGA register. The register is designed as follows, including address and bitfield intervals, and the meaning of the bitfield values expressed:
0X00, bit field [ 31: 0], the upper 32 bits representing the firmware version number;
0X04, bit field [ 31: 0], the lower 32 bits representing the firmware version number;
0X08, bit field [0] indicates video data channel reset, high active; bit field [1] represents that the data channel of the point is reset and is high-effective; the bit field [2] represents that the slave fifo interface is reset and is high-effective; bit field [ 7: 3] represents reset; the bit field [8] represents a sensor trigger signal (when an image is captured, the image can be captured only by triggering, and a certain signal can be triggered or can not be triggered through the signal data), when the signal is 1, the camera starts to trigger exposure and outputs the image, and when the signal is 0, the trigger is stopped; bit field [9] indicates exp exposure control signal source selection, controlling the output duration of exp _ pwm, and thus the infrared LED brightness, 0: exposure indication signal 1 of sen _ IT sensor: the exp _ gen local exposure signal is a synchronous model controlled and generated by a local frame period counter; the bit field [16] represents an x-direction point data mirror image and does not influence the original image; a bit field [17] represents a y-direction point data mirror image and does not influence the original image; bit field [18] indicates the original image threshold mode, 0: when the original pixel value is larger than raw _ thd and is the original value, and when the original pixel value is smaller than raw _ thd, the original pixel value is 0, 1: when the original pixel value is greater than raw _ thd, it is the original value-raw _ thd, and when it is less than it, it is 0. [25: 24] represents master sync sensor selection, 0: select sensor0 as master sync sensor, 1: select sensor1 as the master synchronization sensor, 2, 3: and (4) invalidation.
0x0c, bit field [ 31: 0], indicating the start of the exp _ gen local exposure signal, which counts to exp _ start _ pos pull-up exp _ gen at frame _ cnt.
0x10, bit field [ 31: 0], indicating the end of the exp _ gen local exposure signal, the exp _ gen is pulled low by exp _ start _ pos as counted at frame _ cnt.
Ox14, domain [ 31: 0], indicating the start of the sensor trigger signal, pulling up the sensor trigger signal tig _ gen when it counts to tig _ start _ pos in frame _ cnt.
Ox18, domain [ 15: 0], represents the pulse width of the sensor trigger signal tig _ gen.
0x1c, bit field [ 15: 0], a low level width of PWM indicating the exp exposure control signal; bit field [ 31: 16], represents the high-level width of PWM of the exp exposure control signal.
0x20, bit field [ 31: 0] indicating the frame period count length, controlling the count range of the period counter frame _ cnt.
0x24, bit field [ 31: 0] indicating the training state of the sensor0 lvds interface, train _ status [31 ]: training completion indication, train _ status [ 4: 0]: the lvds channel training status, high indicates that the channel is trained through.
0x28, bit field [ 31: 0], represents the training state of the sensor1 lvds interface, train _ status [31 ]: training completion indication, train _ status [ 4: 0]: the lvds channel training status, high indicates that the channel is trained through.
0x34, bit field [ 15: 0], y size representing dot data, and image height, default 1024. Bit field [ 31: 16] represents the x size of the dot data, and is equal to the image width, with a default of 1280.
0x38, bit field [ 31: 0] indicating that the image background filtering threshold is used in conjunction with the threshold mode, [ 31: 24]: image area 3 filtering threshold, [ 23: 16]: image area 2 filtering threshold, [ 15: 8]: image area 1 filtering threshold, [ 7: 0]: the image area 0 filtering threshold is usually configured with the same value.
0x3c, a bit field [0] indicates that the SPI controller of the sensor reads the completion indication signal, and the high indicates that the reading operation is completed; bit field [8] represents the ready signal of the sensor's SPI controller, which is enabled when the control command data is configured and informs the sensor's SPI controller to take the command data away.
0x40, bit field [ 31: 0] represents cmd and data of the SPI controller of the sensor, [ 31: 28] cmd 0: reading 1: writing; [24: 16] addr spi address; [15: 0 data spi writes data, and does not work when reading.
0x48, bit field [ 31: 0], 16 high and low bits of read-back data representing read operations, respectively representing read-back data of two sensors in the binocular mode.
The external interface of the control development kit comprises an infrared binocular USB camera setting interface, an infrared binocular USB camera state acquisition interface and an infrared binocular USB camera data acquisition interface.
The infrared binocular USB camera setting interface comprises an infrared binocular USB camera opening interface, an infrared binocular USB camera closing interface, an infrared binocular USB camera frame rate setting interface, an infrared binocular USB camera exposure time setting interface, an infrared binocular USB camera LED lamp brightness setting interface, an infrared binocular USB camera threshold value setting interface, an infrared binocular USB camera point coordinate data transmission enabling interface, an infrared binocular USB camera image data transmission enabling interface and an infrared binocular USB camera point data mirror image enabling interface.
The infrared binocular USB camera state acquisition interface comprises an infrared binocular USB camera opening state acquisition interface; whether the infrared binocular USB camera starts a point coordinate transmission acquisition interface or not; whether the infrared binocular USB camera starts an image data transmission acquisition interface or not; whether the infrared binocular USB camera starts a point coordinate mirror image acquisition interface or not; a hardware version information acquisition interface of the infrared binocular USB camera; a resolution acquisition interface of the infrared binocular USB sensor; the infrared binocular USB camera transmits a resolution ratio acquisition interface after image compression; a basic parameter acquisition interface of the infrared binocular USB camera; the basic parameters of the infrared binocular USB camera comprise exposure time, frame rate, LED brightness and threshold value.
The data acquisition interface of the infrared binocular USB camera comprises a left point coordinate data acquisition interface and a right point coordinate data acquisition interface of the infrared binocular USB camera and a left image data acquisition interface and a right image data acquisition interface of the infrared binocular USB camera.
By using the development kit software package generated by the method for generating the development kit of the infrared binocular camera according to the embodiment, the method for controlling the binocular USB camera according to the embodiment can be implemented by the following procedures: the control development kit is connected with a binocular USB camera through a USB drive, register values of the infrared binocular camera are initialized, point coordinate data and the space size of an image cache are initialized, a data receiving thread is started, the received data of the same type of the left camera and the right camera are synchronously stored in the data cache according to frame numbers, and an event trigger mechanism is used for ensuring the reading and writing synchronization of the coordinate data and the image data.
More specifically, the flow of the control method of the binocular USB camera of the present embodiment may be as follows:
according to the address and the bit field value meaning of the bottom layer FPGA register, an address structure ADDR and a bit field value structure REG of the FPGA are defined, and the address and the bit field value structure REG comprise hardware version information of the infrared binocular USB camera, basic parameter configuration of the infrared binocular USB camera, exposure time address and bit field configuration and the like. And then after an infrared binocular USB camera is connected through a USB drive interface of CYAPI (development tool set of USB drive), inputting corresponding values in the ADDR and REG structural bodies through an i2cWrite interface and an i2cRead interface to acquire current camera state information and set camera parameters, and simultaneously storing the current camera state information and set camera parameters into a camera image information storage structural body and a camera coordinate data storage structural body object of the infrared binocular USB camera. After a data receiving thread is started, the received data of the same type of the left camera and the right camera are synchronously stored in a data cache according to the frame number, and an event trigger mechanism is used for ensuring the reading and writing synchronization of the coordinate and the image data.
The information structure body of the infrared binocular USB camera comprises hardware version information, a frame rate, a threshold value, exposure time, LED lamp brightness, a coordinate \ image transmission enabling state and the like.
The camera image information storage structure according to the embodiment of the present invention includes an ID of a previous frame of image data, an ID of a current image frame, and an image data array (storing image data of left and right cameras); the specific implementation mode is as follows:
the camera coordinate data storage structure according to the embodiment of the present invention includes an ID of a previous frame of coordinate data, an ID of a current coordinate frame, and coordinate information (including a coordinate region, a gray value, and values in X and Y directions), and is specifically implemented in the following manner:
the specific flow of the data receiving thread provided by the embodiment of the invention is as follows:
when the receiving zone bit of the data receiving thread is true, the data are read circularly, the read data are analyzed, whether the received data belong to point coordinates or image data is judged through a header and the zone bit, whether the data belong to the left camera or the right camera of a binocular camera is distinguished, the data are filled into a data cache, and after the N frames of data of the left camera and the right camera are transmitted, the data of the left camera and the right camera are synchronously output outwards through event triggering; wherein N is a positive integer.
According to the embodiment of the invention, a set of infrared camera control development kit is developed to control parameters and acquire data of the infrared binocular infrared camera, an external interface of the development kit enables a developer to better call the development kit without understanding function realization and logic design of a bottom layer, and the interface call is used for setting various parameters of the camera to acquire the current state value of the camera, so that the infrared binocular USB camera is more conveniently controlled.
The above embodiments are preferred embodiments of the present invention, but the present invention is not limited to the above embodiments, and any other changes, modifications, substitutions, combinations, and simplifications which do not depart from the spirit and principle of the present invention should be construed as equivalents thereof, and all such changes, modifications, substitutions, combinations, and simplifications are intended to be included in the scope of the present invention.