Using OpenCV from C++

From wiki.ferrari.mo.it
Revision as of 14:12, 19 July 2018 by Admin (talk | contribs) (Created page with " == Using OpenCV from C++ == Install libopencv-dev apt-get install libopencv-dev = Capture a frame from USB Camera = Create the file DisplayImage.cpp #include "opencv2/...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Using OpenCV from C++[edit]

Install libopencv-dev

apt-get install libopencv-dev

Capture a frame from USB Camera[edit]

Create the file DisplayImage.cpp

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    cap.set(CV_CAP_PROP_FRAME_WIDTH,1280);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT,1024);

    Mat frame;
    cap >> frame; // get a new frame from camera
    // do any processing
    imwrite("/tmp/image.png", frame);
    return 0;
}

Create the CMakeLists.txt file

cmake_minimum_required(VERSION 2.8)
project( CaptureImage )
find_package( OpenCV REQUIRED )
add_executable( CaptureImage CaptureImage.cpp )
target_link_libraries( CaptureImage ${OpenCV_LIBS} )

Compile

cmake .
make