Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Swap Camera Bandwidth Issues (http://www.chiefdelphi.com/forums/showthread.php?t=154541)

Nick Donahue 40 31-01-2017 19:22

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.

Nick Donahue 40 31-01-2017 20:43

Re: Swap Camera Bandwidth Issues
 
I have discovered that there is an option to disable CvSinks, as shown here.
Code:

              cvSink1.setEnabled(false);
                            cvSink2.setEnabled(false);
                            cvSink3.setEnabled(true);

This would go in the while set of your code under each individual if statement.

Mark Sellars 04-02-2017 10:15

Re: Swap Camera Bandwidth Issues
 
G'day Nick - you might want to take a look at this thread as well


All times are GMT -5. The time now is 09:54.

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