suppress deprecation warning
This commit is contained in:
@@ -3,6 +3,7 @@ import numpy as np
|
|||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import argparse
|
import argparse
|
||||||
from aruco_types import ARUCO_DICT
|
from aruco_types import ARUCO_DICT
|
||||||
|
import math
|
||||||
|
|
||||||
ENTRY = {'charuco_corners': [], 'charuco_ids': [], 'obj_points': [], 'img_points': []}
|
ENTRY = {'charuco_corners': [], 'charuco_ids': [], 'obj_points': [], 'img_points': []}
|
||||||
CAM_CALIB_FILE = "results/cam_calib_charuco.npz"
|
CAM_CALIB_FILE = "results/cam_calib_charuco.npz"
|
||||||
@@ -41,6 +42,7 @@ def main():
|
|||||||
process_video(detector, board)
|
process_video(detector, board)
|
||||||
|
|
||||||
def process_video(detector: cv.aruco.CharucoDetector, board):
|
def process_video(detector: cv.aruco.CharucoDetector, board):
|
||||||
|
global ENTRY
|
||||||
mtx = None
|
mtx = None
|
||||||
dist = None
|
dist = None
|
||||||
rvecs = None
|
rvecs = None
|
||||||
@@ -71,6 +73,8 @@ def process_video(detector: cv.aruco.CharucoDetector, board):
|
|||||||
img_size = store_frame(detector, board, img)
|
img_size = store_frame(detector, board, img)
|
||||||
elif k == ord('c'):
|
elif k == ord('c'):
|
||||||
mtx, dist, _, _ = calibrate_camera(img_size, mtx, dist, None, None)
|
mtx, dist, _, _ = calibrate_camera(img_size, mtx, dist, None, None)
|
||||||
|
elif k == ord('x'):
|
||||||
|
ENTRY = {'charuco_corners': [], 'charuco_ids': [], 'obj_points': [], 'img_points': []}
|
||||||
else:
|
else:
|
||||||
process(detector, board, img, mtx, dist, rvecs, tvecs)
|
process(detector, board, img, mtx, dist, rvecs, tvecs)
|
||||||
|
|
||||||
@@ -99,11 +103,10 @@ def store_frame(detector: cv.aruco.CharucoDetector, board: cv.aruco.Board, img):
|
|||||||
return img_size
|
return img_size
|
||||||
|
|
||||||
def calibrate_camera(img_size, mtx, dist, rvecs=None, tvecs=None):
|
def calibrate_camera(img_size, mtx, dist, rvecs=None, tvecs=None):
|
||||||
global ENTRY
|
|
||||||
if len(ENTRY['obj_points']) > 0 and len(ENTRY['img_points']) > 0:
|
if len(ENTRY['obj_points']) > 0 and len(ENTRY['img_points']) > 0:
|
||||||
ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(ENTRY['obj_points'], ENTRY['img_points'], img_size, mtx, dist, rvecs=rvecs, tvecs=tvecs)
|
flags = cv.CALIB_USE_INTRINSIC_GUESS
|
||||||
|
ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(ENTRY['obj_points'], ENTRY['img_points'], img_size, mtx, dist, rvecs=rvecs, tvecs=tvecs, flags=flags)
|
||||||
np.savez(f"{CAM_CALIB_FILE}", mtx=mtx, dist=dist, rvecs=rvecs, tvecs=tvecs)
|
np.savez(f"{CAM_CALIB_FILE}", mtx=mtx, dist=dist, rvecs=rvecs, tvecs=tvecs)
|
||||||
ENTRY = {'charuco_corners': [], 'charuco_ids': [], 'obj_points': [], 'img_points': []}
|
|
||||||
print(f"Camera calibration finished. Result = {ret}")
|
print(f"Camera calibration finished. Result = {ret}")
|
||||||
return mtx, dist, rvecs, tvecs
|
return mtx, dist, rvecs, tvecs
|
||||||
|
|
||||||
@@ -123,6 +126,8 @@ def process(detector: cv.aruco.CharucoDetector, board: cv.aruco.Board, img, mtx,
|
|||||||
obj_points, img_points = board.matchImagePoints(charuco_corners, charuco_ids)
|
obj_points, img_points = board.matchImagePoints(charuco_corners, charuco_ids)
|
||||||
if mtx is not None and dist is not None:
|
if mtx is not None and dist is not None:
|
||||||
pose, rvec, tvec = cv.solvePnP(obj_points, img_points, mtx, dist, rvec=rvecs, tvec=tvecs)
|
pose, rvec, tvec = cv.solvePnP(obj_points, img_points, mtx, dist, rvec=rvecs, tvec=tvecs)
|
||||||
|
rot = [float(180/math.pi*v) for v in rvec[:,0]]
|
||||||
|
print(f"Rotation X|Y|Z: {rot[0]:.1f} | {rot[1]:.1f} | {rot[2]:.1f}")
|
||||||
if pose:
|
if pose:
|
||||||
# Draw Axis
|
# Draw Axis
|
||||||
cv.drawFrameAxes(img, mtx, dist, rvec, tvec, 10)
|
cv.drawFrameAxes(img, mtx, dist, rvec, tvec, 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user