#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void drawDashRect(CvArr* img,int linelength,int dashlength,CvRect* blob,CvScalar color,int thickness)
{
int w=cvRound(blob->width);//width
int h=cvRound(blob->height);//height
int tl_x=cvRound(blob->x);//top left x
int tl_y=cvRound(blob->y);//top left y
int totallength=dashlength+linelength;
int nCountX=w/totallength;//
int nCountY=h/totallength;//
CvPoint start,end;//start and end point of each dash
//draw the horizontal lines
start.y=tl_y;
start.x=tl_x;
end.x=tl_x;
end.y=tl_y;
for (int i=0;i<nCountX;i++)
{
end.x=tl_x+(i+1)*totallength-dashlength;//draw top dash line
end.y=tl_y;
start.x=tl_x+i*totallength;
start.y=tl_y;
cvLine(img,start,end,color,thickness);
}
for (int i=0;i<nCountX;i++)
{
start.x=tl_x+i
用opencv画虚线框矩形
最新推荐文章于 2024-08-01 20:28:27 发布
这篇博客介绍了如何在OpenCV中实现虚线矩形框的绘制,通过自定义函数`drawDashRect`利用直线`cvLine`进行间隔绘制,实现了虚线效果。在main函数中给出了具体应用实例,读取图片并显示带有虚线框的图像。
摘要由CSDN通过智能技术生成