-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add camera instrinsics config files; and class to convert points base… #414
Draft
hdefazio
wants to merge
1
commit into
master
Choose a base branch
from
dev/camera_intrinsics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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,49 @@ | ||
import configparser | ||
import kwimage | ||
|
||
import numpy as np | ||
|
||
|
||
class CameraCalibration: | ||
def __init__( | ||
self, | ||
src_calibration_fp="config/camera_intrinsics/hololens2.conf", | ||
src_calibration_key="RIGHT_CAM_HD", | ||
dst_calibration_fp="config/camera_intrinsics/zed.conf", | ||
dst_calibration_key="RIGHT_CAM_HD" | ||
): | ||
# Read the camera intrinsics | ||
configparser = configparser.ConfigParser() | ||
src_calibration_config = configparser.read(src_calibration_fp) | ||
dst_calibration_config = configparser.read(dst_calibration_fp) | ||
|
||
src_intrinsics = src_calibration_config[src_calibration_key] | ||
dst_intrinsics = dst_calibration_config[dst_calibration_key] | ||
|
||
self.k_src = np.array( | ||
[src_intrinsics["fx"], src_intrinsics["s"], src_intrinsics["cx"]], | ||
[0, src_intrinsics["fy"], src_intrinsics["cy"]], | ||
[0, 0, 1] | ||
) | ||
self.k_dst = np.array( | ||
[dst_intrinsics["fx"], dst_intrinsics["s"], dst_intrinsics["cx"]], | ||
[0, dst_intrinsics["fy"], dst_intrinsics["cy"]], | ||
[0, 0, 1] | ||
) | ||
|
||
self.k = np.matmul(self.k_dst, np.linalg.inv(self.k_src)) | ||
|
||
def calibrate_bbox(self, bbox: kwimage.Box): | ||
# Make sure the bbox is tlbr | ||
bbox = bbox.toformat("tlbr") | ||
tl = bbox.data[:1] | ||
br = bbox.data[1:] | ||
|
||
# Convert coordinates from src to dst camera | ||
tl_dst = numpy.matmul(self.k, tl) | ||
br_dst = numpy.matmul(self.k, br) | ||
|
||
tl_final = tl_dst / tl_dst[2] | ||
br_final = br_dst / br_dst[2] | ||
|
||
return tl_final + br_final |
This file contains 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,41 @@ | ||
# Helpful resource: https://de.mathworks.com/help/vision/ug/camera-calibration.html | ||
|
||
[PV_CAM_1280x720] | ||
ImageHeight=720 | ||
ImageWidth=1280 | ||
FrameRate=30 | ||
# focal length | ||
fx=986.7971 | ||
fy=986.1311 | ||
# principal point | ||
cx=628.5365 | ||
cy=338.7137 | ||
# radial distortion | ||
k1=0 | ||
k2=0 | ||
k3=0 | ||
# tangential distortion | ||
p1=0 | ||
p2=0 | ||
# skew coefficient | ||
s=0 | ||
|
||
[PV_CAM_760x428] | ||
ImageHeight=428 | ||
ImageWidth=760 | ||
FrameRate=30 | ||
# focal length | ||
fx=589.9811 | ||
fy=589.1793 | ||
# principal point | ||
cx=314.2682 | ||
cy=169.3568 | ||
# radial distortion | ||
k1=0 | ||
k2=0 | ||
k3=0 | ||
# tangential distortion | ||
p1=0 | ||
p2=0 | ||
# skew coefficient | ||
s=0 |
This file contains 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,35 @@ | ||
# Helpful resource: https://de.mathworks.com/help/vision/ug/camera-calibration.html | ||
|
||
[LEFT_CAM_HD] | ||
# focal length | ||
fx=699.25 | ||
fy=699.31 | ||
# principal point | ||
cx=671.745 | ||
cy=368.2635 | ||
# radial distortion | ||
k1=-0.174627 | ||
k2=0.0277376 | ||
k3=9.87232e-11 | ||
# tangential distortion | ||
p1=0.000100253 | ||
p2=7.86794e-05 | ||
# skew coefficient | ||
s=0 | ||
|
||
[RIGHT_CAM_HD] | ||
# focal length | ||
fx=699.73 | ||
fy=699.865 | ||
# principal point | ||
cx=643.675 | ||
cy=366.9085 | ||
# radial distortion | ||
k1=-0.173558 | ||
k2=0.0269429 | ||
k3=3.36205e-11 | ||
# tangential distortion | ||
p1=-4.90694e-05 | ||
p2=-0.000155324 | ||
# skew coefficient | ||
s=0 |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.k_dst_k_src_inv = ...