开始学习
< 返回

第一个 OpenCV 程序

示例代码

helloworld.cpp(GitHub

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/types_c.h>

using namespace cv;

int main(int argc, char** argv) {

    //create a gui window:
    namedWindow("GetIoT",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("GetIoT", output);

    //wait for the user to press any key:
    waitKey(0);

    return 0;
}

运行效果

编译

g++ -I /usr/include/opencv4 helloworld.cpp -o hello_opencv -lopencv_core -lopencv_highgui -lopencv_imgproc

运行

./hello_opencv

将显示如下窗口:

第一个 OpenCV 程序

Was this article helpful?
5 out of 5 stars

2 ratings

5 Stars 100%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
Please Share Your Feedback
How Can We Improve This Article?
文章目录