当前位置:网站首页>Opencv 在图像上进行标注(画框+写字)
Opencv 在图像上进行标注(画框+写字)
2022-07-26 03:05:00 【璇焱如柳】
在做目标检测时,检测到目标后,通常要用矩形框框选出目标的位置,并在旁边附上标签
在opencv实现这一目标主要用到两个函数,rectangle()和putText()
函数原型:
void rectangle(Mat& img, Rect rec, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )
参数详解: Mat& img:图像数据
Rect rect:矩形框的位置。Rect是一个struct,有四个元素(x,y,heigth,width),分别是框左上角坐标,高度,宽度。
const Scalar& color:框线的颜色。
int thickness:框线宽度,线占像素个数。
int lineType:线型,默认直线。
int shift:没看懂,官方说默认就行。
const string& text:文本内容。
Point org:文本左下角坐标。Point为一个struct,有两个元素,是啥就不用我说了吧。
int fontFace:字体类型。
double fontScale:字体大小。
bool bottomLeftOrigin:如果为true,文本旋转180度。
看例子:
#include <iostream>
#include <libavutil/avutil.h>
#include <opencv2/highgui.hpp>
#include <opencv4/opencv2/imgproc.hpp>
/*在视频(图像)上添加标签,本质就是画个框,再写个文本*/
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("/home/lfh/图片/壁纸/琴女.png");
Rect rect;
rect.x = 300; //(x,y)表示左上角坐标
rect.y = 300;
rect.height = 100;
rect.width = 100;
Scalar color = CV_RGB(250,0,0); //红色
string text = "i'm text";
Point p; //文本框左下角坐标
p.x = rect.x;
p.y = rect.y - 5;
rectangle(image,rect,color,2);
putText(image,text,p, FONT_HERSHEY_SIMPLEX,0.6,color,1,8,0);
imshow("camera image",image);
waitKey(0);
}
结果:
边栏推荐
- [translation] announce Vites 13
- 26 points that must be paid attention to for stability test
- Neo4j import CSV data error: neo4j load CSV error: couldn't load the external resource
- [steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)
- 多线程编程
- Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
- 一切的源头,代码分支策略的选择
- 循环与分支(一)
- 如何根据登录测试的需求设计测试用例?
- Study notes of pytorch deep learning practice: convolutional neural network (Advanced)
猜你喜欢

Oxycon 2022 network capture frontier conference is about to open!
![[C Advanced] deeply explore the storage of data (in-depth analysis + interpretation of typical examples)](/img/1e/33f9cc9446dcad8cdb78babbb5a22c.jpg)
[C Advanced] deeply explore the storage of data (in-depth analysis + interpretation of typical examples)

How to effectively prevent others from wearing the homepage snapshot of the website
![[SQL] 自连接的用法](/img/92/92474343b4b4e6ea60453b4799cb55.jpg)
[SQL] 自连接的用法

如何正确计算 Kubernetes 容器 CPU 使用率

Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?

测试/开发程序员老了怎么办?挥之不去残酷的事实......

1. Software testing ----- the basic concept of software testing

从各大APP年度报告看用户画像——标签,比你更懂你自己

Shardingsphere data slicing
随机推荐
.net serialize enumeration as string
Swin Transformer【Backbone】
AMD64 (x86_64) architecture ABI document: medium
如何用U盘进行装机?
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 1)
[C language] deeply understand integer lifting and arithmetic conversion
Arthas download and startup
手把手教你依赖管理
AMD64 (x86_64) architecture ABI document:
Shardingsphere data slicing
VOFA+ 串口调试助手
MySQL build websites data table
织梦提示你设定了字段为联动类型如何解决
Opening method of win11 microphone permission
The difference between the world wide web, the Internet and the Internet
Vofa+ serial port debugging assistant
1.软件测试-----软件测试的基本概念
如何有效的去防止别人穿该网站首页快照
[SQL] 自连接的用法
QT signal transmission between multi-level objects signal transmission between multi-level nested class objects