View Single Post
  #2   Spotlight this post!  
Unread 24-01-2017, 22:39
dmelcer9 dmelcer9 is offline
Registered User
AKA: Daniel
FRC #0810 (Mechanical Bulls)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2012
Location: Smithtown
Posts: 51
dmelcer9 is an unknown quantity at this point
Re: Switching Camera Views

You can do something like this (edited from the screensteps page):

Code:
public void robotInit() {
            new Thread(() -> {
                UsbCamera camera1 = CameraServer.getInstance().startAutomaticCapture(0);
                camera1.setResolution(640, 480);
                UsbCamera camera2 = CameraServer.getInstance().startAutomaticCapture(1);
                camera2.setResolution(640, 480);
                
                CvSink cvSink1 = CameraServer.getInstance().getVideo(camera1);
                CvSink cvSink2 = CameraServer.getInstance().getVideo(camera2);
                CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 640, 480);
                
                Mat image = new Mat();
                
                while(!Thread.interrupted()) {
                    if(/*switcher button logic*/){
                      cvSink1.grabFrame(image);
                    } else{
                      cvSink2.grabFrame(image);
                    }
                    
                    outputStream.putFrame(image);
                }
            }).start();
    }
I'm tired, so this is all I can think of now. The code may not be entirely right, but the general idea should work. There probably is a much better/simpler/more efficient way that I have no clue about.

Last edited by dmelcer9 : 24-01-2017 at 22:40. Reason: Code
Reply With Quote