- 操作系统:ubuntu22.04
- OpenCV版本:OpenCV4.9
- IDE:Visual Studio Code
- 编程语言:C++11
算法描述
cv::drawMarker 函数在 OpenCV 中用于在一个给定的位置上绘制标记。目前支持几种不同的标记类型,具体信息可以参考 MarkerTypes
函数原型
void cv::drawMarker
(InputOutputArray img,Point position,const Scalar & color,int markerType = MARKER_CROSS,int markerSize = 20,int thickness = 1,int line_type = 8
)
参数
- 参数img 图像.
- 参数position 十字准星所在的位置点
- 参数color 线条颜色
- 参数markerType 您想要使用的标记类型,参见 MarkerTypes
- 参数thickness 线条粗细
- 参数line_type 线条类型,参见 LineTypes
- 参数markerSize 标记轴的长度 [默认 = 20 像素]
代码示例
#include <iostream>
#include <opencv2/opencv.hpp>int main()
{// 创建一个空白图像cv::Mat image = cv::Mat::zeros( 500, 500, CV_8UC3 );// 设置标记参数cv::Point position( 40, 40 ); // 标记位置cv::Scalar color( 0, 0, 255 ); // 标记颜色(BGR格式)int markerType = cv::MARKER_CROSS; // 标记类型 十字形标记形状。int markerSize = 50; // 标记大小int thickness = 2; // 标记线条厚度int line_type = cv::LINE_8; // 线条类型// 绘制标记cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );// 45度倾斜的十字形标记形状markerType = cv::MARKER_TILTED_CROSS;position = cv::Point( 90, 90 );cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );//星形标记形状,是十字形和倾斜十字形的组合markerType = cv::MARKER_STAR;position = cv::Point( 150, 150 );cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );//菱形标记形状。markerType = cv::MARKER_DIAMOND;position = cv::Point( 210, 210 );cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );// 正方形标记形状。markerType = cv::MARKER_SQUARE;position = cv::Point( 270, 270 );cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );// 向上的三角形标记形状markerType = cv::MARKER_TRIANGLE_UP;position = cv::Point( 330, 330 );cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );//向下的三角形标记形状markerType = cv::MARKER_TRIANGLE_DOWN;position = cv::Point( 400, 400 );cv::drawMarker( image, position, color, markerType, markerSize, thickness, line_type );// 显示图像cv::imshow( "Marker Drawing", image );cv::waitKey( 0 );return 0;
}