Using OpenCV from C++
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