LoginSignup
1
2

More than 5 years have passed since last update.

OpenCVその5円描画

Posted at

Opencv
http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html

cmake
http://www.wakayama-u.ac.jp/~chen/cmake/cmakecv.html

参考:http://opencv.jp/cookbook/opencv_drawing.html
少々、追加、変更しています。
名前空間cv使用宣言
ウィンドウサイズ
円の中心座標、線の色

そのままですが前提.
gcc,OpenCV,CMakeインストール済み。

ステップ
1.MyCircle.cpp
2.CMake file CMakeLists.txt
3.cmake make
4.Run

Using OpenCV with gcc and CMake
Note We assume that you have successfully installed OpenCV in your workstation.
The easiest way of using OpenCV in your code is to use CMake. A few advantages (taken from the Wiki):
No need to change anything when porting between Linux and Windows
Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK )
If you are not familiar with CMake, checkout the tutorial on its website.
Steps

Create a program using OpenCV
Let’s use a simple program such as DisplayImage.cpp shown below.

MyCircle.cpp
//MyCircle.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int
main(int argc, char *argv[])
{
  Mat img = Mat::zeros(600, 900, CV_8UC3);

  // Green
  // 画像,円の中心座標,半径,色,線太さ,種類
  circle(img, Point(500, 200), 200, Scalar(0,200,0), 3, 4);
  // White
  circle(img, Point(300, 250), 120, Scalar(200,200,200), 1, 8);
  // Blue
  circle(img, Point(300, 400), 80, Scalar(100,0,0), -1, CV_AA);

  namedWindow("MyCircle", CV_WINDOW_AUTOSIZE|CV_WINDOW_FREERATIO);
  imshow("MyCircle", img);
  waitKey(0);
}
//

Create a CMake file
Now you have to create your CMakeLists.txt file. It should look like this:

CMakeLists.txt
cmake_minimum_required (VERSION 2.6)

project( MyCircle )
find_package( OpenCV REQUIRED )
add_executable( MyCircle MyCircle.cpp ) 
target_link_libraries( MyCircle ${OpenCV_LIBS} )

Generate the executable
This part is easy, just proceed as with any other project using CMake:

cd <MyCircle_directory>
cmake .
make

Run
./MyCircle

Result
kobito.1419002700.551510.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2