DESK-MX8M-L-TN-0002: python and OpenCV

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box


200px-Emblem-important.svg.png

This technical note has been validated using the kit version in the History table.

History
Issue Date Notes
2024/07/26 DESK-MX8M-L 4.0.0


Introduction[edit | edit source]

Nowadays, python together with OpenCV2 are used on many applications for - as an example:

  • capturing an image from a camera
  • processing the image with OpenCV
  • displaying the results in the screen

In this Technical Note we defines the distro features required for using python3 and OpenCV for image manipulation and display on the screen.

OpenCV HighGui and X compositor[edit | edit source]

The imshow HighGui support requires an X distro as reported here. This means that the standard wayland distro does not work properly.


200px-Emblem-important.svg.png

By default dave-image-devel is built with Wayland backend (fsl-imx-wayland distro)

User needs to rebuild this image using fsl-imx-xwayland distro to enable xwayland support and use OpenCV HighGui

Running python3 and opencv2[edit | edit source]

Once the proper root file system is extracted into the SD card, the python3/opencv2 module can be used under Python:

root@desk-mx8mm:~# python3
Python 3.10.7 (main, Sep  5 2022, 13:12:31) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> img  = cv2.imread("/run/media/boot-mmcblk1p1/splash_image.bmp")
>>> cv2.imshow("window splash", img)
>>> cv2.waitKey(0)

On display you can see the following image

python3 and openCV2 on MITO 8M Mini

Using a MIPI camera, for example with ORCA Evaluation Kit, it is possible to grab a camera picture and proceed in the same way:

root@desk-mx8mm:~# python3
Python 3.10.7 (main, Sep  5 2022, 13:12:31) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> vid = cv2.VideoCapture(1)
>>> e,img=vid.read()
>>> cv2.imshow("window splash", img)
>>> cv2.waitKey(0)