Go to Post There's 2 things that are really hard in CS - naming things, cache invalidation, and off by one errors. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 31-01-2017, 20:23
thecoopster20 thecoopster20 is offline
4th Year Programmer - Java
FRC #3602 (Robomos)
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2014
Location: Escanaba, MI
Posts: 27
thecoopster20 is an unknown quantity at this point
Help With Raspberry Pi Camera Stream

Hello, recently I was able to get a USB camera plugged into a raspberry pi 3 to stream via MJPEG streamer. Before we had two usb cameras plugged into the RIO and swapped via this code which has now been modified to theoretically work with the pi stream. However, when I try this, I either get a too many simultaneous streams error, or an error saying that the address specified cannot be reached.

I have the MJPEG stream also set to stream port 1180. Any tips on how to get this working? Also, am I better off just putting this switcher logic on the pi and grab the switch button via Network Tables?
Code:
public void robotInit() {
    	
    	Thread t = new Thread(() -> {
    		
    		boolean allowCam1 = false;
    		
    		UsbCamera camera1 = CameraServer.getInstance().startAutomaticCapture(0);
            camera1.setResolution(320, 240);
            camera1.setFPS(30);
            
            HttpCamera piCam = new HttpCamera("piCam", "http://10.23.170.203:1180/?action=stream", HttpCameraKind.kMJPGStreamer);
            
            
            CvSink cvSink1 = CameraServer.getInstance().getVideo(camera1);
            CvSink cvSink2 = CameraServer.getInstance().getVideo(piCam);
            CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 640, 480);
            
            Mat image = new Mat();
            
            while(!Thread.interrupted()) {
            	
            	if(oi.getGamepad().getRawButton(9)) {
            		allowCam1 = !allowCam1;
            		Timer.delay(1);
            	}
            	
                if(allowCam1){
                  cvSink2.setEnabled(false);
                  cvSink1.setEnabled(true);
                  cvSink1.grabFrame(image);
                } else{
                  cvSink1.setEnabled(false);
                  cvSink2.setEnabled(true);
                  cvSink2.grabFrame(image);     
                }
                
                outputStream.putFrame(image);
            }
            
        });
        t.start();
Reply With Quote
  #2   Spotlight this post!  
Unread 01-02-2017, 23:22
jmcculloch jmcculloch is offline
Jeremy McCulloch
FRC #2485 (W.A.R. (We Are Robot) Lords)
Team Role: Programmer
 
Join Date: May 2016
Rookie Year: 2015
Location: San Diego
Posts: 6
jmcculloch is a jewel in the roughjmcculloch is a jewel in the roughjmcculloch is a jewel in the roughjmcculloch is a jewel in the rough
Re: Help With Raspberry Pi Camera Stream

Can you also post the code that is running on the Raspberry Pi?

Also, you should check the url for the camera/raspberry pi, because it ordinarily takes the form 10.TE.AM.xxx and yours appears to not. This may be the source of the address specified not reached error.

Hope this helps.

Last edited by jmcculloch : 02-02-2017 at 00:08. Reason: Wrote that the port that is used when startautomaticcapture is run is 1180, but it is actually 1181
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2017, 07:21
thecoopster20 thecoopster20 is offline
4th Year Programmer - Java
FRC #3602 (Robomos)
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2014
Location: Escanaba, MI
Posts: 27
thecoopster20 is an unknown quantity at this point
Re: Help With Raspberry Pi Camera Stream

This is the command run from a script inside the pi:

mjpg_streamer -o "output_http.so -w ./www -p 1180" -i "input_uvc.so -f 15 -r 640x480 -y -n" &

It outputs the stream to the Raspberry Pi's IP address, not the robot's IP. Maybe I should try getting mDNS on the pi and try using raspberrypi.local?

Last edited by thecoopster20 : 02-02-2017 at 07:30.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-02-2017, 19:37
thecoopster20 thecoopster20 is offline
4th Year Programmer - Java
FRC #3602 (Robomos)
Team Role: Programmer
 
Join Date: Mar 2016
Rookie Year: 2014
Location: Escanaba, MI
Posts: 27
thecoopster20 is an unknown quantity at this point
Re: Help With Raspberry Pi Camera Stream

Alright, I figured it out. Rather than hook the cameras into the pi and stream from there, I've kept the cameras on the RIO and then I grab the "Switcher" stream's ip and use that for GRIP. Makes everything a heck of a lot easier to manage as well, since I don't have to worry about the settings for the pi getting properly executed and started.
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 09:49.

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