PhotonVision / photonvision

PhotonVision is the free, fast, and easy-to-use computer vision solution for the FIRST Robotics Competition.
https://photonvision.org
GNU General Public License v3.0
271 stars 187 forks source link

Add option to import and export pipeline settings from a json file #853

Open srimanachanta opened 1 year ago

srimanachanta commented 1 year ago

Currently, there is no simple way to share pipeline settings between devices or teams without having to export all settings which might not be the desired behavior to override all settings other than pipelines. There should be an option to export and import pipeline configs as JSON files. This allows the photon team and other teams to easily share pipeline settings with other teams along with helping teams store pipelines long-term. This is already a feature in Limelight where pipelines can be exported as .vpr files.

srimanachanta commented 1 year ago

Setting files should look something like this (.JSONC file). They can be directly dumped from state.cameraSettings.currentPipelineSettings with data pulled from other areas.

// Example Pipeline Format

{
  // Pipeline Overview
  "pipelineName": "Test Pipeline",
  "pipelineType": 5,

  // General Settings
  "cameraExposure": 1,
  "cameraBrightness": 2,
  "cameraAutoExposure": false,
  "cameraRedGain": 3,
  "cameraBlueGain": 4,
  "inputImageRotationMode": 0,
  "cameraVideoModeIndex": 0,
  "streamingFrameDivisor": 0,

  // Reflective Settings
  "hsvHue": [0, 15],
  "hsvSaturation": [0, 15],
  "hsvValue": [0, 25],
  "hueInverted": false,
  "contourArea": [0, 12],
  "contourRatio": [0, 12],
  "contourFullness": [0, 12],
  "contourSpecklePercentage": 5,
  "contourFilterRangeX": 5,
  "contourFilterRangeY": 5,
  "contourGroupingMode": 0,
  "contourIntersection": 0,
  "contourSortMode": 0,
  "inputShouldShow": true,
  "outputShouldShow": true,
  "outputShouldDraw": true,
  "outputShowMultipleTargets": false,
  "offsetRobotOffsetMode": 0,
  "solvePNPEnabled": false,
  "targetRegion": 0,
  "contourTargetOrientation": 1,
  "cornerDetectionAccuracyPercentage": 10,

  // AprilTag Settings
  "tagFamily": 1,
  "decimate": 1.0,
  "blur": 0.0,
  "threads": 1,
  "debug": false,
  "refineEdges": true,
  "numIterations": 1,
  "decisionMargin": 0,
  "hammingDist": 0
}

Input validation needs to be done to make sure that there aren't pipelines with duplicate names and individual validation for each config setting to make sure it is within some min and max thresholds or some other values. This is in case people edit the file itself after saving it.