Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPIcal documentation initial draft #2691

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ElliotScher
Copy link

Adds initial draft of documentation for new WPIcal tool: wpilibsuite/allwpilib#6915

@mcm001
Copy link
Contributor

mcm001 commented Aug 11, 2024

Great stuff so far overall! Great to see this coming together.

@ElliotScher ElliotScher requested review from mcm001 and rzblue August 12, 2024 02:14
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
source/docs/software/wpilib-tools/wpical/index.rst Outdated Show resolved Hide resolved
.. image:: images/Calibrate.png
:alt: Calibrate

There are two options for calibrating your camera, :guilabel:`OpenCV` and :guilabel:`MRcal`. It is generally recommended to calibrate with :guilabel:`MRcal`, as it has slightly better accuracy and is more robust against bad calibration data. WPIcal uses a ChArUco board for camera calibration. You can generate a ChArUco board here: `calib.io <https://calib.io/pages/camera-calibration-pattern-generator>`_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular recommendations on board width/height? I noticed the gui defaults to 12x8. And whitch dictionary should I be using?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(wpical seems to be hard-coded to 5x5?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the calibration is hard coded to 5x5. I was testing with a 12x8 board and it seemed to work well. I haven't tested other widths or heights too thoroughly. The optimal dimensions will vary camera to camera right?


Camera Calibration
------------------
To measure the distance between tags in a video, you need the camera's intrinsics to account for things like distortion. WPIcal allows users to upload a video file to calibrate the camera in the tool, or upload a JSON file with your camera's intrinsics
Copy link
Contributor

@mcm001 mcm001 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I capture a video file? I was able to do it on linux with gstreamer, but it was pretty non-trivial.

gst-launch-1.0 -vvv v4l2src device=/dev/video0 extra-controls="c,gain=25,exposure_auto=1" ! image/jpeg,format=MJPG,width=1600,height=1200,framerate=50/1 ! jpegdec ! videoconvert ! tee name=t t. ! queue ! autovideosink t. ! queue ! videoconvert ! avimux ! filesink location=output.avi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using a phone camera and then transferring the file to a computer to calibrate. For linux It will need to be transcoded. Do you think we should document how to capture the video for linux machines too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OBS also works well

  1. Add a V4L2 video capture device
  2. Change properties:
    image
  3. Under settings->video change the base resolution
    image
  4. Settings->output, not sure why i don't see avi on linux but it should be an option


.. warning:: CalibDB calibrations have been known to fail when bad snapshots are taken. If your calibration data looks suspect, repeat calibration process again.

Custom JSON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there's any value in supporting the photonvision JSON format directly? It's fairly similar

{
"resolution":{"width":1600.0,"height":1200.0},
"cameraIntrinsics":{"rows":3,"cols":3,"type":6,"data":[894.6473376999364,0.0,793.0568907406183,0.0,894.5611200668925,667.7549963404546,0.0,0.0,1.0]},
"distCoeffs":{"rows":1,"cols":8,"type":6,"data":[-0.04029854641739141,-0.03601719361588292,-0.0016269824645254384,-6.609780019207605E-4,0.14767766830679485,-0.09429815218469685,0.057468937992229234,0.11574241865507603]},
"calobjectWarp":[6.226950423907065E-4,6.020992541813042E-5]
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean if teams want to use their PV calibrations and cameras for field calibration?

Linux Users Only:
*****************
Linux users must transcode all videos to MJPEG codec without an audio stream in an .avi file before uploading to WPIcal. This can be done with an ffmpeg command:
``ffmpeg -i <video_file.mp4> -f avi -c:v mjpeg -b:v 4000k -an <video_file.avi>``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that -b:v 4000k is totally arbitrary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is a good default?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, I just stole it from stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants