Featured image of post 【OpenCV】c++ OpenCV - 在 ubuntu 上第一次執行 OpenCV 程式 sample code (內含範例程式碼)

【OpenCV】c++ OpenCV - 在 ubuntu 上第一次執行 OpenCV 程式 sample code (內含範例程式碼)

前言

此文為 C ++ 在 OpenCV 執行第一隻程式的方法範例

sample code

#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main(){
    // generate black image
    cv::Mat image = cv::Mat::zeros(cv::Size(640, 480), CV_8UC3);

    // show result
    cv::imshow("image", image);
    cv::waitKey(0);
    return 0;
}

C++ compile

g++ test.cpp -o test.out -std=c++11 `pkg-config --cflags --libs opencv` 
./test.out
  • test.cpp:為要編譯的程式碼
  • test.out:為編譯結果的 binary (執行也是用此執行檔執行)

執行結果

Reference

https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html
https://blog.gtwang.org/programming/ubuntu-linux-install-opencv-cpp-python-hello-world-tutorial/