Home

fschneider
There is a newer version of this page. You can find it here.

Download project

OpenCV Example 2

This example shows a python implementation of opencv a free library of programming functions.
With this library a picture gets evaluated and the information is transfered to CODESYS via shared memory.

Product description

In this example a picture gets evaluated via python and the free library of programming functions opencv.
There are different color circles in the picture, the blue ones are filtered and coordinates of the contoures are written in a string.
The string gets combined with a string of the current time stamp. This string gets transferred into a byte array and filed on shared memory.

For a selected time the shared memory is open (in this case 60 seconds), to make it possible for CODESYS to read the data.
In CODESYS the shared memory buffer is read and the byte array is transferred to a string again.

After transferring to string the coordinates of four contoures are in the string such as the time stamp.
Another prepared possibility is the evaluation of a video stream, the contours in this case are limited to five to get no overflow.

More information

Preparations

Open "OpenCV_Example2.project" via CODESYS.
Install Python 3.4 or higher, set the environment variables in Path and install opencv:
Command line : pip install opencv-python

Folder location

The python project and example picture should be in the same folder.
Name the shared memory buffer in CODESYS same as in python (default "MySharedMemory").
Set the same size for shared memory buffer in CODESYS as in python (default "100").
The time of open shared memory can be set in python project (default 60 seconds).

Procedure

Start CODESYS and connect to local ControlWin and log in, start, etc.
In monitoring (PLC_PRG.strRead) value of string is "".
Run python script -> In monitoring string has four coordinates and one time stamp.

Further functionalitys

The main functionality of opencv can be looked up on the website https://opencv.org/.
For more functions the buffer of shared memory maybe must be increased.

System requirements and restrictions

System requirements and restrictions Info
Programming System CODESYS Development System Version 3.5.16.0 or higher
Runtime System CODESYS Control Version 3.5.16.0
Required Accessories -