前言


基本的几何图形,标注功能。

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: drawing的更多相关文章

  1. [OpenCV] Samples 01: Geometry - 几何图形

    前言 基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #inc ...

  2. [OpenCV] Samples 16: Decompose and Analyse RGB channels

    物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...

  3. [OpenCV] Samples 10: imagelist_creator

    yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic re ...

  4. [OpenCV] Samples 06: [ML] logistic regression

    logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...

  5. [OpenCV] Samples 06: logistic regression

    logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...

  6. [OpenCV] Samples 13: opencv_version

    cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true whe ...

  7. [OpenCV] Samples 12: laplace

    先模糊再laplace,也可以替换为sobel等. 变换效果后录成视频,挺好玩. #include "opencv2/videoio/videoio.hpp" #include & ...

  8. [OpenCV] Samples 05: convexhull

    得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边. 对于 ...

  9. [OpenCV] Samples 03: cout_mat

    操作Mat元素时:I.at<double>(1,1) = CV_PI; /* * * cvout_sample just demonstrates the serial out capab ...

随机推荐

  1. selenium总结篇,常见方法和页面元素的操作【转】

    原文:http://www.cnblogs.com/tobecrazy/p/4570494.html 今天,总结一下selenium怎么操作web页面常见的元素. 主要有: 上传 alter dial ...

  2. solr&lucene3.6.0源码解析(三)

    solr索引操作(包括新增 更新 删除 提交 合并等)相关UML图如下 从上面的类图我们可以发现,其中体现了工厂方法模式及责任链模式的运用 UpdateRequestProcessor相当于责任链模式 ...

  3. linux sort,uniq,cut,wc命令详解

    linux sort,uniq,cut,wc命令详解 sort sort 命令对 File 参数指定的文件中的行排序,并将结果写到标准输出.如果 File 参数指定多个文件,那么 sort 命令将这些 ...

  4. WCF服务配置问题

      上一篇中,我们主要是使用了代码来实现服务的自我寄宿.代码的实现稍微复杂些,不过还有些使用配置文件和配置工具的方法.下面来一一介绍下.     1.配置文件.首先在Host下添加个app.confi ...

  5. 多线程NSInvocationOperation(NSOperationQueue)的基本用法

        #import "ViewController.h" @interface ViewController () @end @implementation ViewContr ...

  6. http://blog.sina.com.cn/s/blog_4c3b6a070100etad.html

    http://blog.sina.com.cn/s/blog_4c3b6a070100etad.html

  7. 解剖SQLSERVER 第三篇 数据类型的实现(译)

    解剖SQLSERVER 第三篇  数据类型的实现(译) http://improve.dk/implementing-data-types-in-orcamdf/ 实现对SQLSERVER数据类型的解 ...

  8. 不用asp.net MVC,用WebForm照样可以实现MVC(请看最后一句话)

    在<避开WebForm天坑,拥抱ASP.Net MVC吧>这篇博客中我讲到了ASP.net WebForm由于一些先天的“诱导犯罪”的缺陷,现在用ASP.net MVC的公司越来越多.但是 ...

  9. Twitter全局唯一ID生成算法

    测试:private static void TestIdWorker() { HashSet<long> set = new HashSet<long>(); IdWorke ...

  10. 在windows上安装ASP.NET 5(译文)

    本文将介绍如何在windows上安装ASP.NET5,包括单独安装和通过Visual Studio 2015 安装. 本文包括: 通过Visual Studio安装ASP.NET 单独安装ASP.NE ...