Search code examples
matlabimage-processingvideopolygonmatlab-cvst

how to draw a shape using projective2d and a polygon in a video converted into frames


Hi I am trying to extract frames from the camera and apply SURF detection in the frames acquired. The process works well except for I am not able to draw a shape or polygon around the detected object. In the estimate geometric transform I am able to get the projective2d tform. But when I am trying to draw a box polygon around the detected object i am not able to see any polygon or shape. Sometimes the polygon comes and disappears. Sometime the polygon is not accurate around the detected object.

The code for tform and polygon is as follows:

[tform, ~, ~,status] = ...
estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'projective');

%box Polygon
boxPolygon = [1, 1;...                           % top-left
     size(boxImage, 2), 1;...                 % top-right
     size(boxImage, 2), size(boxImage, 1);... % bottom-right
     1, size(boxImage, 1);...                 % bottom-left
     1, 1]; 
newBoxPolygon = transformPointsForward(tform, boxPolygon);

% Display the frame
imshow(data)
hold on;
      line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');
refreshdata;

Solution

  • If the polygon disappears or is inaccurate, that could be because you are not finding enough matches, or because your matches are incorrect. You may want to see if that is the case, and if so, try to tweak the parameters of the matchFeatures function.

    You can also use insertShape to draw the polygon directly into the image pixels. But again, that assumes that you have good feature matches, and that you have computed the correct transformation.