用opencv画虚线框矩形
2016-04-08 15:50
281 查看
#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*totallength; start.y=tl_y+h; end.x=tl_x+(i+1)*totallength-dashlength;//draw bottom dash line end.y=tl_y+h; cvLine(img,start,end,color,thickness); } for (int i=0;i<nCountY;i++) { start.x=tl_x; start.y=tl_y+i*totallength; end.y=tl_y+(i+1)*totallength-dashlength;//draw left dash line end.x=tl_x; cvLine(img,start,end,color,thickness); } for (int i=0;i<nCountY;i++) { start.x=tl_x+w; start.y=tl_y+i*totallength; end.y=tl_y+(i+1)*totallength-dashlength;//draw right dash line end.x=tl_x+w; cvLine(img,start,end,color,thickness); } } int main(int argc, char* argv[]) { IplImage *img = cvLoadImage( "F:\\chen\\车辆跟踪对比图\\blurcar4 0024.jpg"); CvRect rect1 = cvRect(100,200,200,100); drawDashRect(img,1,2,&rect1,CV_RGB(255,255,255),1); cvShowImage("1",img); cvWaitKey(0); return 0; }
做对比实验时,经常用到虚线框,但是opencv中没有找到直接函数,所以就在网上看见大神写的,借过来用,怕以后忘记,所以现在记下来
相关文章推荐
- 分享到:空间等各大网站 代码
- linux源码entry_32.S中interrupt数组的分析
- shell查看进程
- centos7 mysql授权远程链接
- Linux通过防火墙禁止IP来防止攻击
- Linux 进程创建
- Opencv2.4.9源码分析——HoughCircles
- linux 命令前后台切换
- ECShop安装问题
- 读取配置文件的方式user.properties
- centos 7安装mysql数据库
- linux 光标快捷键
- php源码,php网站源码,php源码下载
- error LNK1104: 无法打开文件“OPENNI2_LIB.obj”
- docker中部署openstack的验证
- (总结)Nginx配置文件nginx.conf中文详解
- Centos上源码安装Hadoop2.7.2
- OpenCV学习:人脸识别 简单程序
- Apache下配置虚拟域名
- 【学习笔记】3D图形核心基础精炼版-3:屏幕中的三维坐标概念