Created
October 23, 2012 18:37
-
-
Save EyalAr/3940636 to your computer and use it in GitHub Desktop.
Hello World in OpenCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opencv2/opencv.hpp" | |
#include "opencv2/highgui/highgui.hpp" | |
using namespace cv; | |
int main(int argc, char** argv) { | |
//create a gui window: | |
namedWindow("Output",1); | |
//initialize a 120X350 matrix of black pixels: | |
Mat output = Mat::zeros( 120, 350, CV_8UC3 ); | |
//write text on the matrix: | |
putText(output, | |
"Hello World :)", | |
cvPoint(15,70), | |
FONT_HERSHEY_PLAIN, | |
3, | |
cvScalar(0,255,0), | |
4); | |
//display the image: | |
imshow("Output", output); | |
//wait for the user to press any key: | |
waitKey(0); | |
return 0; | |
} |
In my case I had to add #include <opencv2/core/types_c.h>
for cvPoint and cvScalar
Really needs to be accompanied by an appropriate CMakeLists.txt .. I think..
cmake_minimum_required(VERSION 3.15)
project(hellow)
set(CMAKE_CXX_STANDARD 17)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(hello hello.cpp)
target_link_libraries(hello ${OpenCV_LIBS})
Another option without having to include #include <opencv2/core/types_c.h>
is to modify cvPoint
for cv::Point
or just Point
as follows:
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(int argc, char** argv) {
//create a gui window:
namedWindow("Output",1);
//initialize a 120X350 matrix of black pixels:
Mat output = Mat::zeros( 120, 350, CV_8UC3 );
//write text on the matrix:
putText(output,
"Hello World :)",
Point(15,70),
FONT_HERSHEY_PLAIN,
3,
Scalar(0,255,0),
4);
//display the image:
imshow("Output", output);
//wait for the user to press any key:
waitKey(0);
return 0;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, nice and simple Hello World!