keyPointsToStruct
Description
Examples
This example shows how to use the prebuilt MATLAB interface for the OpenCV function cv::Fast in MATLAB to detect keypoints in an image. Additionally, use the keyPointsToStruct utility function to write the keypoints returned by the OpenCV cv::Fast function to a MATLAB structure.
Add the MATLAB interface to OpenCV package names to the import list.
import clib.opencv.*; import vision.opencv.util.*;
Read an image into the MATLAB workspace.
img = imread("elephant.jpg");Create MATLAB interface objects for the OpenCV MatND and InputArray classes to store the input image.
[inputMat,inputArray] = createMat(img);
Create a MATLAB interface object for the OpenCV KeyPoint vector by using the clibArray function.
keyPointsVec = clibArray("clib.opencv.cv.KeyPoint",0);Specify the parameters for computing keypoints using the FAST detector.
threshold = 100; nonmaxSuppression = true;
Compute keypoints in the image by calling the OpenCV function cv::FAST in MATLAB.
cv.FAST(inputArray,keyPointsVec,threshold,nonmaxSuppression);
Convert the KeyPoints object returned by the OpenCV function into a MATLAB structure.
mlstruct = keyPointsToStruct(keyPointsVec);
Inspect the fields in the output MATLAB structure.
mlstruct
mlstruct = struct with fields:
Location: [48×2 double]
Scale: [48×1 double]
Metric: [48×1 double]
Misc: [48×1 double]
Orientation: [48×1 double]
Display the input image and plot the detected keypoints.
figure imshow(img) hold on plot(mlstruct.Location(:,1),mlstruct.Location(:,2),"*r") hold off

Input Arguments
OpenCV KeyPoints class, specified as a MATLAB interface object. This interface object is a representation of the
KeyPoints class returned by any of the OpenCV functions for
keypoint detection.
Output Arguments
Keypoints detected using the OpenCV function, returned as a MATLAB structure with fields Location,
Scale, Metric, Misc, and
Orientation.
| Fields | Description |
Location | x and y-coordinates of the keypoints. |
Scale | Diameter of the neighborhood region around the keypoints. |
Metric | Strength of the keypoints. |
Orientation | Orientation of the keypoints. |
Version History
Introduced in R2021b
See Also
rectToBbox | getImage | getBasePtr | createUMat | createMat | clibArray
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)