Add stream settings to webdash and examples (#61)

This commit is contained in:
Peter Johnson
2019-01-13 16:59:08 -08:00
committed by GitHub
parent 42d270870e
commit 03dae15ddf
7 changed files with 220 additions and 64 deletions
+19 -3
View File
@@ -38,7 +38,15 @@
"name": <property name>
"value": <property value>
}
]
],
"stream": { // optional
"properties": [
{
"name": <stream property name>
"value": <stream property value>
}
]
}
}
]
}
@@ -59,6 +67,7 @@ struct CameraConfig {
std::string name;
std::string path;
wpi::json config;
wpi::json streamConfig;
};
std::vector<CameraConfig> cameras;
@@ -87,6 +96,9 @@ bool ReadCameraConfig(const wpi::json& config) {
return false;
}
// stream properties
if (config.count("stream") != 0) c.streamConfig = config.at("stream");
c.config = config;
cameras.emplace_back(std::move(c));
@@ -159,11 +171,15 @@ bool ReadConfig() {
void StartCamera(const CameraConfig& config) {
wpi::outs() << "Starting camera '" << config.name << "' on " << config.path
<< '\n';
auto camera = frc::CameraServer::GetInstance()->StartAutomaticCapture(
config.name, config.path);
cs::UsbCamera camera{config.name, config.path};
auto inst = frc::CameraServer::GetInstance();
auto server = inst->StartAutomaticCapture(camera);
camera.SetConfigJson(config.config);
camera.SetConnectionStrategy(cs::VideoSource::kConnectionKeepOpen);
if (config.streamConfig.is_object())
server.SetConfigJson(config.streamConfig);
}
} // namespace
+53 -1
View File
@@ -41,7 +41,7 @@ function displayStatus(message) {
// Enable and disable buttons based on connection status
var connectedButtonIds = ['systemRestart', 'networkApproach', 'networkAddress', 'networkMask', 'networkGateway', 'networkDNS', 'visionUp', 'visionDown', 'visionTerm', 'visionKill', 'systemReadOnly', 'systemWritable', 'visionClient', 'visionTeam', 'visionDiscard', 'addConnectedCamera', 'addCamera', 'applicationType'];
var connectedButtonClasses = ['cameraName', 'cameraPath', 'cameraAlternatePaths', 'cameraPixelFormat', 'cameraWidth', 'cameraHeight', 'cameraFps', 'cameraBrightness', 'cameraWhiteBalance', 'cameraExposure', 'cameraProperties', 'cameraRemove', 'cameraCopyConfig']
var connectedButtonClasses = ['cameraName', 'cameraPath', 'cameraAlternatePaths', 'cameraPixelFormat', 'cameraWidth', 'cameraHeight', 'cameraFps', 'cameraBrightness', 'cameraWhiteBalance', 'cameraExposure', 'cameraProperties', 'streamWidth', 'streamHeight', 'streamFps', 'streamCompression', 'streamDefaultCompression', 'cameraRemove', 'cameraCopyConfig']
var writableButtonIds = ['networkSave', 'visionSave', 'applicationSave'];
var systemStatusIds = ['systemMemoryFree1s', 'systemMemoryFree5s',
'systemMemoryAvail1s', 'systemMemoryAvail5s',
@@ -340,6 +340,18 @@ $('#visionClient').change(function() {
}
});
function getCameraPropertyValue(data, name) {
if (data === null) {
return null;
}
for (var i = 0; i < data.length; i++) {
if (data[i].name === name) {
return data[i].value;
}
}
return null;
}
function updateVisionCameraView(camera, value) {
if ('name' in value) {
camera.find('.cameraTitle').text('Camera ' + value.name);
@@ -356,6 +368,19 @@ function updateVisionCameraView(camera, value) {
camera.find('.cameraWhiteBalance').val(value['white balance']);
camera.find('.cameraExposure').val(value.exposure);
camera.find('.cameraProperties').val(JSON.stringify(value.properties));
if ('stream' in value && 'properties' in value.stream) {
camera.find('.streamWidth').val(getCameraPropertyValue(value.stream.properties, 'width'));
camera.find('.streamHeight').val(getCameraPropertyValue(value.stream.properties, 'height'));
camera.find('.streamFps').val(getCameraPropertyValue(value.stream.properties, 'fps'));
camera.find('.streamCompression').val(getCameraPropertyValue(value.stream.properties, 'compression'));
camera.find('.streamDefaultCompression').val(getCameraPropertyValue(value.stream.properties, 'default_compression'));
} else {
camera.find('.streamWidth').val('');
camera.find('.streamHeight').val('');
camera.find('.streamFps').val('');
camera.find('.streamCompression').val('');
camera.find('.streamDefaultCompression').val('');
}
}
function updateVisionCameraDataFromJson(i, data) {
@@ -548,6 +573,33 @@ $('#visionSave').click(function() {
} catch (err) {
delete value['properties'];
}
value.stream = {'properties': []};
var streamWidth = parseInt(camera.find('.streamWidth').val(), 10);
if (!isNaN(streamWidth)) {
value.stream.properties.push({'name': 'width', 'value': streamWidth});
}
var streamHeight = parseInt(camera.find('.streamHeight').val(), 10);
if (!isNaN(streamHeight)) {
value.stream.properties.push({'name': 'height', 'value': streamHeight});
}
var streamFps = parseInt(camera.find('.streamFps').val(), 10);
if (!isNaN(streamFps)) {
value.stream.properties.push({'name': 'fps', 'value': streamFps});
}
var streamCompression = parseInt(camera.find('.streamCompression').val(), 10);
if (!isNaN(streamCompression)) {
value.stream.properties.push({'name': 'compression', 'value': streamCompression});
}
var streamDefaultCompression = parseInt(camera.find('.streamDefaultCompression').val(), 10);
if (!isNaN(streamDefaultCompression)) {
value.stream.properties.push({'name': 'default_compression', 'value': streamDefaultCompression});
}
});
var msg = {
type: 'visionSave',
+87 -49
View File
@@ -280,59 +280,97 @@
</div>
</div>
</div>
<div class="form-group">
<div class="custom-file">
<input type="file" class="custom-file-input cameraSettingsFile" accept=".json,text/json,application/json" id="cameraSettingsFileNEW">
<label class="custom-file-label" for="cameraSettingsFileNEW">Load Source Config From JSON File</label>
<div class="card">
<div class="card-header">
Camera Settings
</div>
<div class="card-body">
<div class="form-group">
<div class="custom-file">
<input type="file" class="custom-file-input cameraSettingsFile" accept=".json,text/json,application/json" id="cameraSettingsFileNEW">
<label class="custom-file-label" for="cameraSettingsFileNEW">Load Source Config From JSON File</label>
</div>
</div>
<div class="form-group">
<button class="btn btn-sm cameraCopyConfig" type="button">
<span data-feather="copy"></span>
Copy Source Config From Camera
</button>
</div>
<div class="form-row">
<div class="form-group col-auto">
<label for="cameraPixelFormatNEW">Pixel Format</label>
<select class="form-control cameraPixelFormat" id="cameraPixelFormatNEW">
<option value="mjpeg">MJPEG</option>
<option value="yuyv">YUYV</option>
<option value="rgb565">RGB565</option>
<option value="bgr">BGR</option>
<option value="gray">Gray</option>
</select>
</div>
<div class="form-group col-auto">
<label for="cameraWidthNEW">Width</label>
<input type="number" class="form-control cameraWidth" id="cameraWidthNEW" size="5">
</div>
<div class="form-group col-auto">
<label for="cameraHeightNEW">Height</label>
<input type="number" class="form-control cameraHeight" id="cameraHeightNEW" size="5">
</div>
<div class="form-group col-auto">
<label for="cameraFpsNEW">FPS</label>
<input type="number" class="form-control cameraFps" id="cameraFpsNEW" size="4">
</div>
</div>
<div class="form-row">
<div class="form-group col-auto">
<label for="cameraBrightnessNEW">Brightness</label>
<input type="text" class="form-control cameraBrightness" id="cameraBrightnessNEW" size="4">
</div>
<div class="form-group col-auto">
<label for="cameraWhiteBalanceNEW">White Balance</label>
<input type="text" class="form-control cameraWhiteBalance" id="cameraWhiteBalanceNEW" size="4">
</div>
<div class="form-group col-auto">
<label for="cameraExposureNEW">Exposure</label>
<input type="text" class="form-control cameraExposure" id="cameraExposureNEW" size="4">
</div>
</div>
<div class="form-group">
<label for="cameraPropertiesNEW">Custom Properties JSON</label>
<textarea class="form-control cameraProperties" id="cameraPropertiesNEW" rows="3"></textarea>
</div>
</div>
</div>
<div class="form-group">
<button class="btn btn-sm cameraCopyConfig" type="button">
<span data-feather="copy"></span>
Copy Source Config From Camera
</button>
</div>
<div class="form-row">
<div class="form-group col-auto">
<label for="cameraPixelFormatNEW">Pixel Format</label>
<select class="form-control cameraPixelFormat" id="cameraPixelFormatNEW">
<option value="mjpeg">MJPEG</option>
<option value="yuyv">YUYV</option>
<option value="rgb565">RGB565</option>
<option value="bgr">BGR</option>
<option value="gray">Gray</option>
</select>
<div class="card">
<div class="card-header">
Video Stream Defaults
</div>
<div class="form-group col-auto">
<label for="cameraWidthNEW">Width</label>
<input type="number" class="form-control cameraWidth" id="cameraWidthNEW" size="5">
<div class="card-body">
<div class="form-row">
<div class="form-group col-auto">
<label for="streamWidthNEW">Width</label>
<input type="number" class="form-control streamWidth" id="streamWidthNEW" size="5">
</div>
<div class="form-group col-auto">
<label for="streamHeightNEW">Height</label>
<input type="number" class="form-control streamHeight" id="streamHeightNEW" size="5">
</div>
<div class="form-group col-auto">
<label for="streamFpsNEW">FPS</label>
<input type="number" class="form-control streamFps" id="streamFpsNEW" size="4">
</div>
</div>
<div class="form-row">
<div class="form-group col-auto">
<label for="streamCompressionNEW">Compression</label>
<input type="number" class="form-control streamCompression" id="streamWidthNEW" size="5">
</div>
<div class="form-group col-auto">
<label for="streamDefaultCompressionNEW">Default Compression</label>
<input type="number" class="form-control streamDefaultCompression" id="streamDefaultCompressionNEW" size="4">
</div>
</div>
</div>
<div class="form-group col-auto">
<label for="cameraHeightNEW">Height</label>
<input type="number" class="form-control cameraHeight" id="cameraHeightNEW" size="5">
</div>
<div class="form-group col-auto">
<label for="cameraFpsNEW">FPS</label>
<input type="number" class="form-control cameraFps" id="cameraFpsNEW" size="4">
</div>
</div>
<div class="form-row">
<div class="form-group col-auto">
<label for="cameraBrightnessNEW">Brightness</label>
<input type="text" class="form-control cameraBrightness" id="cameraBrightnessNEW" size="4">
</div>
<div class="form-group col-auto">
<label for="cameraWhiteBalanceNEW">White Balance</label>
<input type="text" class="form-control cameraWhiteBalance" id="cameraWhiteBalanceNEW" size="4">
</div>
<div class="form-group col-auto">
<label for="cameraExposureNEW">Exposure</label>
<input type="text" class="form-control cameraExposure" id="cameraExposureNEW" size="4">
</div>
</div>
<div class="form-group">
<label for="cameraPropertiesNEW">Custom Properties JSON</label>
<textarea class="form-control cameraProperties" id="cameraPropertiesNEW" rows="3"></textarea>
</div>
</form>
</div>