JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
PythonParallel.PythonParallel Class Reference

Simple example of parallel image processing using OpenCV in Python on JeVois. More...

Public Member Functions

 processNoUSB (self, inframe)
 Process function with no USB output.
 
 process (self, inframe, outframe)
 Process function with USB output.
 
 uninit (self)
 Required multiprocessing pool cleanup to avoid hanging on module unload JeVois engine calls uninit(), if present, before destroying our module.
 

Public Attributes

 pool
 
 timer
 

Detailed Description

Simple example of parallel image processing using OpenCV in Python on JeVois.

This module by default simply converts the input image to a grayscale OpenCV image, and then applies the Canny edge detection algorithm, 4 times running in parallel with 4 different edge coarseness settings. The resulting image is simply the 4 horizontally stacked results from the 4 parallel runs. Try to edit it to do something else!

True multi-threaded processing is not supported by Python (the python threading module does not allow concurrent execution of several threads of python code). Parallel processing is somewhat feasible using the mutiprocessing python module, which is a process-based multiprocessing approach. Note that there are significant costs to parallelizing code over multiple processes, the main one being that data needs to be transferred back and forth between processes, using pipes, sockets, or other mechanisms. For machine vision, this is a significant problem as the amount of data (streaming video) that needs to be packaged, transferred, and unpacked is high. C++ is the preferred way of developping multi-threaded JeVois modules, where std::async() makes multi-threaded programming easy.

Note
You should consider this module highly experimental and buggy! This module is currently not working well when running with USB output. There is some internal issue with using the Python multiprocessing module in JeVois. Just creating a python process pool interferes with our USB video output driver, even if we simply create the pool and destroy it immediately without using it at all. Once the python process pool has been created, any subsequent attempt to change video format will fail with a video buffer allocation error. This module may still be useful for robotics applications where parallel python processing is needed but no video output to USB is necessary).
This module is hence not enabled by default. You need to edit JEVOIS:/config/videomappings.cfg, and uncomment the line with PythonParallel in it, to enable it.
Conflated with this problem is the fact that guvcview sometimes, when it starts, turns streaming on, then grabs only 5 frames, then stream off, then set same video format again, and then stream on again. We are not sure why guvcview is doing this, however, this breaks this module since the second streamon fails as it is unable to allocate video buffers.

Using this module

One way we have been able to use this module with USB video outputs is: start guvcview -f yuyv -x 352x288 (launches PythonSandbox), then use the pull-down menu to select 1280x240 (switches to PythonParallel)

This module is best used with no USB video outputs. Connect to JeVois over serial and issue:

 setpar serout USB # to get text results through serial-over-USB, or use Hard if you want results on the 4-pin serial
 setpar serlog USB # to get log messages through serial-over-USB, or use Hard if you want them on the 4-pin serial
 setmapping2 YUYV 320 240 25.0 JeVois PythonParallel
 streamon

As noted above, once you have loaded this module, any later attempts to change format again will fail.

Creating your own module

See http://jevois.org/tutorials for tutorials on getting started with programming JeVois in Python without having to install any development software on your host computer.

Author
Laurent Itti
Videomapping:
YUYV 1280 240 25.0 YUYV 320 240 25.0 JeVois PythonParallel # CAUTION: has major issues
Videomapping:
NONE 0 0 0.0 YUYV 320 240 25.0 JeVois PythonParallel
Email:
itti@usc.edu
Address:
University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
Main URL:
http://jevois.org
Support URL:
http://jevois.org/doc
Other URL:
http://iLab.usc.edu
License:
GPL v3
Distribution:
Unrestricted
Restrictions:
None

Definition at line 82 of file PythonParallel.py.

Member Function Documentation

◆ process()

◆ processNoUSB()

PythonParallel.PythonParallel.processNoUSB (   self,
  inframe 
)

Process function with no USB output.

Definition at line 90 of file PythonParallel.py.

◆ uninit()

PythonParallel.PythonParallel.uninit (   self)

Required multiprocessing pool cleanup to avoid hanging on module unload JeVois engine calls uninit(), if present, before destroying our module.

FIXME: python multiprocessing still messes up the system deeply, we become unable to allocate mmap'd UVC buffers after this module has been loaded.

Definition at line 174 of file PythonParallel.py.

References PythonParallel.PythonParallel.pool.

Member Data Documentation

◆ pool

PythonParallel.PythonParallel.pool

◆ timer


The documentation for this class was generated from the following file: