[OpenCV] Samples 01: Geometry - 几何图形
前言
基本的几何图形,标注功能。
commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <stdio.h>
#include <iostream>
using namespace cv; static void help()
{
printf("\nThis program demonstrates OpenCV drawing and text output functions.\n"
"Usage:\n"
" ./drawing\n");
} //Jeff --> Specific structure for colour.
static Scalar randomColor(RNG& rng)
{
int icolor = (unsigned)rng;
return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255);
} int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv, "{help h||}");
if (parser.has("help"))
{
help();
return 0;
} char wndname[] = "Drawing Demo";
const int NUMBER = 100;
const int DELAY = 5;
int lineType = LINE_AA; // change it to LINE_8 to see non-antialiased graphics
int i, width = 1000, height = 700;
int x1 = -width/2, x2 = width*3/2, y1 = -height/2, y2 = height*3/2; //Jeff --> one kind of random number generator with specific distribution.
RNG rng(0xFFFFFFFF); // (1) Show a black background picture.
Mat image = Mat::zeros(height, width, CV_8UC3);
imshow(wndname, image);
waitKey(DELAY); // (2) Draw several lines between points.
for (i = 0; i < NUMBER; i++)
{
Point pt1, pt2;
pt1.x = rng.uniform(x1, x2);
pt1.y = rng.uniform(y1, y2);
pt2.x = rng.uniform(x1, x2);
pt2.y = rng.uniform(y1, y2); line( image, pt1, pt2, randomColor(rng), rng.uniform(1,10), lineType ); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} // (3) Draw rectangle.
for (i = 0; i < NUMBER; i++)
{
//Jeff --> This are two diagonal corners.
Point pt1, pt2;
pt1.x = rng.uniform(x1, x2);
pt1.y = rng.uniform(y1, y2);
pt2.x = rng.uniform(x1, x2);
pt2.y = rng.uniform(y1, y2);
int thickness = rng.uniform(-3, 10); rectangle( image, pt1, pt2, randomColor(rng), MAX(thickness, -1), lineType ); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} // (4) Draw ellipse.
for (i = 0; i < NUMBER; i++)
{
Point center;
center.x = rng.uniform(x1, x2);
center.y = rng.uniform(y1, y2);
Size axes;
axes.width = rng.uniform(0, 200);
axes.height = rng.uniform(0, 200);
double angle = rng.uniform(0, 180); //Jeff --> set angle because this is not a complete circle.
ellipse( image, center, axes, angle, angle - 100, angle + 200,
randomColor(rng), rng.uniform(-1,9), lineType ); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} // (5) Draw polylines.
for (i = 0; i< NUMBER; i++)
{
Point pt[2][3];
pt[0][0].x = rng.uniform(x1, x2);
pt[0][0].y = rng.uniform(y1, y2);
pt[0][1].x = rng.uniform(x1, x2);
pt[0][1].y = rng.uniform(y1, y2);
pt[0][2].x = rng.uniform(x1, x2);
pt[0][2].y = rng.uniform(y1, y2); pt[1][0].x = rng.uniform(x1, x2);
pt[1][0].y = rng.uniform(y1, y2);
pt[1][1].x = rng.uniform(x1, x2);
pt[1][1].y = rng.uniform(y1, y2);
pt[1][2].x = rng.uniform(x1, x2);
pt[1][2].y = rng.uniform(y1, y2); const Point* ppt[2] = {pt[0], pt[1]};
int npt[] = {3, 3}; polylines(image, ppt, npt, 2, true, randomColor(rng), rng.uniform(1,10), lineType); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} // (6) Draw polylines with filled body.
for (i = 0; i< NUMBER; i++)
{
Point pt[2][3];
pt[0][0].x = rng.uniform(x1, x2);
pt[0][0].y = rng.uniform(y1, y2);
pt[0][1].x = rng.uniform(x1, x2);
pt[0][1].y = rng.uniform(y1, y2);
pt[0][2].x = rng.uniform(x1, x2);
pt[0][2].y = rng.uniform(y1, y2);
pt[1][0].x = rng.uniform(x1, x2);
pt[1][0].y = rng.uniform(y1, y2);
pt[1][1].x = rng.uniform(x1, x2);
pt[1][1].y = rng.uniform(y1, y2);
pt[1][2].x = rng.uniform(x1, x2);
pt[1][2].y = rng.uniform(y1, y2);
const Point* ppt[2] = {pt[0], pt[1]};
int npt[] = {3, 3}; fillPoly(image, ppt, npt, 2, randomColor(rng), lineType); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} // (7) Draw circle.
for (i = 0; i < NUMBER; i++)
{
Point center;
center.x = rng.uniform(x1, x2);
center.y = rng.uniform(y1, y2); circle(image, center, rng.uniform(0, 300), randomColor(rng),
rng.uniform(-1, 9), lineType); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} // (8) Draw Text.
for (i = 1; i < NUMBER; i++)
{
Point org;
org.x = rng.uniform(x1, x2);
org.y = rng.uniform(y1, y2); putText(image, "Testing text rendering", org, rng.uniform(0,8),
rng.uniform(0,100)*0.05+0.1, randomColor(rng), rng.uniform(1, 10), lineType); imshow(wndname, image);
if(waitKey(DELAY) >= 0)
return 0;
} Size textsize = getTextSize("OpenCV forever!", FONT_HERSHEY_COMPLEX, 3, 5, 0);
Point org((width - textsize.width)/2, (height - textsize.height)/2); // (9) Foreground picture disappears.
Mat image2;
for( i = 0; i < 255; i += 2 )
{
// Jeff --> step one, erase forecolor.
image2 = image - Scalar::all(i); // Jeff --> step two, show text.
putText(image2, "OpenCV forever!", org, FONT_HERSHEY_COMPLEX, 3,
Scalar(i, i, 255), 5, lineType); imshow(wndname, image2);
if(waitKey(DELAY) >= 0)
return 0;
} waitKey();
return 0;
} #ifdef _EiC
main(1,"drawing.c");
#endif
[OpenCV] Samples 01: Geometry - 几何图形的更多相关文章
- [OpenCV] Samples 01: drawing
基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #includ ...
- [OpenCV] Samples 16: Decompose and Analyse RGB channels
物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...
- [OpenCV] Samples 10: imagelist_creator
yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic re ...
- [OpenCV] Samples 06: [ML] logistic regression
logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...
- [OpenCV] Samples 06: logistic regression
logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...
- WPF 反射加载Geometry几何图形数据图标
相信大家在阅读WPF相关GitHub开源项目源码时都会看见一串串这种数据 这种Geometry数据就是几何图形数据 为什么要用Geometry数据做图标? 有一种做法是使用ttf字体文件代替,不过使用 ...
- [OpenCV] Samples 13: opencv_version
cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true whe ...
- [OpenCV] Samples 12: laplace
先模糊再laplace,也可以替换为sobel等. 变换效果后录成视频,挺好玩. #include "opencv2/videoio/videoio.hpp" #include & ...
- [OpenCV] Samples 05: convexhull
得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边. 对于 ...
随机推荐
- PHP——安装wampserver丢失MSVCR110.dll
win8系统 64位,在安装wampserver时显示计算机丢失MSVCR110.dll 1.首先是打开浏览器,在浏览器的地址栏里输入 http://www.microsoft.com/zh-CN ...
- error TRK0002: Microsoft Visual Studio 10.0\VC\bin\link.exe Access is denied.
When you compile project, visual studio 2010 prompts “…link.exe … Access is denied” This below is I ...
- linux 安装 vsftpd服务
yum install vsftpd 修改配置文件 vim /etc/vsftpd/ftpusers vim /etc/vsftpd/user_list 简单起见,注释掉两个配置文件中的所有用户.
- Spring Boot 上传文件 获取项目根路径 物理地址 resttemplate上传文件
springboot部署之后无法获取项目目录的问题: 之前看到网上有提问在开发一个springboot的项目时,在项目部署的时候遇到一个问题:就是我将项目导出为jar包,然后用java -jar 运行 ...
- TextView 设置部分文字颜色及点击事件SpannableString
设置TextView中一部分文字的颜色及点击事件. SpannableString gotoMsgListStr = new SpannableString("消息列表"); go ...
- Java RMI 的使用及原理
1.示例 三个角色:RMIService.RMIServer.RMIClient.(RMIServer向RMIService注册Stub.RMIService在RMIClient lookup时向其提 ...
- css实现三角形及应用示例
css实现三角形,网上讲了很多,但我发现一般都是三角向上或者向下的,向左向右这两方向似乎讲得很少,本人试了一下,发现原来在IE下很难搞~~(万恶的IE)...css实现三角形的原理是:当元素的宽高为0 ...
- jQuery AJAX中文乱码处理
最近工作中用jQuery ajax返回出现乱码,用的Notepad++编辑器,当JS部分传递中文时,另一页面接收的话会出现乱码,在网上找了很多方法,基本上没有很好的解决. 页面用GB2312编码,JS ...
- SAP的战略企业管理功能介绍
目 录 1. 总述 2. SAP SEM- 战略管理 3. SAP SEM- 绩效测评 4. SAP SEM- 业务合并 5. ...
- (笔记)Linux下怎么安装tar.gz的软件
一般这种的就是源代码.先下载下来.然后cd到下载目录.用tar xvfz XXX.tar.gz的解压.然后进入解压后的目录. 打./configure生成配置文件.打make对源代码进行编译,生成库和 ...