-
Notifications
You must be signed in to change notification settings - Fork 291
Calibration Rotation! #1464
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
Merged
Merged
Calibration Rotation! #1464
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8721ecf
Calibration Rotation!
Juniormunk 5efe0e4
implement mat caching plus bug fixes
Juniormunk 5ab3379
lint and format
Juniormunk f870836
Add libcamera calibration rotation
Juniormunk 12f2bb0
Cache FrameStaticProperties Instead
Juniormunk 7827b1b
Cache Frame Static Properties, Add unit test?, Remove JsonMat BS
Juniormunk 8e3b2ef
shit's fucked, yo
mcm001 da72a00
Clarify rotation handedness
mcm001 d3d5b46
use image points
mcm001 e9bcaaf
Parameterize test
mcm001 1e38934
add rotated test
mcm001 b8550e0
Add ADD
mcm001 d1f8d22
Ugh
mcm001 2f552fb
Update Tests
Juniormunk 1373899
ugh
mcm001 d4cf6b4
oog abooga
mcm001 b33933f
run lint
mcm001 aa6c6d9
lesgo
mcm001 cda7613
run lint
mcm001 0516666
Cleanup and support opencv8
mcm001 16b6f04
hmmmm
mcm001 741ec68
Fixup tests
mcm001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/source/docs/contributing/design-descriptions/image-rotation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Calibration and Image Rotation | ||
|
|
||
| ## Rotating Points | ||
|
|
||
| To stay consistent with the OpenCV camera coordinate frame, we put the origin in the top left, with X right, Y down, and Z out (as required by the right-hand rule). Intuitively though, if I ask you to rotate an image 90 degrees clockwise though, you'd probably rotate it about -Z in this coordinate system. Just be aware of this inconsistency. | ||
|
|
||
|  | ||
|
|
||
| If we have any one point in any of those coordinate systems, we can transform it into any of the other ones using standard geometry libraries by performing relative transformations (like in this pseudocode): | ||
|
|
||
| ``` | ||
| Translation2d tag_corner1 = new Translation2d(); | ||
| Translation2d rotated = tag_corner1.relativeTo(ORIGIN_ROTATED_90_CCW); | ||
| ``` | ||
|
|
||
| ## Image Distortion | ||
|
|
||
| The distortion coefficients for OPENCV8 is given in order `[k1 k2 p1 p2 k3 k4 k5 k6]`. Mrcal names these coefficients `[k_0 k_1, k_2, k_3, k_4, k_5, k_6, k_7]`. | ||
|
|
||
| ```{math} | ||
| \begin{align*} | ||
| \vec P &\equiv \frac{\vec p_{xy}}{p_z} \\ | ||
| r &\equiv \left|\vec P\right| \\ | ||
| \vec P_\mathrm{radial} &\equiv \frac{ 1 + k_0 r^2 + k_1 r^4 + k_4 r^6}{ 1 + k_5 r^2 + k_6 r^4 + k_7 r^6} \vec P \\ | ||
| \vec P_\mathrm{tangential} &\equiv | ||
| \left[ \begin{aligned} | ||
| 2 k_2 P_0 P_1 &+ k_3 \left(r^2 + 2 P_0^2 \right) \\ | ||
| 2 k_3 P_0 P_1 &+ k_2 \left(r^2 + 2 P_1^2 \right) | ||
| \end{aligned}\right] \\ | ||
| \vec q &= \vec f_{xy} \left( \vec P_\mathrm{radial} + \vec P_\mathrm{tangential} \right) + \vec c_{xy} | ||
| \end{align*} | ||
| ``` | ||
|
|
||
| From this, we observe at `k_0, k_1, k_4, k_5, k_6, k_7` depend only on the norm of {math}`\vec P`, and will be constant given a rotated image. However, `k_2` and `k_3` go with {math}`P_0 \cdot P_1`, `k_3` with {math}`P_0^2`, and `k_2` with {math}`P_1^2`. | ||
|
|
||
| Let's try a concrete example. With a 90 degree CCW rotation, we have {math}`P0=-P_{1\mathrm{rotated}}` and {math}`P1=P_{0\mathrm{rotated}}`. Let's substitute in | ||
|
|
||
| ```{math} | ||
| \begin{align*} | ||
| \left[ \begin{aligned} | ||
| 2 k_2 P_0 P_1 &+ k_3 \left(r^2 + 2 P_0^2 \right) \\ | ||
| 2 k_3 P_0 P_1 &+ k_2 \left(r^2 + 2 P_1^2 \right) | ||
| \end{aligned}\right] &= | ||
| \left[ \begin{aligned} | ||
| 2 k_{2\mathrm{rotated}} (-P_{1\mathrm{rotated}}) P_{0\mathrm{rotated}} &+ k_{3\mathrm{rotated}} \left(r^2 + 2 (-P_{1\mathrm{rotated}})^2 \right) \\ | ||
| 2 k_{3\mathrm{rotated}} (-P_{1\mathrm{rotated}}) P_{0\mathrm{rotated}} &+ k_{2\mathrm{rotated}} \left(r^2 + 2 P_{0\mathrm{rotated}}^2 \right) | ||
| \end{aligned}\right] \\ | ||
| &= | ||
| \left[ \begin{aligned} | ||
| -2 k_{2\mathrm{rotated}} P_{1\mathrm{rotated}} P_{0\mathrm{rotated}} &+ k_{3\mathrm{rotated}} \left(r^2 + 2 P_{1\mathrm{rotated}}^2 \right) \\ | ||
| -2 k_{3\mathrm{rotated}} P_{1\mathrm{rotated}} P_{0\mathrm{rotated}} &+ k_{2\mathrm{rotated}} \left(r^2 + 2 P_{0\mathrm{rotated}}^2 \right) | ||
| \end{aligned}\right] | ||
| \end{align*} | ||
| ``` | ||
|
|
||
| By inspection, this results in just applying another 90 degree rotation to the k2/k3 parameters. Proof is left as an exercise for the reader. Note that we can repeat this rotation to yield equations for tangential distortion for 180 and 270 degrees. | ||
|
|
||
| ```{math} | ||
| k_2'=-k_3 | ||
| k_3'=k_2 | ||
| ``` |
Binary file added
BIN
+14.4 KB
docs/source/docs/contributing/design-descriptions/images/image_corner_frames.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Software Architecture Design Descriptions | ||
|
|
||
| ```{toctree} | ||
| :maxdepth: 1 | ||
| image-rotation | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ | |
| building-photon | ||
| building-docs | ||
| developer-docs/index | ||
| design-descriptions/index | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.