[ visual operation and control all-in-one computer small class ] three minutes to realize camera acquisition and image saving

Posted by Chunk1978 on Mon, 27 Dec 2021 15:42:52 +0100

1, Background

The purpose of the implementation of machine vision scheme is to automatically detect the product target through image processing algorithm and output the judgment state and data results. Therefore, image acquisition is the basis of the implementation of machine vision scheme.

There are two methods of image acquisition: one is to obtain image data from the camera, and the other is to obtain pictures from local files for offline debugging.

In the last course, we talked about how to read local images in three minutes using VPLC series visual operation and control all-in-one machine. In this course, the sports assistant will share with you the course of VPLC series visual operation and control all-in-one machine to realize camera acquisition and image preservation.

[ visual operation and control all-in-one computer small class ] three minutes to realize camera acquisition and image saving

2, VPLC controller

(1) VPLC516E framework diagram

(2) Preparation before class

1. One computer with Z3 Software version above 10

2. One vplc516e

3. One 24V DC power supply

4. One network cable

5.WinSCP software

6. Several wires

3, Course knowledge points

1. Scan camera: use cam_ The scan command scans the camera that appears to be connected to the controller.

2. Get the number of cameras scanned: use cam_ The count command scans the number of cameras connected to the controller.

3. Select acquisition device: use CAM_SEL command selects the camera serial number for acquisition operation.

4. Set camera trigger mode: use cam_ The setmode command selects the trigger mode for setting the camera.

5. Start image acquisition: use cam_ The start command selects to set the camera to start collecting images.

6. Send trigger command to camera to take photos: use cam_ The SetParam command selects to trigger the camera to take pictures, and takes pictures once every time.

7. Acquiring images: using cam_ The get instruction acquires a frame of image in the corresponding trigger mode.

8. Save image: use zv_ The writeimage instruction saves the image in the default path.

4, Software implementation

1. Open ZDevelop software: create a new project named "camera capture and save image routine. zpj" → create HMI file → create main Bas file (used to write interface response function and start HMI automatic operation task) → add the file to the project.

2. Design HMI main interface.

3. Write the function of HMI interface to respond by pressing the scan camera button, and associate its action function name.

'*******************Define global variable area**********************

GLOBAL DIM  cam_num                 'Defines and initializes the number of cameras

cam_num = 0

GLOBAL DIM  set_mode                'Select acquisition mode, 0-Free collection, 1-Software trigger, 2 Hardware trigger

GLOBAL DIM  cur_mode                'Current selection mode

GLOBAL ZVOBJECT image              'Define the acquired picture variable

'*******************Define global variable area**********************



'HMI Interface initialization function

GLOBAL SUB init_hmi()   

   ZV_LATCHCLEAR(0)   'Clear latch channel 0

   set_mode=1      'The acquisition mode defaults to software trigger mode  

END SUB



'HMI The interface is a function that responds by pressing the scan camera button. The scan camera function is generally used as the camera initialization function. It does not need to be repeated after scanning the camera

GLOBAL SUB scan_all_cams()

   CAM_SCAN("zmotion")        'Scanning positive motion self brand camera  

   cam_num = CAM_COUNT()      'Gets the number of cameras scanned  

   if (0 = cam_num) then      'If quantity=0 The camera is not found

      ? "Camera not found"  

      return                  'Exit the sub function and do not execute further

   endif 

   ?"Number of cameras:" cam_num       'quantity=0 The number of cameras to scan is prompted

    

   set_mode=1          'Select software trigger, set the acquisition mode and turn on the camera

   CAM_SEL(0)          'Select camera id 

   CAM_SETMODE(0)      'Set the camera to software triggered acquisition mode

   CAM_START(0)        'Turn on the camera

   cur_mode=set_mode   'Assign the currently set acquisition mode to the current mode variable

   

   DIM tmp(32)

   CAM_GETPARAM("ResultingFrameRate",32,0) 'Camera frame rate

   DMCPY tmp(0), TABLE(0), 32

   ?"cam_get_param: cam_ResultingFrameRate = "tmp

END SUB

4. Write the response function when the camera acquisition button is pressed on the HMI interface, and associate its action function name.

'HMI The function that the interface responds to when the camera acquisition button is pressed

GLOBAL SUB btn_grab()

   if (0 = cam_num) then                'If quantity=0 Prompt to scan the camera

      ? "Please scan the camera first!"

      return                            'Exit the sub function and do not execute further

   endif                                'quantity!=0 Continue 

   if (set_mode=1) then 

      CAM_SETPARAM("TriggerSoftware", 0)'Send soft trigger signal

      CAM_GET(image, 0)          'Gets the specified in the camera cache id Image with sequence number 0

   endif

   ZV_LATCH(image, 0)            'display image Image to latch channel 0

END SUB

5. Write the response function when the HMI interface presses the save image button, and de associate its action function name.

'HMI The function that the interface responds to when the save image button is pressed

GLOBAL SUB btn_saveImg()

   ZV_WRITEIMAGE(image,"SAVE.bmp",0)

   ?"Saved successfully" 

END SUB

Note: if the project is running in the emulator, by default, the file path corresponds to the flash directory under ZDevelop software.

If the project is running on the controller, the file path corresponds to... zmc/flash / directory by default, and zv can be used_ Set the setsysstr ("DataDir", "") instruction to the path you want. At the same time, if you need to view the image on the PC, you can connect the controller to the corresponding directory through WinSCP software to take out the image.

6. Effect demonstration.

[visual operation and control integrated computer small class] three minutes to realize the demonstration of camera acquisition and image saving operation

This time, the positive motion technology [visual operation and control all-in-one computer small class] realizes camera acquisition and image saving in three minutes. Let's share it here.

For more interesting content, please pay attention to the "public assistant" official account, and you need the relevant development environment and routine code. Please consult the sales engineer of the sports technology.

This article is original by positive motion technology. You are welcome to reprint it and learn together to improve China's intelligent manufacturing level. The copyright of this article belongs to rightmovement technology. If you reprint it, please indicate the source of the article.

Topics: image processing machine vision