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