Reference Links
Opencv+ qt5.1 完美配置 - 脚踏实地 - 博客频道 - CSDN.NET http://blog.csdn.net/xiaojidan2011/article/details/9421193
【OpenCV】学习札记与源码分析: imread( )函数 - 综合 http://www.myexception.cn/other/1406789.html
openCV基础函数imread第二个参数 - qq764666379的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/haoyunchao/article/details/18325875
源码解析: Imread函数 - 松子茶的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/songzitea/article/details/11096287
代码:main.cpp
/* Time: 2016.12.07
* Author: WJ
* Function: 函数imread() read a image
* Reference:
* Opencv+ qt5.1 完美配置 - 脚踏实地 - 博客频道 - CSDN.NET
* http://blog.csdn.net/xiaojidan2011/article/details/9421193
*/
#include <QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//read a image
Mat image= imread("F:QTcodesQTcreatorOpenCV_0011.png");
// Mat image= imread("F:/QTcodes/QTcreator/OpenCV_001/1.png");
if (image.empty())
{
namedWindow("can not find image : 1.png");
waitKey(5000);
return -1;
}
//creat image windows named "My Image"
namedWindow("My Image",1);
//show the image on window
imshow("My Image",image);
//wait key for 5000ms
waitKey(0);
return a.exec();
}
pro文件:
QT += core
QT -= gui
CONFIG += c++11
TARGET = OpenCV_001
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH+= E:opencv-2.4.13opencvuildincludeopencv
E:opencv-2.4.13opencvuildincludeopencv2
E:opencv-2.4.13opencvuildinclude
LIBS+=E:opencv-2.4.13opencvliblibopencv_calib3d249.dll.a
E:opencv-2.4.13opencvliblibopencv_contrib249.dll.a
E:opencv-2.4.13opencvliblibopencv_core249.dll.a
E:opencv-2.4.13opencvliblibopencv_features2d249.dll.a
E:opencv-2.4.13opencvliblibopencv_flann249.dll.a
E:opencv-2.4.13opencvliblibopencv_gpu249.dll.a
E:opencv-2.4.13opencvliblibopencv_highgui249.dll.a
E:opencv-2.4.13opencvliblibopencv_imgproc249.dll.a
E:opencv-2.4.13opencvliblibopencv_legacy249.dll.a
E:opencv-2.4.13opencvliblibopencv_ml249.dll.a
E:opencv-2.4.13opencvliblibopencv_objdetect249.dll.a
E:opencv-2.4.13opencvliblibopencv_video249.dll.a
遇到的error:
斜杠的方向错误。与windows 路径中的斜杠相反
//read a image
Mat image= imread("F:QTcodesQTcreatorOpenCV_0011.png");
// Mat image= imread("F:/QTcodes/QTcreator/OpenCV_001/1.png");
imread的各个参数如下:
Mat imread(const string& filename, int flags)
{
Mat img; //创建一个变量
imread_(filename,flags,LOAD_MAT,&img); //大多数功能由imread_()函数实现
return img;
}
C++: Mat imread(const string& filename, int flags=1 )
filename – Name of file to be loaded.要加载的文件的名称
flags –
Flags specifying the color type of a loaded image:指定加载的图像的颜色类型的标志
CV_LOAD_IMAGE_ANYDEPTH -
If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. 如果设置,当输入具有相应的深度时返回16位/ 32位图像,否则将其转换为8位。
CV_LOAD_IMAGE_COLOR -
If set, always convert image to the color one 如果设置,请始终将图像转换为
CV_LOAD_IMAGE_GRAYSCALE -
If set, always convert image to the grayscale one如果设置,请始终将图像转换为灰度图像
>0 Return a 3-channel color image.返回3通道彩色图像。
Note: In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.注意在当前实现中,alpha通道(如果有)从输出图像中去除。 如果您需要Alpha通道,请使用负值。
=0 Return a grayscale image.返回灰度图像。
<0 Return the loaded image as is (with alpha channel).返回加载的图像(使用alpha通道)