Add test1 for OpenCV

This commit is contained in:
daleclack 2022-07-14 20:15:07 +08:00
parent a393b3dbbc
commit 270d43226b
4 changed files with 46 additions and 31 deletions

View File

@ -1,31 +0,0 @@
#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;
}

View File

@ -0,0 +1,46 @@
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace cv;
int main(int argc,char ** argv){
std::fstream infile;
char filename[128];
infile.open("filename.txt",std::ios_base::in);
if(infile.is_open()){
infile.read(filename, sizeof(filename));
}
// //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, image2;
image = imread(filename, IMREAD_COLOR);
image2 = imread(filename, IMREAD_GRAYSCALE);
//Check if image loaded
if(!image.data){
std::cout<<"No Image data"<<std::endl;
return -1;
}
//Create a window to show image
namedWindow(filename,WINDOW_NORMAL);
imshow(filename,image);
namedWindow("Gray image", WINDOW_NORMAL);
imshow("Gray image",image2);
waitKey(0);
destroyAllWindows();
return 0;
}