https://april.eecs.umich.edu/w/api.php?action=feedcontributions&user=John+Wang&feedformat=atomApril - User contributions [en]2024-03-29T10:47:50ZUser contributionsMediaWiki 1.25.1https://april.eecs.umich.edu/w/index.php?title=AprilTags&diff=216AprilTags2017-02-07T17:34:55Z<p>John Wang: Replaced content with "The latest version of AprilTag can be found at https://april.eecs.umich.edu/apriltag/"</p>
<hr />
<div>The latest version of AprilTag can be found at https://april.eecs.umich.edu/apriltag/</div>John Wanghttps://april.eecs.umich.edu/w/index.php?title=Camera_suite&diff=215Camera suite2016-05-31T02:16:29Z<p>John Wang: /* Video overview */</p>
<hr />
<div>The APRIL camera calibration suite is now available in the master branch of the APRIL Robotics Toolkit. Located in april.camera, this suite computes accurate camera calibrations and results are more repeatable than popular alternatives like OpenCV (as determined by human trials). A 2D grid of AprilTags is required for calibration and removes the need for observing the entire calibration target for detection. Interactive single-camera calibration via AprilCal is great for novices and experts alike and provides target position suggestions to ensure highly-accurate calibrations. Flexible multi-camera calibration is also supported without interactive suggestions<br />
<br />
== Paper and Citations ==<br />
<br />
The AprilCal paper, '''AprilCal: Assisted and repeatable camera calibration''', will appear at IROS 2013. Please see [http://april.eecs.umich.edu/papers/details.php?name=richardson2013iros this link] for the paper and citation.<br />
<br />
== Video overview ==<br />
A video explanation of AprilCal is available for new users. This video is available in three resolutions: [http://april.eecs.umich.edu/media/aprilcal/aprilcal_1080p.mov 1080p (83M)], [http://april.eecs.umich.edu/media/aprilcal/aprilcal_large.m4v Large (42M)], and [http://april.eecs.umich.edu/media/aprilcal/aprilcal_mobile.m4v Mobile (18M)]<br />
<br />
[[Image:AprilCalVideo.png|thumb|center|500px|Still image from the AprilCal overview video. Use the links above to view the video]]<br />
<br />
== Calibration targets ==<br />
<br />
<gallery align="center" caption="Calibration targets" widths="300px" heights="200px" perrow="6"><br />
File:8.5x11in-tag-mosaic-1.5in.png|8.5x11 mosaic with 1.5 inch tags [[Media:8.5x11in-tag-mosaic-1.5in.pdf|(PDF)]] [[Media:8.5x11in-tag-mosaic-1.5in.png|(png)]]<br />
File:8.5x11in-tag-mosaic-1in.png|8.5x11 mosaic with 1 inch tags [[Media:8.5x11in-tag-mosaic-1in.pdf|(PDF)]] [[Media:8.5x11in-tag-mosaic-1in.png|(png)]]<br />
</gallery><br />
<br />
We recommend mounting these targets on foam poster board. It can<br />
usually be done quite cheaply and quickly (about $5/ sq ft), for<br />
example at Kinkos. If you can find out the email address for your<br />
local FedEx Office, usually formatted country###@fedex.com, you can<br />
use the following as a template to order by email:<br />
<br />
<pre><br />
Hi, I would like to print ## copies of the<br />
8.5x11in-tag-mosaic-1.5in.pdf on a foam mounted matte paper, (I was<br />
quoted 5/sq ft for the foam mounting, plus printing) The file is a<br />
72dpi raster; it's important that if it is resized (e.g. to 300dpi),<br />
that no interpolation/resampling is done to ensure a crisp transition<br />
from black to white on the borders.<br />
<br />
Please let me know when I can get them, and/or contact me if you have<br />
questions. Also, I won't need to see a proof, assuming the final<br />
output preserves crisp transitions from black to white.<br />
<br />
Thanks!<br />
Your Name<br />
Cell: +1 (555) 555-5555<br />
Attachments: 8.5x11in-tag-mosaic-1.5in.pdf<br />
</pre><br />
<br />
== Camera drivers ==<br />
<br />
Connecting to your camera can be done in one of two ways 1) use a camera driver included in the APRIL software stack or 2) use your own camera driver and send imagery over TCP.<br />
<br />
=== APRIL JCam basics (hardware camera library) ===<br />
<br />
april.camera uses april.jcam to interact with camera hardware. Each camera type<br />
implements the abstract class ImageSource. Drivers written in C are used via<br />
JNI bindings and the ImageSourceNative implementation of ImageSource.<br />
Additional drivers for your application could be added using the C image_source<br />
API, or conveniently in Java using ImageSourceReflect, which allows you to host<br />
your Java ImageSource in another tree and specify the class name for<br />
reflection.<br />
<br />
Examples of supported camera drivers/cameras include:<br />
* v4l2 - Video4Linux version 2. This includes most webcams.<br />
* dc1394 - IEEE1394 using libdc1394. We only support Format7<br />
* pgusb - A Point Grey USB driver using libusb to avoid the libdc1394<br />
dependency<br />
* file - A specific file (e.g. a png)<br />
* dir - A directory of files<br />
* islog - ImageSourceLog format. A raw log of the byte buffer returned by<br />
the camera<br />
* islog-lcm - An ISLog with image pointers (byte offsets) published over LCM at<br />
time of writing and received over LCM for playback control.<br />
<br />
A camera url typically has the following format<br />
<br />
<tt>"driver://device?firstpropery=value&secondproperty=value&..."</tt><br />
<br />
Quotes are needed if specifying more than one property, otherwise bash will interpret the ampersand instead of passing it through. Property order matters (e.g. framerate can affect valid shutter range). april.jcam.JCamView is a nice interactive tool to discover feature names. If you use the "print URL" button in JCamView, note that it prints all features, which is not what you want. If a feature is disabled, (e.g. exposure-mode=[0|1] or exposure-enabled=0), the corresponding value (e.g. exposure=3) should be '''omitted'''. Otherwise, some drivers will enable the feature when you attempt to set the value.<br />
<br />
One known bug in jcam is that features set with the camera URL are set before the camera is started. However, the bus is allocated on starting the camera, and the bus allocation determines the maximum framerate. This doesn't affect most users and should be fixed eventually.<br />
<br />
=== Custom drivers with a TCP connection ===<br />
<br />
For easy integration with custom video drivers, the APRIL software stack includes an "ImageSource" that listens for images sent over TCP in a simple format.<br />
<br />
If your linux machine includes a standard webcam, the following commands should test this interface. These should be run concurrently in separate terminals.<br />
<br />
java april.jcam.JCamExample tcp-server://7001<br />
<br />
java april.jcam.JCamTCPExample v4l2:///dev/video0 tcp://localhost:7001<br />
<br />
In this example, JCamExample will listen for images through an ImageSourceTCP object on port 7001. The JCamTCPExample will open the specified camera (using the v4l2 driver) and send the images over the TCP stream to localhost over port 7001.<br />
<br />
Example code for C is available in [[File:tcp_image_streamer.c]]. This file does not connect to a camera (that's left to the user), but will create an image with random pixel values and serialize it into the appropriate format. Compile and run with:<br />
<br />
gcc -o tcpstream -std=gnu99 tcp_image_streamer.c -lc<br />
./tcpstream localhost 7001<br />
<br />
The C example above generates and sends a grayscale image (8 bits per pixel). The appropriate format string for this is "GRAY8". Other supported format strings can be found in april/java/src/april/jcam/ImageConvert.java. Most users will probably use one of the following formats: "GRAY8", "RGB", "BAYER_RGGB" or "BAYER_GBRG".<br />
<br />
== AprilCal ==<br />
<br />
AprilCal is an interactive camera calibrator that suggestions calibration target positions to the user to minimize the worst-case model error measured in pixels. We recommend using the 1.5" tag calibration target with AprilCal.<br />
<br />
[[Image:AprilCalGUI.png|thumb|center|400px|The AprilCal interface]]<br />
<br />
Launch AprilCal with a command like the following. The camera used here is a Point Grey USB camera using the pgusb driver. Most of these settings can actually be ommitted, as they are application defaults (launch with -h to see defaults).<br />
<br />
<tt>java april.camera.calibrator.AprilCal -u "pgusb://?fidx=2?shutter=mode=2&shutter=0.010&gain-mode=2&gain=10" -c april.camera.models.AngularPolynomialInitializer -p kclength=4 -m 0.0381</tt><br />
<br />
To use AprilCal, show the calibration target to the camera and follow the on-screen directions. Images are left-right mirrored for ease-of-use and shown in grayscale to highlight the tag suggestions (shown in bright colors). The shape of the rectified image is shown as an outline in the top-left. At any point, you can click within this outline to switch to a live-rectified view for inspecting your calibration.<br />
<br />
AprilCal will display a suggested mosaic position as squares with colored outlines. Live AprilTag detections are shown as filled, colored squares. Each AprilTag corresponds to a unique ID, and each tag is persistently assigned a color based on this ID. AprilCal instructs the user to place the mosaic in a specific position by showing the colored outlines and expects the user to find the target position that aligns these colors. Note that colors are repeated, but they are repeated in a semi-random ordering that should be easy to decipher. Further, if the mosaic is rotated by roughly 90 or more degrees, text will appear on the display to point this out to the user.<br />
<br />
Sometimes the first suggestion is very hard or impossible to achieve, as the camera calibration is not well known at this point. Get the mosaic reasonably close and hit the spacebar to force an image capture.<br />
<br />
AprilCal includes a simple terminal emulator. Mouse-over the OpenGL canvas and type ":<Tab>" to see a list of commands. These include options like popping-up a plot of the mosaic extrinsics, saving the calibration, and performing model selection. <br />
<br />
The save directory is printed to the terminal and is typically in /tmp/cameraCalibration/ The files with the calibration parameters are human readable and typically named <tt>calibration.config</tt> or, if using model selection, something like <tt>AngularPolynomialCalibration,kclength=4.config</tt>.<br />
<br />
=== A note on technique ===<br />
AprilCal can present a learning curve for some users. It relies on strong visual-spatial reasoning to align the target to the suggestion in a game-like fashion. Beta users of AprilCal were timed and seemed to take around 8 minutes for the first calibration, and 2.5 minutes after that. The main difference between the runs was that they had learned what visual cues to align and focused on them.<br />
<br />
Here are two viable techniques:<br />
* Align a small section of the mosaic first before trying to bring in the far corners of the target<br />
* Align one edge first, then move the target closer to get the right scale and height before finally rotating the physical target about the matched edge until it aligns.<br />
<br />
[http://ifm.eecs.umich.edu/data/Combined.mp4 Here is a video of AprilCal in action with the above technique]<br />
<br />
[[Image:AprilCalTechnique.png|thumb|center|500px|Still image from the AprilCal technique video. Use the link above to view the video]]<br />
<br />
== MultiCameraCalibrator ==<br />
<br />
The MultiCameraCalibrator is a multi-camera calibration tool for experts who do not need mosaic position suggestions. All users are strongly recommended to use AprilCal a few times before using the MultiCameraCalibrator. The quality of your input images has a big impact on the calibration accuracy.<br />
<br />
A command like the following will instantiate multiple cameras for calibration<br />
<br />
<tt>java april.camera.calibrator.MultiCameraCalibrator -u "v4l2:///dev/video0?fidx=4;pgusb://?fidx=2?shutter=mode=2&shutter=0.005&gain-mode=2&gain=3"</tt><br />
<br />
Initially, every camera is rendered in its own coordinate system. In the first image below, you can see a black and dark-gray background, each showing a colored axis to denote the camera position.<br />
<br />
[[Image:MultiCameraCalibratorInterface.png|500px|center|thumb|The MultiCameraCalibrator interface]]<br />
<br />
Eventually, the coordinate systems will merge after observing images that jointly constrain the calibration and after all constrained cameras are initialized. After adding six images, the mosaics are shown as below. The distortion function is plotted for each camera in the lower-left corner. The mean reprojection error (MRE) and mean-squared reprojection error (MSE) are shown in the top-right.<br />
<br />
[[Image:MultiCameraCalibrator-0005.png|500px|center|thumb|The calibration after 6 images]]<br />
<br />
This GUI also lets you perform model selection with the stock set of models, as well as save results. The save directory is printed to the terminal and is typically in /tmp/cameraCalibration/ The files with the calibration parameters are human readable and typically named <tt>calibration.config</tt> or, if using model selection, something like <tt>AngularPolynomialCalibration,kclength=4.config</tt>.<br />
<br />
'''Note''': Images are captured from multiple cameras in an ad-hoc fashion. No time synchronization is done. For high-quality results, take images of stationary targets to ensure that all images correspond to the same mosaic position.<br />
<br />
=== Batch Calibration ===<br />
Batch calibration can be performed on a directory of images, including the images saved from a previous calibration with either AprilCal or the MultiCameraCalibrator. Simply <tt>cd</tt> into the image directory in question and run the following command<br />
<br />
<tt>/usr/bin/java -Xmx2048M -Xms2048M -ea -server april.camera.calibrator.MultiCameraCalibrator -u "dir://`pwd`?loop=false&fps=1" -a</tt><br />
<br />
This command sets the Java memory allocation limits, which is necessary when calibrating with large numbers of high-resolution images. The <tt>dir</tt> ImageSource is used with <tt>pwd</tt> to determine the current directory. It is also possible to fully-specify the directory. Relative paths may not be fully supported, at present. The <tt>loop=false</tt> and <tt>-a</tt> options ensure that all images in the directory are used exactly once. The fps option is strictly optional, but may be desired to allow inspection of the tag detections.<br />
<br />
== Conventions ==<br />
<br />
For ease of use in most image pipelines, integer pixel coordinates are taken to be the center of the pixel. When drawing a texture, the texture should span from <tt>(-0.5, -0.5)</tt> to <tt>(w-0.5, h-0.5)</tt> so that points corresponding to integer image indices are properly centered in each pixel. This convention is followed in the rasterization classes (NearestNeighborRasterizer and BilinearRasterizer).<br />
<br />
Note: Make sure to turn image interpolation off when verifying plot alignment (e.g. NO_MAG_FILTER in april.vis.VisTexture)<br />
<br />
[[Image:pixelconvention.png|center|thumb|300px|Pixel coordinate convention]]<br />
<br />
== Recommended camera model ==<br />
<br />
There are three primary camera models in the april.camera library. This may<br />
change, but at the time of writing, one model is sufficient for our lenses<br />
tested in the APRIL lab (from webcams to fisheye lenses). This model is the<br />
AngularPolynomialCalibration.<br />
<br />
The AngularPolynomialCalibration is reminiscent of both the standard radial<br />
distortion formulation and the lens model from Kannala and Brandt. In the<br />
Caltech model, points are projected using pinhole projection (e.g. x_px is<br />
proportional to X_meters / Z_meters), then distorted using a polynomial<br />
function of the radius after pinhole projection. The reduced version of the<br />
Kannala-Brandt model that we use in this work simply uses a polynomial function<br />
of one of the angles in spherical coordinates to map into the distorted image.<br />
This supports use of points behind the image plane (z < 0) and avoids the<br />
explosion of tan(theta)=X/Z as theta approaches PI/2 radians. In our tests,<br />
this Kannala-Brandt-like model performs as well or better than most<br />
radial-formulated models and seemed to yield a more reasonable extrapolation<br />
outside of the constrained part of the image (in the corners where no<br />
calibration constraints were made)<br />
<br />
[[Image:AngularPolynomialMath.png|thumb|center|300px|The mathematical representation of the AngularPolynomialCalibration. Inspired by the Kannala-Brandt model]]<br />
<br />
For those who need to use the standard radial[-tangential] models used by<br />
Caltech and similar systems, look to the RadialPolynomialCalibration or the<br />
CaltechCalibration, respectively. Unlike the RadialPolynomialCalibration, the<br />
CaltechCalibration includes skew and tangential distortion. Note that the<br />
caltech model combines their distortion coefficients into one vector, which we<br />
do *not* do, for clarity and expandability. This is documented in CaltechCalibration.java.<br />
<br />
Of course, we also include a distortion-free model, DistortionFreeCalibration.<br />
<br />
CalibrationInitializers are companion classes to Calibrations<br />
(e.g. AngularPolynomialCalibration and AngularPolynomialInitializer). The<br />
initializers contain factory methods to instantiate an instance of the calibration<br />
from either observations (calibration images) or a list of parameters<br />
(e.g. for copying). Initializers are typically short classes (<100 lines)<br />
and exist because some calibrations may be sensitive to initialization.<br />
<br />
All models, to varying degrees, support a variable number of distortion<br />
parameters. Caltech models in practice use 2-3 distortion coefficients. 4 is<br />
recommended with the AngularPolynomialCalibration. These are specified in a<br />
key-value pair string that is comma-separated if multiple parameters are<br />
required. These parameters are class-specific, so check the *initializer* to<br />
see which substrings are extracted from the parameterString. For most models,<br />
only one parameter is necessary and the default is sufficient ("kclength=4")<br />
<br />
Our main calibration tools support model selection as a post-processing step,<br />
essentially allowing you to take the images you have collected and re-calibrate<br />
with a number of pre-specified models. The tools which support this includes a<br />
variable number of distortion parameters for each model. Please note that<br />
making a responsible model choice requires a larger number of images than are<br />
typically collected for calibration. A user can achieve a good calibration in<br />
10 images, but more images should be taken to make a confident decision about<br />
model selection due to the risk of over-fitting.<br />
<br />
== Model Selection ==<br />
<br />
If use of an alternate camera model is desired, the recommended approach is to calibrate with AprilCal and the AngularPolynomialCalibration (the default, which typically yields best results), then run model selection after calibrating by selecting the GUI and typing <code>:model-selection</code>. If using the MultiCameraCalibrator GUI, click the appropriate button to run model selection. In either case, a series of batch optimizations will be performed each with a different lens model or number of distortion parameters. Mean reprojection error, mean-squared reprojection error, and max reprojection error statistics will be printed for each model so the user can make an informed decision and pick the appropriate model. Configuration files for each model will be saved alongside the images in the directory specified, or in <code>/tmp/cameraCalibration/imageSetX</code> if unspecified<br />
<br />
== Compatibility with OpenCV ==<br />
<br />
Two calibration models are compatible with [http://www.vision.caltech.edu/bouguetj/calib_doc/ Caltech's camera calibration toolbox] and [http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html the OpenCV calibrator]:<br />
# CaltechCalibration (and CaltechInitializer)<br />
# RadialPolynomialCalibration (and RadialPolynomialInitializer)<br />
<br />
The difference between these models is simply that the RadialPolynomialCalibration does not contain skew or tangential distortion terms. Otherwise, the same radial distortion model is the same between the RadialPolynomialCalibration and CaltechCalibration models.<br />
<br />
When converting one of these calibrations to a format compatible with OpenCV, note the [http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html#theory order of the distortion terms]. Caltech and OpenCV order the terms as follows: <code>(k1, k2, p1, p2, k3)</code>. AprilCal supports a variable number of polynomial terms for the radial distortion models, including the CaltechCalibration. For simplicity, the radial and tangential distortion terms are stored in separate arrays.<br />
<br />
When using a RadialPolynomialCalibration model with three distortion terms (kclength=3), use the following distortion array for OpenCV: <code>(kc[0], kc[1], 0, 0, kc[2])</code>.<br />
<br />
When using a CaltechCalibration model with three distortion terms (kclength=3), use the following distortion array for OpenCV: <code>(kc[0], kc[1], lc[0], lc[1], kc[2])</code><br />
<br />
If using fewer than three distortion parameters, set unknown parameters to zero.<br />
<br />
Obtaining the parameters for these models is as simple as running model selection as a post-processing step, and picking the appropriate file.<br />
<br />
== Image rectification ==<br />
<br />
Each camera model implements the View interface, which species methods to<br />
convert pixel coordinates (distorted coordinates, if appropriate for the model)<br />
to 3D rays. Classes conforming to the radial distortion model typically return<br />
rays with z==1, while the AngularPolynomialCalibration returns rays on the unit<br />
sphere (mag==1)<br />
<br />
Resampling images uses a *rasterizer* class, such as the BilinearRasterizer.<br />
This class takes a pair of models and produces an image for the output model<br />
using the following conversion:<br />
<br />
pixel for output -> 3D ray -> pixel for input<br />
<br />
The NearestNeighborRasterizer simply looks up the appropriate pixel index,<br />
while the bilinear variant performs bilinear interpolation to reduce image<br />
artifacts.<br />
<br />
Images can be freely rectified or synthetically distorted using this class.<br />
They can also be rotated about the focal center, as is appropriate in stereo<br />
rectification.<br />
<br />
Rectifying images requires an implementation of the View interface that<br />
specifies the new camera intrinsics matrix and width/height of the new image.<br />
These can be created by hand (e.g. DistortionFreeCalibration), but typically<br />
users will use one of the following classes:<br />
<br />
* MaxRectifiedView <br />
Contains the whole rectified image as determined by iteratively rectifying<br />
the border of the distorted image to compute the appropriate bounds<br />
<br />
* MaxInscribedRectifiedView <br />
Like the MaxRectifiedView, but uses a simple heuristic to find the largest<br />
rectangle inside the rectified border. This should result in an image<br />
without undefined pixels<br />
<br />
* MaxGrownInscribedRectifiedView <br />
Like the MaxInscribedRectifiedView, except the region is computed with a<br />
simple region-growing algorithm. This is necessary for stereo rectified<br />
pairs where one camera was significantly rotated<br />
<br />
Both the input and output view can be passed through a ScaledView if<br />
appropriate for your application. If the input view is a scaled view, the input<br />
image must have already been scaled appropriately (the dimensions will be<br />
checked with assertions). ScaledViews are best for advanced users -- you<br />
should be careful to check your model if you are, for example, making an image<br />
pyramid.<br />
<br />
=== Examples ===<br />
<br />
==== Source image ====<br />
<br />
[[Image:Rectification-image0002.png|thumb|center|300px|Source image]]<br />
<br />
==== MaxRectifiedView ====<br />
<br />
<tt>java april.camera.tools.ExampleRectifier -c calibration.config -s aprilCameraCalibration.camera0000 -r april.camera.MaxRectifiedView -i image0002.png</tt><br />
<br />
[[Image:Rectification-image0002.MaxRectifiedView.png|thumb|center|300px|Max rectified view (shows entire image)]]<br />
<br />
==== MaxInscribedRectifiedView ====<br />
<br />
Here is an inscribed rectified view. Note that the image is essentially the MaxRectifiedView above, but cropped by an appropriate amount to remove the black padding that comes with the MaxRectifiedView. This is done using a heuristic that appears to work in single-camera cases. For multi-camera cases where one camera is rotated, like stereo rectification, use the MaxGrownInscribedRectifiedView<br />
<br />
<tt>java april.camera.tools.ExampleRectifier -c calibration.config -s aprilCameraCalibration.camera0000 -r april.camera.MaxInscribedRectifiedView -i image0002.png</tt><br />
<br />
[[Image:Rectification-image0002.MaxInscribedRectifiedView.png|thumb|center|300px|Max inscribed rectified view (shows image without undefined areas)]]<br />
<br />
=== Stereo rectification ===<br />
<br />
Here is an illustrative example of stereo rectification. The red lines are included by the tool for human inspection and can be omitted with a command-line option.<br />
<br />
<tt>java april.camera.tools.ExampleStereoRectifier -c calibration.config -l camera0/image0002.png -r camera1/image0002.png</tt><br />
<br />
<gallery align="center" widths=350px heights=240px perrow=2 caption"A stereo rectified pair"><br />
File:Rectification-image0002.stereo_rectified_left.png|Left image<br />
File:Rectification-image0002.stereo_rectified_right.png|Right image<br />
</gallery></div>John Wanghttps://april.eecs.umich.edu/w/index.php?title=Index.php/AprilTags&diff=214Index.php/AprilTags2016-05-27T18:09:20Z<p>John Wang: Redirected page to AprilTags</p>
<hr />
<div>#REDIRECT [[AprilTags]]</div>John Wang