DrawShapes.cxx

# include "DrawShapes_utils.h"

#define WINDOW_NAME1 "Painting 1"
#define WINDOW_NAME2 "Painting 2" // main
int main( void )
{
// crate Mat image
cv::Mat atomImage = cv::Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3);
cv::Mat rookImage = cv::Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); // draw image 1
// 1) draw ellipses
DrawEllipse( atomImage, );
DrawEllipse( atomImage, );
DrawEllipse( atomImage, );
DrawEllipse( atomImage, - ); // 2) draw circle
DrawFilledCircle(atomImage, cv::Point(WINDOW_WIDTH/, WINDOW_WIDTH/)); // draw image 2
// 1) draw polygon
DrawPolygon( rookImage ); // 2) draw rectangle
cv::rectangle(rookImage,
cv::Point(, *WINDOW_WIDTH/),
cv::Point(WINDOW_WIDTH, WINDOW_WIDTH),
cv::Scalar( , , ),
-,
);
// 3) draw line segments
DrawLine(rookImage, cv::Point(, *WINDOW_WIDTH/), cv::Point(WINDOW_WIDTH, *WINDOW_WIDTH/));
DrawLine(rookImage, cv::Point(WINDOW_WIDTH/, *WINDOW_WIDTH/), cv::Point(WINDOW_WIDTH/, WINDOW_WIDTH));
DrawLine(rookImage, cv::Point(WINDOW_WIDTH/, *WINDOW_WIDTH/), cv::Point(WINDOW_WIDTH/, WINDOW_WIDTH));
DrawLine(rookImage, cv::Point(*WINDOW_WIDTH/, *WINDOW_WIDTH/), cv::Point(*WINDOW_WIDTH/, WINDOW_WIDTH)); // show images
cv::imshow( WINDOW_NAME1, atomImage );
cv::moveWindow( WINDOW_NAME1, , );
cv::imshow( WINDOW_NAME2, rookImage );
cv::moveWindow( WINDOW_NAME2, WINDOW_WIDTH, ); cv::imwrite("atomImage.jpg", atomImage);
cv::imwrite("rookImage.jpg", rookImage); cv::waitKey(); return ;
}

DrawShapes_utils.h

#ifndef DRAWSHAPES_H_
#define DRAWSHAPES_H_ #include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#define WINDOW_WIDTH 600 // draw ellipse with the same size but different angle
void DrawEllipse( cv::Mat img, double angle ); // draw filled circle
void DrawFilledCircle( cv::Mat img, cv::Point center ); // draw polygon
void DrawPolygon( cv::Mat img ); // draw line
void DrawLine( cv::Mat img, cv::Point start, cv::Point end ); #endif // DRAWSHAPES_H_

DrawShapes_utils.cxx

#include "DrawShapes_utils.h"

// draw ellipse with the same size but different angle
void DrawEllipse( cv::Mat img, double angle )
{
int thickness = ;
int lineType = ; ellipse( img,
cv::Point( WINDOW_WIDTH/, WINDOW_WIDTH/ ), // center point
cv::Size(WINDOW_WIDTH/, WINDOW_WIDTH/), // bounding box
angle, // rotation angle
, // arc start from 0 degree
, // to 360 degrees
cv::Scalar(,,), // color of the ellipse
thickness, // line width
lineType); // line type: 8 neighbor connected line
} // draw filled circle
void DrawFilledCircle( cv::Mat img, cv::Point center )
{
int thickness = -;
int lineType = ; cv::circle( img,
center,
WINDOW_WIDTH/, // radius
cv::Scalar(, , ), // color
thickness, // line width: -1 filled
lineType); // line type
} // draw polygon
void DrawPolygon( cv::Mat img )
{
int lineType = ; // create points
cv::Point rookPoints[][];
rookPoints[][] = cv::Point( WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( WINDOW_WIDTH/, WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( *WINDOW_WIDTH/, *WINDOW_WIDTH/ );
rookPoints[][] = cv::Point( WINDOW_WIDTH/, *WINDOW_WIDTH/ ); const cv::Point* ppt[] = {rookPoints[]};
int npt[] = {}; cv::fillPoly( img,
ppt, // vertices
npt, // number of vertices
, // number of polygon to draw
cv::Scalar(, , ), //color of polygon
lineType);
} // draw line
void DrawLine( cv::Mat img, cv::Point start, cv::Point end )
{
int thickness = ;
int lineType = ;
cv::line( img,
start, // start point
end, // end point
cv::Scalar(, , ), // color of line
thickness, // line width
lineType); // line type
}

CMakeLists.txt

cmake_minimum_required (VERSION 2.8)
project (DrawShapes) # find OpenCV packages
find_package( OpenCV REQUIRED PATHS /usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/)
include_directories( ${OpenCV_INCLUDE_DIRS} ) # add the executable
add_executable (DrawShapes DrawShapes.cxx DrawShapes_utils.h DrawShapes_utils.cxx)
target_link_libraries(DrawShapes opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs)

atomImage

rookImage

实例:图形绘制[OpenCV 笔记15]的更多相关文章

  1. 图像显示 imshow()[OpenCV 笔记5]

    void imshow(const string& winname InputArray mat); winname 窗口表识名称 mat 需要显示的图像.InputArray类型,声明如下 ...

  2. 查找并绘制轮廓[OpenCV 笔记XX]

    好久没有更新了,原谅自己放了个假最近又在赶进度,所以...更新的内容是很靠后的第八章,因为最近工作要用就先跳了,后面会更新笔记编号...加油加油! 在二值图像中寻找轮廓 void cv::findCo ...

  3. 实例:图像载入、显示、混合与输出[OpenCV 笔记8]

    是的是的,忍着尿意努力更新,就是为了更到wuli男神的部分,当然要把男神放在前面镇楼,欢迎下载配图,具体操作见code wuliEddie.jpg logo.png results.jpg LoadS ...

  4. 视频处理简单实例 [OpenCV 笔记2]

    VideoCapture是OpenCV 2.X中新增的类,提供从摄像机或视频文件捕获视频的C++接口.利用它读入视频的方法一般有两种: // method 1 VideoCapture capture ...

  5. 图像处理简单实例[OpenCV 笔记1]

    几个入门的简单程序,和对应的CMakeList, 虽然简单重新测一下写一下也是好的. CMake教程传送门 图像显示 ShowImage.cxx #include <opencv2/opencv ...

  6. OpenCV基本架构[OpenCV 笔记0]

    最近正在系统学习OpenCV,将不定期发布笔记,主要按照毛星云的<OpenCV3编程入门>的顺序学习,会参考官方教程和文档.学习工具是Xcode+CMake,会对书中一部分内容更正,并加入 ...

  7. 滑动条 Trackbar[OpenCV 笔记9]

    OpenCV中没有实现按钮的功能,我们可以利用滑动条来实现按钮功能. , ); trackbarname 轨迹条的名字. winname 窗口的名字,轨迹条会依附在这个窗口上. value 一个指向整 ...

  8. 输出图像到文件 imwrite()[OpenCV 笔记7]

    bool imwrite(const string& filename, InputArray img, const vector<int>& params=vector& ...

  9. 访问图像中的像素[OpenCV 笔记16]

    再更一发好久没更过的OpenCV,不过其实写到这个部分对计算机视觉算法有所了解的应该可以做到用什么查什么了,所以后面可能会更的慢一点吧,既然开了新坑,还是机器学习更有研究价值吧... 图像在内存中的存 ...

随机推荐

  1. Robotium学习笔记三

    以下是从网络上抄录的一些Robotium注意事项 1)有些button没有string,没有text,只能通过index来click这样很不直观,而且button的index并不是固定的,有可能随着控 ...

  2. JS----JS调试技巧

    骨灰级调试大师Alert 那还是互联网刚刚起步的时代,网页前端还主要以内容展示为主,浏览器脚本还只能为页面提供非常简单的辅助功能的时候.那个时候,网页主要运行在以IE6为主的浏览器中,JS的调试功能还 ...

  3. PTA 5-12 排序 (25分)

    给定NN个(长整型范围内的)整数,要求输出从小到大排序后的结果. 本题旨在测试各种不同的排序算法在各种数据情况下的表现.各组测试数据特点如下: 数据1:只有1个元素: 数据2:11个不相同的整数,测试 ...

  4. ASP.NET用HttpListener实现文件断点续传

    本文转载:http://www.cnblogs.com/TianFang/archive/2007/01/03/610739.html 断点续传的原理很简单,就是在Http的请求和应答的报文头上和一般 ...

  5. 适合高级Java程序员看的12本书

    1.Thinking in Java 2.Head First Java 3.Java in a Nutshell 4.The elements of Java style 5.Effective J ...

  6. oracle数据库导入导出的dmp(转)

    window下: imp必须要dba用户,所以用sysdba用户登陆,然后给予chnlmgr用户dba权限 grant connect,resource,dba to chnlmgr; 全部导入 im ...

  7. 使用startCoroutine制定倒计时

    使用startCoroutine制定倒计时 using UnityEngine; using System.Collections; public class TimerCoroutine : Mon ...

  8. linux上安装memcached

    我的版本为Centos Release 5.3 (Final)使用这个命令可以知道你的Linux版本1.cat /etc/redhat-release首先要安装libevent库.cd /usr/lo ...

  9. Linux--------------安装vsftpd

    1.安装vsftpd        yum install -y vsftpd         yum -y install ftp vsftpd    2.安装vsftpd虚拟用户配置依赖包     ...

  10. Java基础知识强化之IO流笔记37:FileReader/FileWriter(转换流的子类)复制文本文件案例

    1. 转换流的简化写法: 由于我们常见的操作都是使用本地默认编码,所以,不用指定编码.而转换流的名称有点长,所以,Java就提供了其子类供我们使用:FileReader / FileWriterOut ...