Add support for enumerating and changing USB camera video mode.

This commit is contained in:
Peter Johnson
2016-09-29 00:04:16 -07:00
parent a5fe605aae
commit 70616c48e3
16 changed files with 813 additions and 20 deletions

View File

@@ -93,7 +93,7 @@ public class CameraServerJNI {
public static native int createUSBSourceDev(String name, int dev);
public static native int createUSBSourcePath(String name, String path);
public static native int createHTTPSource(String name, String url);
public static native int createCvSource(String name);
public static native int createCvSource(String name, int pixelFormat, int width, int height, int fps);
//
// Source Functions
@@ -104,6 +104,12 @@ public class CameraServerJNI {
public static native boolean isSourceConnected(int source);
public static native int getSourceProperty(int source, String name);
public static native int[] enumerateSourceProperties(int source);
public static native VideoMode getSourceVideoMode(int source);
public static native boolean setSourceVideoMode(int source, int pixelFormat, int width, int height, int fps);
public static native boolean setSourcePixelFormat(int source, int pixelFormat);
public static native boolean setSourceResolution(int source, int width, int height);
public static native boolean setSourceFPS(int source, int fps);
public static native VideoMode[] enumerateSourceVideoModes(int source);
public static native int copySource(int source);
public static native void releaseSource(int source);

View File

@@ -11,8 +11,19 @@ package edu.wpi.cameraserver;
public class CvSource extends VideoSource {
/// Create an OpenCV source.
/// @param name Source name (arbitrary unique identifier)
public CvSource(String name) {
super(CameraServerJNI.createCvSource(name));
/// @param mode Video mode being generated
public CvSource(String name, VideoMode mode) {
super(CameraServerJNI.createCvSource(name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
}
/// Create an OpenCV source.
/// @param name Source name (arbitrary unique identifier)
/// @param pixelFormat Pixel format
/// @param width width
/// @param height height
/// @param fps fps
public CvSource(String name, VideoMode.PixelFormat pixelFormat, int width, int height, int fps) {
super(CameraServerJNI.createCvSource(name, pixelFormat.getValue(), width, height, fps));
}
/// Put an OpenCV image and notify sinks.

View File

@@ -0,0 +1,41 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cameraserver;
/// Video mode
public class VideoMode {
public enum PixelFormat {
kUnknown(0), kMJPEG(1), kYUYV(2), kRGB565(3);
private int value;
private PixelFormat(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
private static final PixelFormat[] m_pixelFormatValues = PixelFormat.values();
public VideoMode(int pixelFormat, int width, int height, int fps) {
this.pixelFormat = m_pixelFormatValues[pixelFormat];
this.width = width;
this.height = height;
this.fps = fps;
}
/// Pixel format
public PixelFormat pixelFormat;
/// Width in pixels
public int width;
/// Height in pixels
public int height;
/// Frames per second
public int fps;
}

View File

@@ -19,7 +19,7 @@ public class VideoProperty {
public int getValue() {
return value;
}
};
}
private static final Type[] m_typeValues = Type.values();
public String getName() {

View File

@@ -65,6 +65,54 @@ public class VideoSource {
return rv;
}
/// Get the current video mode.
public VideoMode getVideoMode() {
return CameraServerJNI.getSourceVideoMode(m_handle);
}
/// Set the video mode.
/// @param mode Video mode
public boolean setVideoMode(VideoMode mode) {
return CameraServerJNI.setSourceVideoMode(m_handle, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps);
}
/// Set the video mode.
/// @param pixelFormat desired pixel format
/// @param width desired width
/// @param height desired height
/// @param fps desired FPS
/// @return True if set successfully
public boolean setVideoMode(VideoMode.PixelFormat pixelFormat, int width, int height, int fps) {
return CameraServerJNI.setSourceVideoMode(m_handle, pixelFormat.getValue(), width, height, fps);
}
/// Set the pixel format.
/// @param pixelFormat desired pixel format
/// @return True if set successfully
public boolean setPixelFormat(VideoMode.PixelFormat pixelFormat) {
return CameraServerJNI.setSourcePixelFormat(m_handle, pixelFormat.getValue());
}
/// Set the resolution.
/// @param width desired width
/// @param height desired height
/// @return True if set successfully
public boolean setResolution(int width, int height) {
return CameraServerJNI.setSourceResolution(m_handle, width, height);
}
/// Set the frames per second (FPS).
/// @param fps desired FPS
/// @return True if set successfully
public boolean setFPS(int fps) {
return CameraServerJNI.setSourceFPS(m_handle, fps);
}
/// Enumerate all known video modes for this source.
public VideoMode[] enumerateVideoModes() {
return CameraServerJNI.enumerateSourceVideoModes(m_handle);
}
/// Enumerate all existing sources.
/// @return Vector of sources.
public static VideoSource[] enumerateSources() {