Go to Post Now, almost a day later, no one has begun interpreting, dissecting, attaching synonyms, re-interpreting or otherwise mangling Dave's wise words in an effort to find the hidden key to the game. I smell a conspiracy! - petek [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 07-02-2017, 14:39
5854RoboProgram 5854RoboProgram is offline
Registered User
AKA: Keegan
FRC #5854 (Glitch)
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2016
Location: North Carolina
Posts: 1
5854RoboProgram is an unknown quantity at this point
More Than Two USB Cameras??

Hello FRC programming community,
I am the lead programmer on team 5854, this is the team's second year and my first as lead programmer.

I am using usb cameras to get images to my vision system. I have two cameras hooked up to the usb slots on the roborio and I am using a custom class I made using the built in CameraServer library. (Code Example below) I was wondering if there is a way to make a third camera streaming service. Or if there would be a problem using a usb splitter because I'm not sure how the rio will handle it.


Thnak you in advance.
And sorry if the text is confusing or misspelled, I'm dyslexic.

Code on how I'm making the camera server:

Code:
usbCamera = new UsbCamera("USB Camera 0", cameraId);
usbCamera.setResolution(640, 400);
usbCamera.setBrightness(1);

mjpegServer1 = new MjpegServer("serve_USB Camera 0", 1181);

mjpegServer1.setSource(usbCamera); 
	    
cvSink = new CvSink("opencv_USB Camera 0");

cvSink.setSource(usbCamera);

outputStream = new CvSource("Blur", PixelFormat.kMJPEG, 640, 480, 30);

mjpegServer2 = new MjpegServer("serve_Blur", 1182);

mjpegServer2.setSource(outputStream);
Reply With Quote
  #2   Spotlight this post!  
Unread 07-02-2017, 15:36
Bkeeneykid's Avatar
Bkeeneykid Bkeeneykid is offline
#wheatcoastneatcoast
AKA: Devin Keeney
FRC #1982 (Cougar Robotics); Season Long Fantasy FIRST (F3)
Team Role: Leadership
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Lenexa, Kansas
Posts: 368
Bkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud ofBkeeneykid has much to be proud of
Re: More Than Two USB Cameras??

Using more than two cameras is certainly possibly. Don't use a "USB Splitter", instead just simply use a USB hub on the robot. It may get a little funky with too many because of current draw. Once plugged in, they should simply show up on the roboRIO dashboard, and you should be able to create another CameraServer class.
__________________

F4 Network Website Designer

2010-2012: A Whole Buncha FLL Teams; Team Spirit, Gracious Professionalism Award winner
2015-Current: FRC 1982, Captain, Electrical Lead
Beginning FIRST Volunteer

Moderator on the FIRSTwiki
Reply With Quote
  #3   Spotlight this post!  
Unread 07-02-2017, 19:58
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,602
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: More Than Two USB Cameras??

We've used 3 HD-3000's. You have to be careful with the resolution and fps, because you can run into USB bandwidth issues.
Reply With Quote
  #4   Spotlight this post!  
Unread 07-02-2017, 21:33
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: More Than Two USB Cameras??

I highly recommend using something along these lines to make sure that you are only ever streaming the camera you want, instead of wasting bandwidth by streaming multiple cameras at the same time.

Code:
public void robotInit() {
    	
    	Thread t = new Thread(() -> {
    		
    		boolean allowCam1 = false;
    		
    		UsbCamera camera1 = CameraServer.getInstance().startAutomaticCapture(0);
            camera1.setResolution(320, 240);
            camera1.setFPS(30);
            UsbCamera camera2 = CameraServer.getInstance().startAutomaticCapture(1);
            camera2.setResolution(320, 240);
            camera2.setFPS(30);
            
            CvSink cvSink1 = CameraServer.getInstance().getVideo(camera1);
            CvSink cvSink2 = CameraServer.getInstance().getVideo(camera2);
            CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 320, 240);
            
            Mat image = new Mat();
            
            while(!Thread.interrupted()) {
            	
            	if(oi.getGamepad().getRawButton(9)) {
            		allowCam1 = !allowCam1;
            	}
            	
                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
  #5   Spotlight this post!  
Unread Yesterday, 08:15
ajsmith's Avatar
ajsmith ajsmith is offline
Captain, Programming, Build
AKA: Andy Smith
FRC #5546 (A.R.T.)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2014
Location: Petersburg, VA
Posts: 10
ajsmith is a jewel in the roughajsmith is a jewel in the roughajsmith is a jewel in the rough
Re: More Than Two USB Cameras??

Quote:
Originally Posted by thecoopster20 View Post
I highly recommend using something along these lines to make sure that you are only ever streaming the camera you want, instead of wasting bandwidth by streaming multiple cameras at the same time.

Code:
public void robotInit() {
    	
    	Thread t = new Thread(() -> {
    		
    		boolean allowCam1 = false;
    		
    		UsbCamera camera1 = CameraServer.getInstance().startAutomaticCapture(0);
            camera1.setResolution(320, 240);
            camera1.setFPS(30);
            UsbCamera camera2 = CameraServer.getInstance().startAutomaticCapture(1);
            camera2.setResolution(320, 240);
            camera2.setFPS(30);
            
            CvSink cvSink1 = CameraServer.getInstance().getVideo(camera1);
            CvSink cvSink2 = CameraServer.getInstance().getVideo(camera2);
            CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 320, 240);
            
            Mat image = new Mat();
            
            while(!Thread.interrupted()) {
            	
            	if(oi.getGamepad().getRawButton(9)) {
            		allowCam1 = !allowCam1;
            	}
            	
                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();
I've seen this code in multiple threads here but I have never been able to get it to work. We always end up with the "too many simultaneous client streams" error whenever we try to switch to the second camera (setting allowcam1 to true). Any ideas on why this isn't working for us?

EDIT: We just tried a new robot program with just this code and got it to work. If anyone else has this error, we had to change the source in smartdashboard to "switcher," then RESTART the smartdashboard and the robot, and then it would work. I think the problem was that since the smartdashboard had started off streaming the usb cam 0, it never stopped streaming after switching sources.

Last edited by ajsmith : Yesterday at 08:48. Reason: Fixed problem.
Reply With Quote
  #6   Spotlight this post!  
Unread Today, 20:44
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,076
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: More Than Two USB Cameras??

Quote:
Originally Posted by ajsmith View Post
I've seen this code in multiple threads here but I have never been able to get it to work. We always end up with the "too many simultaneous client streams" error whenever we try to switch to the second camera (setting allowcam1 to true). Any ideas on why this isn't working for us?

EDIT: We just tried a new robot program with just this code and got it to work. If anyone else has this error, we had to change the source in smartdashboard to "switcher," then RESTART the smartdashboard and the robot, and then it would work. I think the problem was that since the smartdashboard had started off streaming the usb cam 0, it never stopped streaming after switching sources.
What do you mean when you say you have to change the source to "switcher?"
Reply With Quote
  #7   Spotlight this post!  
Unread Today, 21:40
ajsmith's Avatar
ajsmith ajsmith is offline
Captain, Programming, Build
AKA: Andy Smith
FRC #5546 (A.R.T.)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2014
Location: Petersburg, VA
Posts: 10
ajsmith is a jewel in the roughajsmith is a jewel in the roughajsmith is a jewel in the rough
Re: More Than Two USB Cameras??

Quote:
Originally Posted by Caleb Sykes View Post
What do you mean when you say you have to change the source to "switcher?"
In SmartDashboard, the USB Camera Viewer widget has a source property. In the code above, it says "putVideo("Switcher", 320, 240);" so that is the new video source. The Java code automatically adds a "Camera 0" or "cam0" source for the webcam, but using that produces an error when switching cameras because you are still trying to stream that single camera rather than the special source that will switch between the two.
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 22:46.

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