Teach you step by step how to use LabVIEW artificial intelligence vision toolkit to quickly realize image reading and acquisition

Preface

Today we will use the LabVIEW AI vision toolkit to quickly implement image reading and color space conversion, and collect images from the camera. The installation and download methods of the toolkit can be found in the two previous blogs.

1. Toolkit location

The installed toolkit is located in the block diagram - function palette - Addons - VIRobotics - opencv_yiku, which includes: Mat type (matrix) operations, camera acquisition, image file reading and writing, basic operators, video generation, neural network calls, etc. Function.
Toolkit contents

2. Image acquisition and color space conversion

1. File reading and writing

(1) Right-click on the block diagram panel: File I/O, drag out the split path and splice path functions to the block diagram panel for later use;
Insert image description here

(2) Right-click on the block diagram panel: File I/O --> File Constants, drag out the current path function to the block diagram panel for later use;
Insert image description here

2. Implement image reading

(1) Right-click in the blank space of the block diagram panel -> Find the imread function to be used in the function palette -> Addons -> VIRobotics -> opencv_yiku-imgcodes, and drag it out; (2) The imread function reads the image of the specified
Insert image description here
path ( jpg/png/bmp format), returns the Mat object, the specific input and output are as follows:
Insert image description here
(3) Right-click on the block diagram panel: Application Control–>Property Node, drag out the property node to obtain various parameters in the Mat object (In this case, it is a picture) and put it in the picture control;
Insert image description here
(4) Release the Mat resource;
Insert image description here
(5) Connect as shown in the figure below, place the picture to be read in the same path as this vi and run it;
Insert image description here
( 6) Read the picture as shown below (the left side is the original picture, the right side is the read picture), we found that the color of the read picture is different from the original picture;
Insert image description here

3. Use the operator cvtColor to implement color space conversion

(1) Because the image arrangement order in LabVIEW is RGB and the image arrangement order in opencv is BGR, the color of the read image is different from the original image; (2) Use the operator cvtColor for color space conversion, block diagram
panel Right-click: Addons–>VIRobotics–>opencv_yiku–>imgproc: cvtColor, drag out;
Insert image description here
(3) The input and output of operator cvtColor are as shown in the figure below:

Insert image description here
(4) How to use the operator (cvtColor) in LabVIEW 1 : The input dst terminal is not connected to the input, and the output image after running the function will replace the original image (the values ​​of src out and dst out are consistent). The program and results are as follows As shown in the figure:
Insert image description here
Insert image description here

(5) The second way to use the operator (cvtColor) in LabVIEW : The input dst is connected to a Create_Mat, that is, a new mat object is created. After running the function, the content of dst will not affect the content of src; the program and results are as shown in the figure below :
Insert image description here
Insert image description here
Insert image description here

3. Collect images from the camera

1.Camera class

(1) Create a new vi, right-click on the block diagram panel: Addons–>VIRobotics --> opencv_yiku: Camera. Find the camera initialization function new_Cap. Cap is output in the upper right corner of the function. It is a necessary action before using the camera. Drag it to a blank space on the panel for later use;
Insert image description here

(2) Right-click on the block diagram panel: Addons–>VIRobotics --> opencv_yiku: Camera. Find startCaptura and drag it to the blank space of the panel. If you only fill in the cameraID when using this function, please ensure that the camera is normal. As long as there is a preference connected, when there are multiple local cameras, the camera assigned to the ID will be used first. If the camera does not exist, other cameras will be used.
Insert image description here

(3) Right-click on the block diagram panel: Addons–>VIRobotics --> opencv_yiku: Camera. Find the image acquisition function readImage, which is connected after turning on the camera to obtain the image captured by the camera. Mat output image (matrix);
Insert image description here

(4) Right-click on the block diagram panel: Addons–>VIRobotics --> opencv_yiku: Camera. Find the stopCapture function, receive it at the end of the program, and release the camera resources. If not operated, it may cause inconvenience next time.
Insert image description here

2.Attribute node

(1) Right-click on the block diagram panel: Application Control: Property Node, drag it out, and connect it to startCaptura
Insert image description here
(2) Set the width and height according to the resolution actually supported by the camera. The arrow of the attribute on the right indicates reading. Just right-click and select Change To Write to change it to writing.
Insert image description here

3. Realize the camera to collect images

The overall program is as follows, use a loop to collect images, click the stop button, the loop ends, the entire program ends and resources are released.
Insert image description here

4. Source code download

Link: https://pan.baidu.com/s/1TEihgoG5bIFz1SRCIab-mQ
Extraction code: 8888

Summarize

For more information about LabVIEW and artificial intelligence technology, you can join the technical exchange group for further discussion.
QQ group number: 705637299

Guess you like

Origin blog.csdn.net/virobotics/article/details/123663532