![]() |
mjpg-streamer now with OpenCV input plugin (+filtering)
I'll expand on this later (and maybe even some documentation...), but for now know that you can use mjpg-streamer with OpenCV to write simple little filter plugins that can process the image from the webcam, and change what is streamed out via HTTP. You can install the mjpg-streamer-cv or mjpg-streamer-py packages using the instructions on our github repo.
We used it on our robot today with a python script to do image processing and networktables operations (Lifecam 3000, 320x240, 15fps, 30 quality), and it seemed to be about 20% CPU usage. Not too shabby. In theory, you could use this on a RPi or other platform too, as I've pushed the changes (plus some significant build system improvements) to mjpg-streamer upstream. |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
Thanks for making this! This is exactly what I have been trying to do for the past week!
The only issue is that when running Mjpg-Streamer with: Code:
export LD_LIBRARY_PATH=.Code:
ImportError: numpy.core.multiarray failed to importIs there something I may have missed? |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I added some rpath fixes that should remove the need to set the LD_LIBRARY_PATH anymore, that might be part of the problem.
Which version of python did the compilation select? I've only tested against Python 3 and NumPy 1.10. |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I don't have the Raspberry Pi with me right now, but now that I think of it, it may have selected python 2 instead of python 3.
Do you know how I would change which version of python it uses? |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I only spent a few minutes playing with this tonight, but in the current build configuration I'm finding it devilishly difficult to tell it to use Python 2 if Python 3 is installed. You can use "ldd" to figure out which one it decided to link against though.
|
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I also spent some time working on it last night, and we found that cmake was using python 2 as its python interpreter when building. After some troubleshooting, we managed to make it build cvfilter_py.so correctly by setting the PYTHON_EXECUTABLE to /usr/bin/python3 instead of /usr/bin/python. Although this seems to have fixed the issue with cmake not finding python to build cvfilter_py.so, it has not fixed the numpy import error when running cvfilter_py.so.
Running ldd on cvfilter_py.so shows that it has decided to link against libpython3.4m.so.1.0 |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I feel like I ran into this problem when I first started working on the plugin... looking at __multiarray_api.h, it appears the thing that triggers it is essentially a "import numpy.core.multiarray", but it might be hiding the actual error message. Perhaps add something like this to line 85 of filter_py.cpp and see if a more revealing error message shows up:
Code:
if (PyImport_ImportModule("numpy.core.multiarray") == NULL) |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I added that code to line 85 and sure enough, a much more revealing error popped up. Now running mjpg-streamer gives the error:
Code:
Traceback (most recent call last): |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
Excellent. It would be nice to fix up the build scripts more, but I think I've spent enough time messing with them. Feel free and issue a PR!
I've added that initial import to a pull request, should be easier to diagnose next time. |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
After a lot of troubleshooting, we're still stuck at this error. We were able to get it working on a laptop Arch Linux install, but still no luck on the Raspberry Pi 2 running Raspbian. Any ideas as to what that error might mean?
|
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
Did you install python by hand (compile + install) or via a package? If you installed by hand, maybe reinstall?
Running ldd on the numpy .so files might yield interesting results. Is it pointing to libraries the same place as running ldd on cvfilter_py.so? Do you have multiple versions of numpy installed (eg, python2 and python3?). Maybe get rid of one of them. It would be interesting to know the contents of sys.path when the numpy import occurs. You can do this by inserting this before the numpy insert fails: Code:
PyRun_SimpleString("import sys; print(sys.path)"); |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
Looks like Python you've built isn't exporting its symbols properly. Try adding "-Xlinker -export-dynamic" to your configure line
|
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
I've been busy getting ready for competition, so I haven't had much time to work on this. I tried building Python 3.5.1 from source and installing it, but still almost the same error, though this time slightly different. Now instead of PyType_GenericNew being the undefined symbol, PyFloat_Type is, leading me to think that Python might not be exporting symbols correctly as nightpool suggested. So I tried adding -Xlinker -export-dynamic" to the cmake build flags through the MAKE_CXX_FLAGS variable. It didn't seem to have any effect, so I'm thinking I may have put it in the wrong cmake variable. Any idea what I might be doing wrong?
Bellow is a log of what I tried, hopefully it will help you! Code:
pi@core2062pi:~/mjpg-streamer/mjpg-streamer-experimental/_build$ cmake .. -DPYTHON_EXECUTABLE=/usr/local/bin/python3.5 -DCMAKE_CXX_FLAGS="-Xlinker -export-dynamic" |
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
The only bug report that I found: https://bugs.python.org/issue24783 ... did you build python with --enable-shared?
|
Re: mjpg-streamer now with OpenCV input plugin (+filtering)
Quote:
|
| All times are GMT -5. The time now is 06:30. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi