آزمایش درستی نصب با اجرای برنامه خودتان
برنامه اول - تست عکس
فایل CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(first)
FIND_PACKAGE(OpenCV REQUIRED core highgui)
add_executable(first main.cpp)
TARGET_LINK_LIBRARIES(first ${OpenCV_LIBS})
فایل main.cpp
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
Mat im;
int main(int argc, char **argv)
{
if (argc!=2)
{
cout << "\nYou must enter an image.\n\n";
return -1;
}
im = imread(argv[1], CV_LOAD_IMAGE_COLOR);
namedWindow("First Program");
imshow("First Program", im);
cout << "Press 'q' to quit.\n\n";
while(1)
{
if(waitKey(1) == 'q') break;
}
destroyAllWindows();
return 0;
}
نحوه کامپایل و اجرا
mkdir build
cd build
cmake ..
make
./first ~/Pictures/test.jpg
برنامه دوم - تست ویدئو
فایل CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(second)
FIND_PACKAGE(OpenCV REQUIRED core highgui)
add_executable(second main.cpp)
TARGET_LINK_LIBRARIES(second ${OpenCV_LIBS})
فایل main.cpp
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char **argv)
{
if (argc!=2)
{
cout << "\nYou must enter a video.\n\n";
return -1;
}
VideoCapture cap(argv[1]); // Create a VideoCapture object to read from video file
if(!cap.isOpened()) //check if the file was opened
{
cout << "\nCapture could not open this video\n\n";
return -1;
}
Mat frame;
namedWindow("Second Program");
while(cap.isOpened())
{
cap >> frame;
if(frame.empty()) // Check if the video is over
{
cout << "\nEnd!\n\n";
break;
}
imshow("Second Program", frame);
waitKey(100);
}
cout << "Press a key to quit.\n\n";
waitKey(0);
destroyAllWindows();
return 0;
}
نحوه کامپایل و اجرا
mkdir build
cd build
cmake ..
make
./scond ~/Videos/test.avi