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

Calibration rvc3 #1060

Merged
merged 66 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
186abae
Added WIP Image Align for visualization
saching13 Aug 9, 2022
5113b6b
Working calibration with SYnc
saching13 Aug 10, 2022
fcc4f4c
added board config files
saching13 Aug 10, 2022
e52e734
Updated the ar0234 res
saching13 Aug 15, 2022
562d331
Updated mono in json
saching13 Aug 15, 2022
d9105b1
Added Output Scale factor and removed the orientation check
saching13 Aug 15, 2022
48cdb67
Fixed the osf
saching13 Aug 15, 2022
f177b01
Fixed capture issue with different names
saching13 Aug 15, 2022
507ede9
updated links translation
saching13 Aug 16, 2022
46f8b1f
WIP structure and vertical Stereo calibration
saching13 Aug 17, 2022
03766f3
Fixed flashing issues
saching13 Aug 19, 2022
84dd899
updatec req condfitions
saching13 Aug 22, 2022
16f6e28
added exception msg
saching13 Aug 22, 2022
7b81117
removed try catch and writing board names
saching13 Aug 22, 2022
1b356df
adding rect data
saching13 Aug 22, 2022
64d5828
Updated rectification flash
saching13 Aug 22, 2022
c9bc18e
Removed comments
saching13 Aug 24, 2022
38e6102
Added rotation to polygons
saching13 Sep 8, 2022
861f9e3
Polygon flex (#789)
saching13 Sep 12, 2022
00acebb
Modified the board file
saching13 Sep 14, 2022
63b5adb
added debugs
saching13 Sep 15, 2022
7372329
tweaked intrinsics in use
saching13 Sep 17, 2022
085b4a6
iterative method added but commented
saching13 Sep 17, 2022
6d3964a
cleanedup image sizes and better ep errors
saching13 Sep 30, 2022
1067cb2
Fixed config error
saching13 Oct 13, 2022
c452188
Tweaked replay
saching13 Dec 13, 2022
029aff0
Added optional rect from projection matrix
saching13 Dec 20, 2022
6f186a6
updated depthai version
saching13 Feb 20, 2023
9deb126
Add `-ab/--antibanding {50|60|off}` option. Implement `-fps` option
alex-luxonis Feb 20, 2023
691f680
Peripheral calibration - fisheye camera model (#952)
njezersek Feb 22, 2023
abc566e
Fix fiheye calibration rotated rectified image
njezersek Feb 23, 2023
d1054c5
new lines from corner to corners
saching13 Mar 3, 2023
9db8704
update calibration handler with cameraModel
saching13 Mar 23, 2023
4d9e428
WIP vermeer
Mar 24, 2023
3be4d44
Fix fisheye calibration
njezersek Mar 28, 2023
023db9c
Merge remote-tracking branch 'origin/peripheral_calibration' into per…
Mar 28, 2023
e0ae7d7
Fixes for RVC3
Apr 11, 2023
9645a5e
Add mouse trigger, save calibration, custom dataset options
Apr 18, 2023
185c2f7
Update depthai version
Apr 18, 2023
5f7e746
Add options for dataset custom path
Apr 19, 2023
6d74171
Add an option to manually specify the number of charucos
Apr 19, 2023
cfff50f
Fixed default dataset path
njezersek Apr 26, 2023
ed1a21d
Support for GRAY8 img type, fix scaling issues
njezersek May 3, 2023
316526a
Lower the threshold for synced frames
May 12, 2023
3a33796
Remove the CALIB_CHECK_COND
May 15, 2023
bc9f90d
Cleared old opencv dependencies versioning
saching13 May 17, 2023
53445f2
Peripheral calibration rvc3 (#1040)
saching13 May 27, 2023
e4e7bea
fixed the requirements.txt
saching13 May 29, 2023
8601c51
saving converge files
saching13 May 31, 2023
d5da79f
modified calibration parameters
saching13 Jun 14, 2023
469d6df
added json for no vertical testing
saching13 Jun 14, 2023
d7af1ad
Changes
MaticTonin Jun 22, 2023
4c04197
Adding_display_option
MaticTonin Jun 22, 2023
3bc52a9
Adding_display_option
MaticTonin Jun 22, 2023
33296e4
Changes
MaticTonin Jun 23, 2023
0a45d47
Merge branch 'main' into calibration_rvc3
MaticTonin Jun 23, 2023
7487107
Change
MaticTonin Jun 23, 2023
33f692c
Resolving_issues
MaticTonin Jun 23, 2023
57d02f0
Resolving_issues
MaticTonin Jun 23, 2023
7aaada4
Fix issues
MaticTonin Jun 23, 2023
328e4d1
Change in scaling matrix
MaticTonin Jun 26, 2023
aeaa9f5
Changes of matrix
MaticTonin Jul 3, 2023
d2553c7
Adding traceLevel as argument
MaticTonin Jul 13, 2023
ec6a6f0
Fix traceLevel
MaticTonin Jul 14, 2023
29b8f10
updated the argument.
saching13 Jul 18, 2023
8ca6176
Updated with main
saching13 Jul 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ share/python-wheels/
MANIFEST
*.idea
# DepthAI-Specific
dataset/
dataset*
*dataset*
.fw_cache/
depthai.calib
mesh_left.calib
Expand Down
41 changes: 41 additions & 0 deletions DepthCamera_2023-06-27-14-50-40.json
saching13 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"class_name" : "PinholeCameraParameters",
"extrinsic" :
[
0.999995500003375,
0.0,
-0.0029999955000020251,
0.0,
0.0,
-1.0,
-0.0,
0.0,
-0.0029999955000020251,
-0.0,
-0.999995500003375,
0.0,
-0.46858788711658533,
0.46999999999999997,
1.756589582102694,
1.0
],
"intrinsic" :
{
"height" : 1080,
"intrinsic_matrix" :
[
935.30743608719376,
0.0,
0.0,
0.0,
935.30743608719376,
0.0,
959.5,
539.5,
1.0
],
"width" : 1920
},
"version_major" : 1,
"version_minor" : 0
}
Binary file added DepthCapture_2023-06-27-14-50-40.png
saching13 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,126 changes: 502 additions & 624 deletions calibrate.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions depthai-boards
Submodule depthai-boards added at 4ca262
731 changes: 575 additions & 156 deletions depthai_helpers/calibration_utils.py

Large diffs are not rendered by default.

Submodule depthai_pipeline_graph added at dd1c2a
7 changes: 3 additions & 4 deletions install_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
if sys.version_info[0] != 3:
raise RuntimeError("Demo script requires Python 3 to run (detected: Python {})".format(sys.version_info[0]))

prebuilt_wheels_python_version = [7, 9]
is_pi = this_platform.startswith("arm")
prebuiltWheelsPythonVersion = [7,9]
if is_pi and sys.version_info[1] not in prebuiltWheelsPythonVersion:

# Pi is a common platform using these instruction sets
is_pi = this_platform == 'armv6l' or this_platform == 'armv7l'
if is_pi and sys.version_info[1] not in prebuilt_wheels_python_version:
print("[WARNING] There are no prebuilt wheels for Python 3.{} for OpenCV, building process on this device may be long and unstable".format(sys.version_info[1]))

if not in_venv:
Expand Down
76 changes: 76 additions & 0 deletions reproject_error_fisheye.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import glob
import cv2
import numpy as np
import cv2.aruco as aruco
import depthai as dai
from pathlib import Path

def detect_markers_corners(frame):
marker_corners, ids, rejectedImgPoints = cv2.aruco.detectMarkers(frame, aruco_dictionary)
marker_corners, ids, refusd, recoverd = cv2.aruco.refineDetectedMarkers(frame, charuco_board,
marker_corners, ids,
rejectedCorners=rejectedImgPoints)
if len(marker_corners) <= 0:
return marker_corners, ids, None, None
ret, charuco_corners, charuco_ids = cv2.aruco.interpolateCornersCharuco(marker_corners, ids, frame, charuco_board)
return marker_corners, ids, charuco_corners, charuco_ids

size = (1920, 1200)

# Load the images
calibration_handler = dai.CalibrationHandler('./resources/1844301021621CF500_05_26_23_16_31.json')
images = glob.glob('./dataset_cam7_may_18_merged/left/*.png')

# Prepare for camera calibration
k = np.array(calibration_handler.getCameraIntrinsics(calibration_handler.getStereoLeftCameraId(), size[0], size[1]))
D_left = np.array(calibration_handler.getDistortionCoefficients(calibration_handler.getStereoLeftCameraId()))
d = np.array(calibration_handler.getDistortionCoefficients(calibration_handler.getStereoLeftCameraId()))
r = np.eye(3, dtype=np.float32)

d_zero = np.zeros((14, 1), dtype=np.float32)
M_focal = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(k, d, size, np.eye(3), fov_scale=1.1)
mapXL, mapYL = cv2.fisheye.initUndistortRectifyMap(k, d[:4], r, M_focal, size, cv2.CV_32FC1)

aruco_dictionary = aruco.Dictionary_get(cv2.aruco.DICT_4X4_1000)
charuco_board = aruco.CharucoBoard_create(
11,
8,
6.0,
4.6,
aruco_dictionary)
checkCorners3D = charuco_board.chessboardCorners
rvec = np.array([[0.0],
[0.0],
[0.0]], dtype=np.float32)

tvec = np.array([[0.0],
[0.0],
[0.0]], dtype=np.float32)
# count = 0
for im_name in images:
## Undistort it first
path = Path(im_name)
img = cv2.imread(im_name)
img_rect = cv2.remap(img , mapXL, mapYL, cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)

marker_corners, ids, charuco_corners, charuco_ids = detect_markers_corners(img_rect)
ret, rvec, tvec = aruco.estimatePoseCharucoBoard(charuco_corners, charuco_ids, charuco_board, M_focal, d_zero, rvec, tvec)

""" if len(charuco_ids) != len(checkCorners3D):
print('charuco_ids shape -> ', charuco_ids.shape)
print('charuco_corners shape -> ', charuco_corners.shape)
print('checkCorners3D shape -> ', checkCorners3D.shape)
raise ValueError("Number of ids does not match number of original corners") """

points_2d, _ = cv2.fisheye.projectPoints(checkCorners3D[None], rvec, tvec, k, d)
undistorted_points_2d = cv2.fisheye.undistortPoints(points_2d, k, d, R = r, P = M_focal)
# print("undistorted_points_2d shape -> ", undistorted_points_2d.shape)
# print("charuco_corners shape -> ", charuco_corners.shape)
error = 0
for i in range(len(charuco_ids)):
error_vec = charuco_corners[i][0] - undistorted_points_2d[0][charuco_ids[i]]
error += np.linalg.norm(error_vec)
# print(im_name)
print(f'Reprojection error is {error / len(charuco_ids)} avg of {len(charuco_ids)} of points in file {path.name} ')


2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pyqt5>5,<5.15.6 ; platform_machine != "armv6l" and platform_machine != "armv7l"
--extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/
depthai==2.21.2.0
Qt.py
scipy
scipy
55 changes: 55 additions & 0 deletions resources/boards/veermer_no_rgb.json
saching13 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"board_config":
{
"name": "VERMEER",
"revision": "R0M0E0",
"cameras":{
"CAM_C": {
"name": "right",
"hfov": 71.86,
"type": "color",
"extrinsics": {
"to_cam": "CAM_B",
"specTranslation": {
"x": 10,
"y": 0,
"z": 0
},
"rotation":{
"r": 0,
"p": 0,
"y": 0
}
}
},
"CAM_B": {
"name": "left",
"hfov": 71.86,
"type": "color",
"extrinsics": {
"to_cam": "CAM_D",
"specTranslation": {
"x": 0,
"y": -4.0,
"z": 0
},
"rotation":{
"r": 0,
"p": 0,
"y": 0
}
}
},
"CAM_D": {
"name": "vertical",
"hfov": 71.86,
"type": "color"
}
},
"stereo_config":{
"left_cam": "CAM_B",
"right_cam": "CAM_C"
}
}
}