Go to Post This is high school robotics for fun and education. Let's try and keep it that way. - Rod [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-03-2016, 22:38
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff

Last edited by virtuald : 12-03-2016 at 22:41.
Reply With Quote
  #2   Spotlight this post!  
Unread 14-03-2016, 10:53
Wishbonea's Avatar
Wishbonea Wishbonea is offline
Registered User
FRC #2062
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2008
Location: Wisconsin
Posts: 11
Wishbonea is an unknown quantity at this point
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=.
./mjpg_streamer -i "input_opencv.so --filter cvfilter_py.so --fargs ~/mjpg-streamer/mjpg-streamer-experimental/plugins/input_opencv/filters/cvfilter_py/example_filter.py" -o "output_http.so -w ./www"
On a Raspberry Pi 2 with OpenCV 3.1.0 and Numpy 1.10, I get the error
Code:
ImportError: numpy.core.multiarray failed to import
Since Mjpg-streamer works fine with the input_uvc plugin and numpy.core.multiarray imports fine in python 2 and 3, I thought I might be using the wrong version of Numpy. So I tried it with Numpy 1.7, 1.9, and 1.10 and even tried a fresh install of OpenCV and Numpy on another SD card, but I still get the same error.

Is there something I may have missed?
Reply With Quote
  #3   Spotlight this post!  
Unread 14-03-2016, 10:57
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #4   Spotlight this post!  
Unread 14-03-2016, 11:02
Wishbonea's Avatar
Wishbonea Wishbonea is offline
Registered User
FRC #2062
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2008
Location: Wisconsin
Posts: 11
Wishbonea is an unknown quantity at this point
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?
Reply With Quote
  #5   Spotlight this post!  
Unread 15-03-2016, 00:50
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #6   Spotlight this post!  
Unread 15-03-2016, 08:41
Wishbonea's Avatar
Wishbonea Wishbonea is offline
Registered User
FRC #2062
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2008
Location: Wisconsin
Posts: 11
Wishbonea is an unknown quantity at this point
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
Reply With Quote
  #7   Spotlight this post!  
Unread 15-03-2016, 18:51
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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)
    PyErr_Print();
else
    fprintf(stderr, "No error occurred!?\n");
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #8   Spotlight this post!  
Unread 15-03-2016, 22:30
Wishbonea's Avatar
Wishbonea Wishbonea is offline
Registered User
FRC #2062
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2008
Location: Wisconsin
Posts: 11
Wishbonea is an unknown quantity at this point
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):
  File "/usr/local/lib/python3.4/dist-packages/numpy/__init__.py", line 180, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python3.4/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python3.4/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python3.4/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python3.4/dist-packages/numpy/core/__init__.py", line 14, in <module>
    from . import multiarray
ImportError: /usr/local/lib/python3.4/dist-packages/numpy/core/multiarray.cpython-34m.so: undefined symbol: PyType_GenericNew
ImportError: numpy.core.multiarray failed to import
Error loading numpy!
Thanks so much for your help!
Reply With Quote
  #9   Spotlight this post!  
Unread 15-03-2016, 23:28
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #10   Spotlight this post!  
Unread 17-03-2016, 09:17
Wishbonea's Avatar
Wishbonea Wishbonea is offline
Registered User
FRC #2062
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2008
Location: Wisconsin
Posts: 11
Wishbonea is an unknown quantity at this point
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?
Reply With Quote
  #11   Spotlight this post!  
Unread 17-03-2016, 10:47
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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)");
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #12   Spotlight this post!  
Unread 16-05-2016, 02:25
jrw jrw is offline
Registered User
FRC #4774 (The Drop Bears)
Team Role: Mentor
 
Join Date: Sep 2013
Rookie Year: 2013
Location: Sydney
Posts: 6
jrw is an unknown quantity at this point
Re: mjpg-streamer now with OpenCV input plugin (+filtering)

Quote:
Originally Posted by virtuald View Post
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.
Did you ever use the exposure parameter (-ex)? We have the same webcam, but cannot get the stream with the correct exposure. It is definitely calling the opencv filter, because the image has the result of our processing (eg detected contours), but the exposure is stubbornly refusing to be set.
Reply With Quote
  #13   Spotlight this post!  
Unread 16-05-2016, 11:50
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: mjpg-streamer now with OpenCV input plugin (+filtering)

Quote:
Originally Posted by jrw View Post
Did you ever use the exposure parameter (-ex)? We have the same webcam, but cannot get the stream with the correct exposure. It is definitely calling the opencv filter, because the image has the result of our processing (eg detected contours), but the exposure is stubbornly refusing to be set.
Yeah, OpenCV doesn't set exposure properly. See this bug report (looks like a fix was merged, so maybe next year it'll work!).

To set exposure correctly, we use the v4l-ctl executable. I thought I had documented it somewhere, but I can't seem to find it. Anyways, we found it useful to be able to switch the exposure dynamically via NetworkTables, so I created an object to manage that.

You'll have to search the forums, but I remember seeing that the lifecam-3000 only supports certain exposure setting values (like 5 and 10), and for all others it just does full exposure. We use 5 I think.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:30.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi