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. HW4.4

    public class Solution { public static void main(String[] args) { final double KILOMETERS_PER_MILE = ...

  2. A Tour of Go Basic types

    Go's basic types are bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr ...

  3. iOS 检测网络状态

    一般有两种方式,都是第三方的框架,轮子嘛,能用就先用着,后面再优化. 一:Reachability 1.首先在AppDelegate.h添加头文件"Reachability.h", ...

  4. JavaWeb文件的上传与下载(1)

    经常用到的上传: 头像上传,资料分享等 文件上传的步骤 1.指定表单类型为文件上传表单 enctype="multipart/form-data" 2.表单提交方式必须为:post ...

  5. RSS实例文档

    <?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0&quo ...

  6. [C#]工具类—FTP上传下载

    public class FtpHelper { /// <summary> /// ftp方式上传 /// </summary> public static int Uplo ...

  7. Eclipse开发PHP环境配置

    首先准备好软件: 1. Apache,到这里找个最新版本 2. PHP,到这里下载 3. Eclipse IDE for Java EE Developers,到这里下载 4. DLTK Core F ...

  8. C语言中怎么求动态数组大小

    先来个简单的样例 int a[] = {1,2,3}; int arr_len = 0; arr_len = sizeof(a)/sizeof(int); 解释:sizeof() keyword是求出 ...

  9. Linux环境进程间通信

    http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.html http://bbs.chinaunix.net/forum.ph ...

  10. dubbo与spring mvc

    安装 一.本地服务     1.定义服务接口: (该接口需单独打包,在服务提供方和消费方共享) public interface CustomerService { public String get ...