Python Parallel
Simple example of parallel image processing using OpenCV in Python on JeVois.
By Laurent Ittiitti@usc.eduhttp://jevois.orgGPL v3
 Language: PythonSupports mappings with USB output: YesSupports mappings with NO USB output: Yes 
 Video Mapping:   YUYV 1280 240 25.0 YUYV 320 240 25.0 JeVois PythonParallel # CAUTION: has major issues
 Video Mapping:   NONE 0 0 0.0 YUYV 320 240 25.0 JeVois PythonParallel

Module Documentation

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.

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.

ParameterTypeDescriptionDefaultValid Values
This module exposes no parameter
Detailed docs:PythonParallel
Copyright:Copyright (C) 2018 by Laurent Itti, iLab and the University of Southern California
License:GPL v3
Distribution:Unrestricted
Restrictions:None
Support URL:http://jevois.org/doc
Other URL:http://iLab.usc.edu
Address:University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA