Add OpenCV Test
This commit is contained in:
parent
dd2656a9ff
commit
7b98a06db9
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(OpenCV_test VERSION 1.0.0)
|
||||
|
||||
#Find the opencv package
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
#include directories for opencv
|
||||
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||
|
||||
add_executable(OpenCV_test main.cpp)
|
||||
|
||||
#Add command to generate .gitignore
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
|
||||
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
|
||||
|
||||
#Add OpenCV Libraries
|
||||
target_link_libraries(OpenCV_test ${OpenCV_LIBS})
|
|
@ -0,0 +1,31 @@
|
|||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc,char ** argv){
|
||||
//If no image file name, throw a error
|
||||
if(argc != 2){
|
||||
std::cout<<"Usage:OpenCV_test <filename>"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout<<argv[1]<<std::endl;
|
||||
|
||||
//Create a new image
|
||||
Mat image;
|
||||
image = imread(argv[1],1);
|
||||
|
||||
//Check if image loaded
|
||||
if(!image.data){
|
||||
std::cout<<"No Image data"<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Create a window to show image
|
||||
namedWindow(argv[1],WINDOW_NORMAL);
|
||||
imshow(argv[1],image);
|
||||
|
||||
waitKey(0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue