opencv基本操作--读取并显示图片
程序员文章站
2022-03-01 21:44:33
...
开发环境:Opencv 2.4.10+ visual studio 2013
头文件主要是
#include<opencv2\opencv.hpp>
#include<opencv2\core\core.hpp>
opencv读取图片的操作是
string file = "xxx.jpg";
src = imread(file );
imread这个函数的定义是
Mat imread( const string& filename, int flags=1 );
然后opencv 显示图片的操作则是
imshow("123", src);
imshow这个函数的定义是
void imshow(const string& winname, InputArray mat);
下面是完整代码
#include<iostream>
#include<stdio.h>
#include<string>
#include<opencv2\opencv.hpp>
#include<opencv2\core\core.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat src;
string file = "xxx.jpg";
src = imread(file );
if (src.empty())
{
fprintf(stderr, "Can not load image %s\n", file);
return -1;
}
imshow("123", src);
waitKey(0);
return 0;
}