This plugin allows you to use a Python 3.x script to process images received by mjpg-streamer. This has been tested with Python 3.4.
To run a Python 3.x script, you can do the following:
mjpg_streamer -i "input_opencv.so --filter cvfilter_py.so --fargs path/to/filter.py"
Your script MUST define a function called 'init_filter', that takes zero arguments and returns a single callable. This returned callable must take a single argument (a numpy array), and returns a single object (a numpy array). A simple example follows:
def filter_fn(img):
'''
:param img: A numpy array representing the input image
:returns: A numpy array to send to the mjpg-streamer output plugin
'''
return img
def init_filter():
return filter_fn
For a more complex example, see the included example_filter.py
When mjpg-streamer is terminated, a KeyError
is raised in the threading
module. While annoying, it's harmless. Most likely it happens because the
python interpreter is destroyed on the wrong thread.
After going through all of this effort to create the code for this module, I bet it can be done a lot simpler via cython.
Dustin Spicuzza ([email protected])