├── Distance Estimation ├── 4. calib_data │ └── MultiMatrix.npz ├── 1. generate_markers │ ├── markers │ │ ├── marker_0.png │ │ ├── marker_1.png │ │ ├── marker_10.png │ │ ├── marker_11.png │ │ ├── marker_12.png │ │ ├── marker_13.png │ │ ├── marker_14.png │ │ ├── marker_15.png │ │ ├── marker_16.png │ │ ├── marker_17.png │ │ ├── marker_18.png │ │ ├── marker_19.png │ │ ├── marker_2.png │ │ ├── marker_3.png │ │ ├── marker_4.png │ │ ├── marker_5.png │ │ ├── marker_6.png │ │ ├── marker_7.png │ │ ├── marker_8.png │ │ └── marker_9.png │ └── main.py ├── 3.1 camera_calibration │ ├── images │ │ ├── image0.png │ │ ├── image1.png │ │ ├── image10.png │ │ ├── image11.png │ │ ├── image12.png │ │ ├── image13.png │ │ ├── image14.png │ │ ├── image15.png │ │ ├── image16.png │ │ ├── image17.png │ │ ├── image18.png │ │ ├── image19.png │ │ ├── image2.png │ │ ├── image3.png │ │ ├── image4.png │ │ ├── image5.png │ │ ├── image6.png │ │ ├── image7.png │ │ ├── image8.png │ │ └── image9.png │ ├── capture_images.py │ └── calibration_script.py ├── 3.2 chessboard_image │ └── calibration pattern.png ├── 2. marker_detection │ └── main.py └── 5. distance_check │ └── check.py └── README.md /Distance Estimation/4. calib_data/MultiMatrix.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/4. calib_data/MultiMatrix.npz -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_0.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_1.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_10.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_11.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_12.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_13.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_14.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_15.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_16.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_17.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_18.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_19.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_2.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_3.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_4.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_5.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_6.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_7.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_8.png -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/markers/marker_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/1. generate_markers/markers/marker_9.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image0.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image1.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image10.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image11.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image12.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image13.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image14.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image15.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image16.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image17.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image18.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image19.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image2.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image3.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image4.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image5.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image6.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image7.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image8.png -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/images/image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.1 camera_calibration/images/image9.png -------------------------------------------------------------------------------- /Distance Estimation/3.2 chessboard_image/calibration pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SiliconJelly/OpenCV/HEAD/Distance Estimation/3.2 chessboard_image/calibration pattern.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenCV 2 | Projects including object detection and tracking, data augmentation, facial recognition, image segmentation and many weird and funny ones could be found here. Also, some projects are for Mongol-Tori, BRAC University Rover's AI and Autonomous Navigation Team. 3 | -------------------------------------------------------------------------------- /Distance Estimation/1. generate_markers/main.py: -------------------------------------------------------------------------------- 1 | import cv2 as cv 2 | from cv2 import aruco 3 | 4 | # dictionary to specify type of the marker 5 | marker_dict = aruco.getPredefinedDictionary(aruco.DICT_5X5_250) 6 | 7 | # MARKER_ID = 0 8 | MARKER_SIZE = 400 # pixels 9 | 10 | # generating unique IDs using for loop 11 | for id in range(20): # genereting 20 markers 12 | # using funtion to draw a marker 13 | marker_image = aruco.generateImageMarker(marker_dict, id, MARKER_SIZE) 14 | cv.imshow("img", marker_image) 15 | cv.imwrite(f"markers/marker_{id}.png", marker_image) 16 | # cv.waitKey(0) 17 | # break 18 | -------------------------------------------------------------------------------- /Distance Estimation/2. marker_detection/main.py: -------------------------------------------------------------------------------- 1 | import cv2 as cv 2 | from cv2 import aruco 3 | import numpy as np 4 | 5 | # dictionary to specify type of the marker 6 | marker_dict = aruco.getPredefinedDictionary(aruco.DICT_5X5_250) 7 | 8 | # detect the marker 9 | param_markers = aruco.DetectorParameters() 10 | 11 | # utilizes default camera/webcam driver 12 | cap = cv.VideoCapture(0) 13 | 14 | # iterate through multiple frames, in a live video feed 15 | while True: 16 | ret, frame = cap.read() 17 | if not ret: 18 | break 19 | # turning the frame to grayscale-only (for efficiency) 20 | gray_frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) 21 | marker_corners, marker_IDs, reject = aruco.detectMarkers( 22 | gray_frame, marker_dict, parameters=param_markers 23 | ) 24 | # getting conrners of markers 25 | if marker_corners: 26 | for ids, corners in zip(marker_IDs, marker_corners): 27 | cv.polylines( 28 | frame, [corners.astype(np.int32)], True, (0, 255, 255), 4, cv.LINE_AA 29 | ) 30 | corners = corners.reshape(4, 2) 31 | corners = corners.astype(int) 32 | top_right = corners[0].ravel() 33 | top_left = corners[1].ravel() 34 | bottom_right = corners[2].ravel() 35 | bottom_left = corners[3].ravel() 36 | cv.putText( 37 | frame, 38 | f"id: {ids[0]}", 39 | top_right, 40 | cv.FONT_HERSHEY_PLAIN, 41 | 1.3, 42 | (200, 100, 0), 43 | 2, 44 | cv.LINE_AA, 45 | ) 46 | # print(ids, " ", corners) 47 | cv.imshow("frame", frame) 48 | key = cv.waitKey(1) 49 | if key == ord("q"): 50 | break 51 | cap.release() 52 | cv.destroyAllWindows() 53 | -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/capture_images.py: -------------------------------------------------------------------------------- 1 | import cv2 as cv 2 | import os 3 | 4 | Chess_Board_Dimensions = (9, 6) 5 | 6 | n = 0 # image counter 7 | 8 | # checks images dir is exist or not 9 | image_path = "images" 10 | 11 | Dir_Check = os.path.isdir(image_path) 12 | 13 | if not Dir_Check: # if directory does not exist, a new one is created 14 | os.makedirs(image_path) 15 | print(f'"{image_path}" Directory is created') 16 | else: 17 | print(f'"{image_path}" Directory already exists.') 18 | 19 | criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001) 20 | 21 | 22 | def detect_checker_board(image, grayImage, criteria, boardDimension): 23 | ret, corners = cv.findChessboardCorners(grayImage, boardDimension) 24 | if ret == True: 25 | corners1 = cv.cornerSubPix(grayImage, corners, (3, 3), (-1, -1), criteria) 26 | image = cv.drawChessboardCorners(image, boardDimension, corners1, ret) 27 | 28 | return image, ret 29 | 30 | 31 | cap = cv.VideoCapture(0) 32 | 33 | while True: 34 | _, frame = cap.read() 35 | copyFrame = frame.copy() 36 | gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) 37 | 38 | image, board_detected = detect_checker_board( 39 | frame, gray, criteria, Chess_Board_Dimensions 40 | ) 41 | # print(ret) 42 | cv.putText( 43 | frame, 44 | f"saved_img : {n}", 45 | (30, 40), 46 | cv.FONT_HERSHEY_PLAIN, 47 | 1.4, 48 | (0, 255, 0), 49 | 2, 50 | cv.LINE_AA, 51 | ) 52 | 53 | cv.imshow("frame", frame) 54 | # copyframe; without augmentation 55 | cv.imshow("copyFrame", copyFrame) 56 | 57 | key = cv.waitKey(1) 58 | 59 | if key == ord("q"): 60 | break 61 | if key == ord("s") and board_detected == True: 62 | # the checker board image gets stored 63 | cv.imwrite(f"{image_path}/image{n}.png", copyFrame) 64 | 65 | print(f"saved image number {n}") 66 | n += 1 # the image counter: incrementing 67 | cap.release() 68 | cv.destroyAllWindows() 69 | 70 | print("Total saved Images:", n) 71 | -------------------------------------------------------------------------------- /Distance Estimation/3.1 camera_calibration/calibration_script.py: -------------------------------------------------------------------------------- 1 | import cv2 as cv 2 | import os 3 | import numpy as np 4 | 5 | # Chess/checker board size, dimensions 6 | CHESS_BOARD_DIM = (9, 6) 7 | 8 | # The size of squares in the checker board design. 9 | SQUARE_SIZE = 22 # millimeters (change it according to printed size) 10 | 11 | # termination criteria 12 | criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001) 13 | 14 | 15 | calib_data_path = "../calib_data" 16 | CHECK_DIR = os.path.isdir(calib_data_path) 17 | 18 | 19 | # saving the image / camera calibration data 20 | 21 | if not CHECK_DIR: 22 | os.makedirs(calib_data_path) 23 | print(f'"{calib_data_path}" Directory is created') 24 | 25 | else: 26 | print(f'"{calib_data_path}" Directory already Exists.') 27 | 28 | # prepare object points, i.e. (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0) 29 | obj_3D = np.zeros((CHESS_BOARD_DIM[0] * CHESS_BOARD_DIM[1], 3), np.float32) 30 | 31 | obj_3D[:, :2] = np.mgrid[0 : CHESS_BOARD_DIM[0], 0 : CHESS_BOARD_DIM[1]].T.reshape( 32 | -1, 2 33 | ) 34 | obj_3D *= SQUARE_SIZE 35 | print(obj_3D) 36 | 37 | # Arrays to store object points and image points from all the given images. 38 | obj_points_3D = [] # 3d point in real world space 39 | img_points_2D = [] # 2d points in image plane 40 | 41 | # The images directory path 42 | image_dir_path = "images" 43 | 44 | files = os.listdir(image_dir_path) # list of names of all the files present 45 | for file in files: 46 | print(file) 47 | imagePath = os.path.join(image_dir_path, file) 48 | # print(imagePath) 49 | 50 | image = cv.imread(imagePath) 51 | grayScale = cv.cvtColor(image, cv.COLOR_BGR2GRAY) 52 | ret, corners = cv.findChessboardCorners(image, CHESS_BOARD_DIM, None) 53 | if ret == True: 54 | obj_points_3D.append(obj_3D) 55 | corners2 = cv.cornerSubPix(grayScale, corners, (3, 3), (-1, -1), criteria) 56 | img_points_2D.append(corners2) 57 | 58 | img = cv.drawChessboardCorners(image, CHESS_BOARD_DIM, corners2, ret) 59 | 60 | cv.destroyAllWindows() 61 | # h, w = image.shape[:2] 62 | ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera( 63 | obj_points_3D, img_points_2D, grayScale.shape[::-1], None, None 64 | ) 65 | print("calibrated") 66 | 67 | print("dumping the data into one files using numpy ") 68 | np.savez( 69 | f"{calib_data_path}/MultiMatrix", 70 | camMatrix=mtx, 71 | distCoef=dist, 72 | rVector=rvecs, 73 | tVector=tvecs, 74 | ) 75 | 76 | print("-------------------------------------------") 77 | 78 | print("loading data stored using numpy savez function\n \n \n") 79 | 80 | data = np.load(f"{calib_data_path}/MultiMatrix.npz") 81 | 82 | camMatrix = data["camMatrix"] 83 | distCof = data["distCoef"] 84 | rVector = data["rVector"] 85 | tVector = data["tVector"] 86 | 87 | print("loaded calibration data successfully") 88 | -------------------------------------------------------------------------------- /Distance Estimation/5. distance_check/check.py: -------------------------------------------------------------------------------- 1 | import cv2 as cv 2 | from cv2 import aruco 3 | import numpy as np 4 | 5 | # load in the calibration data 6 | calib_data_path = "../calib_data/MultiMatrix.npz" 7 | 8 | calib_data = np.load(calib_data_path) 9 | print(calib_data.files) 10 | 11 | cam_mat = calib_data["camMatrix"] 12 | dist_coef = calib_data["distCoef"] 13 | r_vectors = calib_data["rVector"] 14 | t_vectors = calib_data["tVector"] 15 | 16 | MARKER_SIZE = 6 # centimeters (measure your printed marker size) 17 | 18 | marker_dict = aruco.getPredefinedDictionary(aruco.DICT_5X5_250) 19 | 20 | param_markers = aruco.DetectorParameters() 21 | 22 | cap = cv.VideoCapture(0) 23 | 24 | while True: 25 | ret, frame = cap.read() 26 | if not ret: 27 | break 28 | gray_frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) 29 | marker_corners, marker_IDs, reject = aruco.detectMarkers( 30 | gray_frame, marker_dict, parameters=param_markers 31 | ) 32 | if marker_corners: 33 | rVec, tVec, _ = aruco.estimatePoseSingleMarkers( 34 | marker_corners, MARKER_SIZE, cam_mat, dist_coef 35 | ) 36 | total_markers = range(0, marker_IDs.size) 37 | for ids, corners, i in zip(marker_IDs, marker_corners, total_markers): 38 | cv.polylines( 39 | frame, [corners.astype(np.int32)], True, (0, 255, 255), 4, cv.LINE_AA 40 | ) 41 | corners = corners.reshape(4, 2) 42 | corners = corners.astype(int) 43 | top_right = corners[0].ravel() 44 | top_left = corners[1].ravel() 45 | bottom_right = corners[2].ravel() 46 | bottom_left = corners[3].ravel() 47 | 48 | # Calculating the distance 49 | distance = np.sqrt( 50 | tVec[i][0][2] ** 2 + tVec[i][0][0] ** 2 + tVec[i][0][1] ** 2 51 | ) 52 | # Draw the pose of the marker 53 | point = cv.drawFrameAxes(frame, cam_mat, dist_coef, rVec[i], tVec[i], 4, 4) 54 | cv.putText( 55 | frame, 56 | f"id: {ids[0]} Dist: {round(distance, 2)}", 57 | top_right, 58 | cv.FONT_HERSHEY_PLAIN, 59 | 1.3, 60 | (0, 0, 255), 61 | 2, 62 | cv.LINE_AA, 63 | ) 64 | cv.putText( 65 | frame, 66 | f"x:{round(tVec[i][0][0],1)} y: {round(tVec[i][0][1],1)} ", 67 | bottom_right, 68 | cv.FONT_HERSHEY_PLAIN, 69 | 1.0, 70 | (0, 0, 255), 71 | 2, 72 | cv.LINE_AA, 73 | ) 74 | # print(ids, " ", corners) 75 | cv.imshow("frame", frame) 76 | key = cv.waitKey(1) 77 | if key == ord("q"): 78 | break 79 | cap.release() 80 | cv.destroyAllWindows() 81 | --------------------------------------------------------------------------------