001/*----------------------------------------------------------------------------*/ 002/* Copyright (c) FIRST 2016. All Rights Reserved. */ 003/* Open Source Software - may be modified and shared by FRC teams. The code */ 004/* must be accompanied by the FIRST BSD license file in the root directory of */ 005/* the project. */ 006/*----------------------------------------------------------------------------*/ 007 008package edu.wpi.cscore; 009 010import org.opencv.core.Mat; 011 012/// A source that represents a video camera. 013public class CvSource extends VideoSource { 014 /// Create an OpenCV source. 015 /// @param name Source name (arbitrary unique identifier) 016 /// @param mode Video mode being generated 017 public CvSource(String name, VideoMode mode) { 018 super(CameraServerJNI.createCvSource(name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps)); 019 } 020 021 /// Create an OpenCV source. 022 /// @param name Source name (arbitrary unique identifier) 023 /// @param pixelFormat Pixel format 024 /// @param width width 025 /// @param height height 026 /// @param fps fps 027 public CvSource(String name, VideoMode.PixelFormat pixelFormat, int width, int height, int fps) { 028 super(CameraServerJNI.createCvSource(name, pixelFormat.getValue(), width, height, fps)); 029 } 030 031 /// Put an OpenCV image and notify sinks. 032 /// Only 8-bit single-channel or 3-channel (with BGR channel order) images 033 /// are supported. If the format, depth or channel order is different, use 034 /// Mat.convertTo() and/or cvtColor() to convert it first. 035 /// @param image OpenCV image 036 public void putFrame(Mat image) { 037 CameraServerJNI.putSourceFrame(m_handle, image.nativeObj); 038 } 039 040 /// Signal sinks that an error has occurred. This should be called instead 041 /// of NotifyFrame when an error occurs. 042 public void notifyError(String msg) { 043 CameraServerJNI.notifySourceError(m_handle, msg); 044 } 045 046 /// Set source connection status. Defaults to true. 047 /// @param connected True for connected, false for disconnected 048 public void setConnected(boolean connected) { 049 CameraServerJNI.setSourceConnected(m_handle, connected); 050 } 051 052 /// Set source description. 053 /// @param description Description 054 public void setDescription(String description) { 055 CameraServerJNI.setSourceDescription(m_handle, description); 056 } 057 058 /// Create a property. 059 /// @param name Property name 060 /// @param kind Property kind 061 /// @param minimum Minimum value 062 /// @param maximum Maximum value 063 /// @param step Step value 064 /// @param defaultValue Default value 065 /// @param value Current value 066 /// @return Property 067 public VideoProperty createProperty(String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value) { 068 return new VideoProperty( 069 CameraServerJNI.createSourceProperty(m_handle, name, kind.getValue(), minimum, maximum, step, defaultValue, value)); 070 } 071 072 /// Create a property with a change callback. 073 /// @param name Property name 074 /// @param kind Property kind 075 /// @param minimum Minimum value 076 /// @param maximum Maximum value 077 /// @param step Step value 078 /// @param defaultValue Default value 079 /// @param value Current value 080 /// @param onChange Callback to call when the property value changes 081 /// @return Property 082 //public VideoProperty createProperty( 083 // String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value, 084 // std::function<void(VideoProperty property)> 085 // onChange); 086 087 /// Configure enum property choices. 088 /// @param property Property 089 /// @param choices Choices 090 public void SetEnumPropertyChoices(VideoProperty property, String[] choices) { 091 CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.m_handle, choices); 092 } 093}