mercoledì 14 giugno 2023

Aruco calibration file format

 Ho provato a vedere se effettuare la calibrazione di tag Aruco con immagini in formato raw lossless od in formato jpg (lossy) poteva influenzare l'errore finale




Per fare cio' ho preso un telefono Android che permette di salvare la stessa immagine in formato DNG ed in formato JPG 

Lo script di calcolo e' il seguente

import numpy as np
import cv2
import cv2.aruco as aruco

# Aruco parameters
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)
aruco_params = aruco.DetectorParameters_create()

# Chessboard parameters
num_chessboard_corners_horizontal = 9
num_chessboard_corners_vertical = 6
chessboard_square_size = 0.025  # in meters

# Image directory and file extension
image_directory = 'path_to_images_directory/'
image_extension = '.jpg'

# Arrays to store object points and image points
obj_points = []  # 3D points in real-world coordinates
img_points = []  # 2D points in image plane

# Generate chessboard object points
chessboard_size = (num_chessboard_corners_horizontal,
num_chessboard_corners_vertical)
objp = np.zeros((num_chessboard_corners_horizontal *
num_chessboard_corners_vertical, 3), np.float32)
objp[:, :2] = np.mgrid[0:num_chessboard_corners_horizontal,
0:num_chessboard_corners_vertical].T.reshape(-1, 2)
objp = objp * chessboard_square_size

# Iterate through images and find chessboard corners
image_count = 0
while True:
    # Load image
    image_path = image_directory + str(image_count) + image_extension
    image = cv2.imread(image_path)
    if image is None:
        break

    # Convert to grayscale
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Find chessboard corners
    ret, corners = cv2.findChessboardCorners(gray, chessboard_size, None)

    # If corners found, add object points and image points
    if ret == True:
        obj_points.append(objp)
        img_points.append(corners)

        # Draw and display corners
        cv2.drawChessboardCorners(image, chessboard_size, corners, ret)
        cv2.imshow('Chessboard Corners', image)
        cv2.waitKey(500)

    image_count += 1

cv2.destroyAllWindows()

# Perform Aruco calibration
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_points,
img_points, gray.shape[::-1], None, None)

# Calculate reprojection error
mean_error = 0
for i in range(len(obj_points)):
    img_points_proj, _ = cv2.projectPoints(obj_points[i], rvecs[i],
tvecs[i], mtx, dist)
    error = cv2.norm(img_points[i], img_points_proj, cv2.NORM_L2) /
len(img_points_proj)
    mean_error += error

calibration_error = mean_error / len(obj_points)
print("Calibration error: {}".format(calibration_error))

# Estimate additional error
reproj_error = 0
total_points = 0
for i in range(len(obj_points)):
    img_points_proj, _ = cv2.projectPoints(obj_points[i], rvecs[i],
tvecs[i], mtx, dist)
    error = cv2.norm(img_points[i], img_points_proj, cv2.NORM_L2)
    reproj_error += error
    total_points += len(obj_points[i])

additional_error = reproj_error / total_points
print("Additional error: {}".format(additional_error))

I risultati sono i seguenti (per i file DNG ho usato la libreria rawpy)

JPG

python calibration.py --dir ./jpg/ --square_size 0.015  -w 9 -t 6
Calibration error: 0.13602731796497697
Additional error: 0.13602731796497697

DNG

Calibration error: 0.13606447706803765

Additional error: 0.13606447706803765

In conclusione non si ha una significativa differenza di errore nell'usare JPG o DNG

Nessun commento:

Posta un commento

Debugger integrato ESP32S3

Aggiornamento In realta' il Jtag USB funziona anche sui moduli cinesi Il problema risiede  nell'ID USB della porta Jtag. Nel modulo...