Go to Post What is this word "done" of which you speak? - Rick TYler [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 31-01-2017, 19:22
Nick Donahue 40 Nick Donahue 40 is offline
Registered User
FRC #4028
 
Join Date: Jan 2017
Location: Cincinnati
Posts: 3
Nick Donahue 40 is an unknown quantity at this point
Swap Camera Bandwidth Issues

Hello,
I am a programmer from team 4028, and I have been tasked with being able to swap between camera streams with the push of a button. I have been able to do so with the code below.
Code:
package org.usfirst.frc.team4028.robot;

import org.opencv.core.Mat;

import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.CvSource;
import edu.wpi.cscore.MjpegServer;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.cscore.VideoSink;
import edu.wpi.first.wpilibj.CameraServer;

public class MakeItWork
{	
	private String _cameraname;
	
	public MakeItWork(String cameraname)
	{
		_cameraname = cameraname;
		Thread cameraThread = new Thread(JavadotMakeItWork);
		cameraThread.start();
	}

	public String GetString()
	{
		return _cameraname;
	}
	
	public void SwapCamera(String cameraname) 
	{
		_cameraname = cameraname;
	}	
	
	private Runnable JavadotMakeItWork = new Runnable()
	{

		@Override
		public void run() {
			
			// TODO Auto-generated method stub
			UsbCamera _cam0 = new UsbCamera("cam0", 0); //CameraServer.getInstance().startAutomaticCapture(0);
           
            
            UsbCamera _cam1 = new UsbCamera("cam1", 1); //= CameraServer.getInstance().startAutomaticCapture(1);
            
            
            UsbCamera _cam2 = new UsbCamera("cam2", 2); //= CameraServer.getInstance().startAutomaticCapture(1);
           
            CvSink cvSink1 = CameraServer.getInstance().getVideo(_cam0);
            CvSink cvSink2 = CameraServer.getInstance().getVideo(_cam1);
            CvSink cvSink3 = CameraServer.getInstance().getVideo(_cam2);
            
            CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 640, 480);
            
            Mat image = new Mat();
            
            MjpegServer server = new MjpegServer("server", 1181);
            
            server.setSource(outputStream);
            
            while(!Thread.interrupted()) 
            {
            	if(_cameraname == "cam0")
            	{         

            		_cam0.setFPS(16);
            		_cam1.setFPS(0);
            		_cam2.setFPS(0);
            		_cam0.setResolution(640, 480);
            		cvSink1.grabFrame(image);
            	
            	} 
            	else if(_cameraname == "cam1")
            	{

            		_cam0.setFPS(0);
            		_cam1.setFPS(16);
            		_cam2.setFPS(0);
            		_cam1.setResolution(640, 480);
            		cvSink2.grabFrame(image);
        
            		
            	}
            	else if(_cameraname =="cam2")
            	{

            		_cam0.setFPS(0);
            		_cam1.setFPS(0);
            		_cam2.setFPS(16);
            		_cam2.setResolution(640, 480);
            		cvSink3.grabFrame(image);
            	}
                
                outputStream.putFrame(image);
            }
		}

	};

}
However, the problem is with the resolution and FPS. In order to have enough bandwidth to stream all 3 (and possibly more) cameras, the resolution and FPS has to be so bad it is not practical to use it in competition. Does anyone have any ideas as to how to cancel previous camera streams via alterations to my code or the source code itself? Any help would be much appreciated.
Reply With Quote
 


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 04:04.

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