From bb0631a365bd09cda1045c5f4a5bac3ff6ef0f9c Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 16 Apr 2015 17:33:38 +0300 Subject: [PATCH] Add sample cmake project --- samples/cpp/example_cmake/CMakeLists.txt | 28 +++++++++++++ samples/cpp/example_cmake/example.cpp | 50 ++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 samples/cpp/example_cmake/CMakeLists.txt create mode 100644 samples/cpp/example_cmake/example.cpp diff --git a/samples/cpp/example_cmake/CMakeLists.txt b/samples/cpp/example_cmake/CMakeLists.txt new file mode 100644 index 0000000000..fe7e629812 --- /dev/null +++ b/samples/cpp/example_cmake/CMakeLists.txt @@ -0,0 +1,28 @@ +# cmake needs this line +cmake_minimum_required(VERSION 2.8) + +# Define project name +project(opencv_example_project) + +# Find OpenCV, you may need to set OpenCV_DIR variable +# to the absolute path to the directory containing OpenCVConfig.cmake file +# via the command line or GUI +find_package(OpenCV REQUIRED) + +# If the package has been found, several variables will +# be set, you can find the full list with descriptions +# in the OpenCVConfig.cmake file. +# Print some message showing some of them +message(STATUS "OpenCV library status:") +message(STATUS " version: ${OpenCV_VERSION}") +message(STATUS " libraries: ${OpenCV_LIBS}") +message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") + +# Add OpenCV headers location to your include paths +include_directories(${OpenCV_INCLUDE_DIRS}) + +# Declare the executable target built from your sources +add_executable(opencv_example example.cpp) + +# Link your application with OpenCV libraries +target_link_libraries(opencv_example ${OpenCV_LIBS}) diff --git a/samples/cpp/example_cmake/example.cpp b/samples/cpp/example_cmake/example.cpp new file mode 100644 index 0000000000..cac5050b2d --- /dev/null +++ b/samples/cpp/example_cmake/example.cpp @@ -0,0 +1,50 @@ +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/videoio.hpp" +#include + +using namespace cv; +using namespace std; + +void drawText(Mat & image); + +int main() +{ + cout << "Built with OpenCV " << CV_VERSION << endl; + Mat image; + VideoCapture capture; + capture.open(0); + if(capture.isOpened()) + { + cout << "Capture is opened" << endl; + for(;;) + { + capture >> image; + if(image.empty()) + break; + drawText(image); + imshow("Sample", image); + if(waitKey(10) >= 0) + break; + } + } + else + { + cout << "No capture" << endl; + image = Mat::zeros(480, 640, CV_8UC1); + drawText(image); + imshow("Sample", image); + waitKey(0); + } + return 0; +} + +void drawText(Mat & image) +{ + putText(image, "Hello OpenCV", + Point(20, 50), + FONT_HERSHEY_COMPLEX, 1, // font face and scale + Scalar(255, 255, 255), // white + 1, LINE_AA); // line thickness and type +}