2022-04-03 13:07:33 -06:00
|
|
|
#!/usr/bin/env python3
|
2020-03-26 20:19:47 -06:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
# copied from common.transformations/camera.py
|
2020-05-31 15:03:22 -06:00
|
|
|
eon_focal_length = 910.0 # pixels
|
|
|
|
eon_dcam_focal_length = 860.0 # pixels
|
2020-03-26 20:19:47 -06:00
|
|
|
|
2022-04-03 13:07:33 -06:00
|
|
|
webcam_focal_length = 914.014724315 # pixels
|
2020-03-26 20:19:47 -06:00
|
|
|
|
|
|
|
eon_intrinsics = np.array([
|
|
|
|
[eon_focal_length, 0., 1164/2.],
|
|
|
|
[ 0., eon_focal_length, 874/2.],
|
|
|
|
[ 0., 0., 1.]])
|
|
|
|
|
|
|
|
eon_dcam_intrinsics = np.array([
|
|
|
|
[eon_dcam_focal_length, 0, 1152/2.],
|
|
|
|
[ 0, eon_dcam_focal_length, 864/2.],
|
|
|
|
[ 0, 0, 1]])
|
|
|
|
|
|
|
|
webcam_intrinsics = np.array([
|
2022-04-03 13:07:33 -06:00
|
|
|
[webcam_focal_length, 0., 1280/2],
|
|
|
|
[ 0., webcam_focal_length, 800/2],
|
2020-03-26 20:19:47 -06:00
|
|
|
[ 0., 0., 1.]])
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-05-28 16:40:48 -06:00
|
|
|
import cv2 # pylint: disable=import-error
|
2020-05-31 13:37:52 -06:00
|
|
|
trans_webcam_to_eon_rear = np.dot(eon_intrinsics, np.linalg.inv(webcam_intrinsics))
|
|
|
|
trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))
|
2020-03-26 20:19:47 -06:00
|
|
|
print("trans_webcam_to_eon_rear:\n", trans_webcam_to_eon_rear)
|
|
|
|
print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)
|
|
|
|
|
2022-04-03 13:07:33 -06:00
|
|
|
cap = cv2.VideoCapture(0)
|
2020-03-27 12:43:30 -06:00
|
|
|
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)
|
|
|
|
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
2020-03-26 20:19:47 -06:00
|
|
|
|
|
|
|
while (True):
|
|
|
|
ret, img = cap.read()
|
|
|
|
if ret:
|
2022-04-03 13:07:33 -06:00
|
|
|
img = cv2.warpPerspective(img, trans_webcam_to_eon_rear, (1164,874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
|
|
|
|
# img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1164, 874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
|
2020-03-26 20:19:47 -06:00
|
|
|
cv2.imshow('preview', img)
|
|
|
|
cv2.waitKey(10)
|