JeVoisBase
1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Simple example of parallel image processing using OpenCV in Python on JeVois. More...
Public Member Functions | |
def | processNoUSB (self, inframe) |
Process function with no USB output. More... | |
def | process (self, inframe, outframe) |
Process function with USB output. More... | |
def | uninit (self) |
Required multiprocessing pool cleanup to avoid hanging on module unload JeVois engine calls uninit(), if present, before destroying our module. More... | |
Public Attributes | |
pool | |
timer | |
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.
\fixme 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).
\fixme 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.
\fixme 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.
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.
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.
Definition at line 82 of file PythonParallel.py.
def PythonParallel.PythonParallel.process | ( | self, | |
inframe, | |||
outframe | |||
) |
Process function with USB output.
Definition at line 132 of file PythonParallel.py.
References hasattr(), PythonParallel.PythonParallel.pool, PythonTutorial2::PythonTutorial2.timer, PyModule::__MODULE__.timer, PyPoseDetector.PyPoseDetector.timer, PyFaceMesh.PyFaceMesh.timer, PyHandDetector.PyHandDetector.timer, PyDMTX.PyDMTX.timer, PythonOpenCV.PythonOpenCV.timer, PySelfie.PySelfie.timer, PyObjectron.PyObjectron.timer, PyEmotion.PyEmotion.timer, PyLicensePlate.PyLicensePlate.timer, PyCoralDetect.PyCoralDetect.timer, PyCoralSegment.PyCoralSegment.timer, PySceneText.PySceneText.timer, PyCoralClassify.PyCoralClassify.timer, PyClassificationDNN.PyClassificationDNN.timer, PythonParallel.PythonParallel.timer, FirstPython.FirstPython.timer, PyDetectionDNN.PyDetectionDNN.timer, and PythonObject6D.PythonObject6D.timer.
def PythonParallel.PythonParallel.processNoUSB | ( | self, | |
inframe | |||
) |
Process function with no USB output.
Definition at line 90 of file PythonParallel.py.
References hasattr().
def 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 hasattr(), and PythonParallel.PythonParallel.pool.
PythonParallel.PythonParallel.pool |
Definition at line 94 of file PythonParallel.py.
Referenced by PythonParallel.PythonParallel.process(), and PythonParallel.PythonParallel.uninit().
PythonParallel.PythonParallel.timer |
Definition at line 96 of file PythonParallel.py.
Referenced by PythonSandbox.PythonSandbox.process(), PythonParallel.PythonParallel.process(), PythonTest.PythonTest.processGUI(), PythonSandbox.PythonSandbox.processGUI(), and PythonSandbox.PythonSandbox.processNoUSB().