insertObjectKeypoints
Description
specifies one or more name-value arguments, in addition to any combination of input
arguments from the previous syntax, to configure the keypoints to be inserted in the image.
For example, RGB
= insertObjectKeypoints(___,Name=Value
)KeypointSize=3
inserts keypoints with the size of
3
pixels in the image.
Examples
Insert Object Keypoints and Connections
This example uses:
- Computer Vision ToolboxComputer Vision Toolbox
- Computer Vision Toolbox Model for Object Keypoint DetectionComputer Vision Toolbox Model for Object Keypoint Detection
- Computer Vision Toolbox Model for YOLO v4 Object DetectionComputer Vision Toolbox Model for YOLO v4 Object Detection
Read an input image
I = imread("visionteam.jpg");
Run the detect
method of YOLOv4 object detector to detect bounding boxes around persons in the image. Here, persons are considered as objects.
detector = yolov4ObjectDetector("csp-darknet53-coco"); [bboxes,scores,labels] = detect(detector,I,Threshold=0.4); personIndices = labels=="person"; personBoxes = bboxes(personIndices,:);
Run the detect
method of a pretrained HRNet object keypoint detector to detect keypoints of every person in the image.
keypointDetector = hrnetObjectKeypointDetector; [keypoints,keypointScores,valid] = detect(keypointDetector,I,personBoxes);
Create an object skeleton from keypoint connections. Each row in the skeleton corresponds to categorical keypoint class indices of a keypoint connection.
objectSkeleton = keypointDetector.KeypointConnections
objectSkeleton = 17×2
2 4
2 1
3 5
3 1
1 6
1 7
6 8
8 10
7 9
9 11
⋮
Insert the keypoints and skeleton on the respective person and display results.
detectedKeypoints = insertObjectKeypoints(I,keypoints,KeypointColor="yellow",KeypointSize=2,... Connections=objectSkeleton,ConnectionColor="c",LineWidth=1); imshow(detectedKeypoints);
Insert Object Keypoints with Label Annotations
Read an input image.
I = imread("visionPeople.jpg");
Specify a bounding box to detect the persons in the image.
bboxes = uint8([1.39,19.30,122.39,341.61;131.78,27.06,108.36,324.50]);
Detect keypoints of the person by using the detect
method of pretrained HRNet object keypoint detector.
keypointDetector = hrnetObjectKeypointDetector("human-full-body-w32");
[keypoints,keypointScores,valid] = detect(keypointDetector,I,bboxes);
Read categorical class labels of keypoints from the keypoint detector object.
labels = keypointDetector.KeyPointClasses
labels = 17x1 categorical
Nose
Left-eye
Right-eye
Left-ear
Right-ear
Left-shoulder
Right-shoulder
Left-elbow
Right-elbow
Left-wrist
Right-wrist
Left-hip
Right-hip
Left-knee
Right-knee
Left-ankle
Right-ankle
Insert and display detected keypoints along with the labels in the image.
detectedKeypoints = insertObjectKeypoints(I,keypoints,KeypointColor="yellow",KeypointSize=2,keypointLabel=labels,... TextBoxColor="white",TextBoxOpacity=0.8,FontSize=8); imshow(detectedKeypoints);
Input Arguments
I
— Input image
matrix | array
Input image, specified as an X-by-Y matrix for a grayscale image, or an X-by-Y-by-3 array for a RGB color image.
Data Types: single
| double
| int16
| uint8
| uint16
keypoints
— Object keypoints
array
Object keypoints, specified as an M-by-2-by-P array for P objects in the image. M is the number of keypoints corresponding to each object in the input image I. Each row of the M-by-2 matrix is a keypoint location in the format [x y].
Data Types: double
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: insertObjectKeypoints(__,KeypointColor=[255 0 0])
inserts all
the keypoints in red color.
Connections
— Keypoint indices of keypoint connections
[]
(default) | matrix
Keypoint indices of keypoint connections specified as an L-by-2 matrix. L is the number of keypoint connections in an object. Each row in the matrix has two indices of connected keypoints. These two keypoints are connected by a line segment.
Data Types: double
KeypointVisibility
— Keypoint visibility value
true
(default) | M-by-P matrix
Keypoint visibility value, specified as an M-by-P logical matrix. M is the number of keypoints in an object. P is the total number of objects in the image.
Keypoints with the keypoint visibility value set to
true
or1
in the matrix are inserted in the image.Keypoints with the keypoint visibility value set to
false
or0
in the matrix are not inserted in the image.
By default, all keypoints have a keypoint visibility value set to
true
or 1
.
Data Types: logical
KeypointColor
— Keypoint color
[0.850 0.325 0.098]
(default) | character vector | cell array of character vectors | string scalar | string array | M-by-3 matrix
Keypoint color, specified as a character vector, cell array of character vectors, M- element vector, or M-by-3 matrix of RGB values.
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color.
You can specify a different color for each keypoint or one color for all
keypoints. To specify one color for all keypoints, set
KeypointColor
to a color string or an [R
G
B] vector.
Specification | Format | Example |
---|---|---|
One color for all keypoints | String or character color name |
|
1-by-3 vector (RGB triplet) |
| |
Different color for each keypoint | M-element vector |
|
M-by-3 matrix, as a list of RGB values | [1 0 0 0 1 1 1 0 1] |
Supported colors are listed in the table.
Color Name | Short Name | RGB Triplet | Appearance |
---|---|---|---|
"red" | "r" | [1 0 0] | |
"green" | "g" | [0 1 0] | |
"blue" | "b" | [0 0 1] | |
"cyan" | "c" | [0 1 1] | |
"magenta" | "m" | [1 0 1] | |
"yellow" | "y" | [1 1 0] | |
"black" | "k" | [0 0 0] | |
"white" | "w" | [1 1 1] |
Data Types: logical
| uint8
| uint16
| int16
| double
| single
KeypointLabel
— Keypoint labels
[]
(default) | M-element vector
Keypoint labels, specified as an M-element categorical vector. M is the number of keypoints in an object.
Data Types: categorical
KeypointSize
— Keypoint size
2
(default) | positive integer
Keypoint size, specified as a positive integer in pixels.
Data Types: categorical
Opacity
— Opacity of keypoints and connections
1
(default) | scalar in the range [0
1
]
Opacity of keypoints and connections, specified as a scalar value in the range [0
1]. The value 1
makes the keypoints and connections completely
opaque and the value 0
makes them completely transparent.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
ConnectionColor
— Color of line segment connecting keypoints
[0 0.447 0.741]
(default) | character vector | cell array of character vectors | string scalar | string array | M-by-3 matrix
Color of line segment connecting keypoints, specified as a character vector, cell array of character vectors, M- element vector, or M-by-3 matrix of RGB values.
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color.
You can specify a different color for each keypoint connection or one color for
all connections. To specify one color for all keypoint connections, set
ConnectionColor
to a color string or an [R
G
B] vector.
For a description of RGB color and how to specify it, see
KeypointColor
.
Data Types: logical
| uint8
| uint16
| int16
| double
| single
LineWidth
— Line width of keypoint connection
2
(default) | positive integer
Line width of keypoint connection, specified as a positive integer. The unit is pixels.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
TextBoxColor
— Text box color of keypoint label
"yellow"
(default) | character vector | cell array of character vectors | string scalar | string array | M-by-3 matrix
Text box color of keypoint label, specified as a character vector, cell array of character vectors, M- element vector, or M-by-3 matrix of RGB values. M is the number of keypoints in an object.
An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color.
You can specify a different color for each text box or one color for all text
boxes. To specify one color for all text boxes, set TextBoxColor
to a color string or an [R
G
B] vector.
For a description of RGB color and how to specify it, see
KeypointColor
.
Data Types: logical
| uint8
| uint16
| int16
| double
| single
TextBoxOpacity
— Text box background opacity of keypoint label
0.6 (default) | scalar in the range [0
1
]
Text box background opacity of keypoint label, specified as a scalar. Specify the
opacity value in the range [0
1
].
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
FontColor
— Font color of keypoint label
"black"
(default) | character vector | cell array of character vectors | string scalar | string array | M-by-3 matrix
Font color of keypoint label, specified as a character vector, cell array of character vectors, vector, or M-by-3 matrix of RGB values. M is the number of keypoints in an object.
You can specify a different font color for each keypoint label or one font color
for all keypoint labels. To specify one color for all keypoint labels, set
FontColor
to a color string or an [R
G
B] vector. For a description of RGB color and how to specify it,
see KeypointColor
.
Data Types: logical
| uint8
| uint16
| int16
| double
| single
Font
— Font face of text
"LucidaSansRegular"
(default) | character vector | string scalar
Font face of text, specified as a character vector. The font face must be one of
the available truetype fonts installed on your system. To get a list of available
fonts on your system, type listTrueTypeFonts
at the MATLAB® command prompt.
Data Types: char
| string
FontSize
— Font size of keypoint label text
12 (default) | integer in the range [8
72
]
Font size of keypoint label text, specified as an integer that corresponds to
points in the range [8 72
].
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Output Arguments
RGB
— Output image
truecolor image
Output image, returned as a RGB color image of same datatype as the input image,
with the same X-by-Y-by-3 dimensions as
I
.
Limitations
Value to the LineWidth
, TextBoxColor
,
TextBoxOpacity
, Font
,
FontColor
, FontSize
arguments should be specified
only when the KeypointLabel
argument is non-empty.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Font
,FontSize
,KeypointColor
andKeypointConnections
name-value arguments must be compile-time constants.Non-ASCII characters are not supported.
Version History
Introduced in R2023b
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)