Skip to content

Instantly share code, notes, and snippets.

@EyalAr
Created October 23, 2012 18:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save EyalAr/3940636 to your computer and use it in GitHub Desktop.
Save EyalAr/3940636 to your computer and use it in GitHub Desktop.
Hello World in OpenCV
#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;
}
@eduardothomas
Copy link

eduardothomas commented Jul 24, 2018

Thanks, nice and simple Hello World!

@glebteterin
Copy link

In my case I had to add #include <opencv2/core/types_c.h> for cvPoint and cvScalar

@ananthchellappa
Copy link

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})

@alefdezsuarez
Copy link

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