applying homography to artoolkit marker

3 visualizaciones (últimos 30 días)
stefan gligorijevic
stefan gligorijevic el 6 de Mayo de 2023
The image of the ARToolKIT markers used for camera calibration is deformed due to the perspective transformation when using the perspective camera as can be seen in Figure 1a)
In order to eliminate image deformation, it is necessary to apply the Homography method through the following steps:
Perform segmentation of the image using the "global thresholding" method (global brightness threshold) with the aim of extracting markers A-B-C-D and calculating the coordinates of points A, B, C and D in the image (assume that the coordinate start of the image coordinate system is in the upper left corner)
Using the calculated coordinates of points A, B, C and D in the image, taking into account the following realistic dimensions of markers A-B-C-D:
length: 150 mm, width: 150 mm,
calculate the homography matrix H that describes the mapping of the marker from the real space to the image plane (x'=Hx; x-vector of the point on the real marker, x'-vector of the corresponding point on the image)
Using the calculated matrix H, remove the perspective deformation of the ARToolKIT marker (calculate the coordinates of the marker corners in the synthetic image that is "free" from the perspective deformation x''=H-1x')
My code:
img = imread('ARToolKIT marker.png');
gray_img = rgb2gray(img);
threshold_value = graythresh(gray_img);
bw = imbinarize(gray_img, threshold_value);
bw = logical(1-bw);
bw_filled = imfill(bw, 'holes');
bw_largest = bwareafilt(bw_filled, 1);
bw_double = im2double(bw_largest);
bw_filtered = imgaussfilt(bw_double, 2);
corners = detectHarrisFeatures(bw_filtered, 'MinQuality', 0.1);
midpoint = mean(corners.Location);
angles = atan2d(corners.Location(:,2)-midpoint(2), corners.Location(:,1)-midpoint(1));
[~, order] = sort(angles);
corners = corners(order,:);
A = corners(1,:);
B = corners(2,:);
C = corners(3,:);
D = corners(4,:);
img_corners = [A;B;C;D];
marker_width = 150; % in millimeters
marker_length = 150; % in millimeters
real_points = [-marker_width/2, -marker_length/2 ;
marker_width/2, -marker_length/2;
marker_width/2, marker_length/2;
-marker_width/2, marker_length/2];
image_points = double([A.Location; B.Location; C.Location; D.Location]);
tform = estimateGeometricTransform(image_points, real_points, 'projective');
Tinv=inv(tform.T);
transformedImage = imwarp(img, tform);
marker_corners = [A.Location(1), A.Location(2); B.Location(1), B.Location(2); C.Location(1), C.Location(2); D.Location(1), D.Location(2)];
marker_corners_homogeneous = [marker_corners, ones(4,1)];
marker_corners_transformed_homogeneous = marker_corners_homogeneous * Tinv;
marker_corners_transformed = marker_corners_transformed_homogeneous(:,1:2) ./ marker_corners_transformed_homogeneous(:,3);
figure;
subplot(1,2,1);
imshow(img);
title('Original Image');
hold on;
plot(image_points(:,1), image_points(:,2), 'r+', 'MarkerSize', 10, 'LineWidth', 2);
subplot(1,2,2);
imshow(transformedImage);
title('Transformed Image');
hold on;
plot(marker_corners_transformed(:,1), marker_corners_transformed(:,2), 'r+', 'MarkerSize', 10, 'LineWidth', 2);
Summary: i think that transformation looks good. But marker_corners, or should i say points of the marker on the transformed images have some different values, it could be to some error in my code.*note i trying to detect the corners using regionprops extrema, but the function couldnt recongize top left corner so i had to go with the harris function.
This is the resulting picture :

Respuestas (0)

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by