参考链接
openCV基函数imread第二参数- qq764666379中的列-博客通道- csdn.net http://blog.csdn.net/haoyun Chao/article/details/1832587777
代码: main.cpp
/*时间: 2016.12.07
* Author: WJ
*功能:函数imread () read a image
*参考:
* Opencv qt5.1完美配置-脚踏实地-博客频道- CSDN.NET
* http://blog.csdn.net/Xiao Ji Dan 2011/article/details/9421193
*/
#包含
#包含
#包含
#include 'cv.h '
#include 'cxcore.h '
#include 'highgui.h '
using namespace cv;
(intmain(intargc,char *argv[] ) ) ) ) ) ) ) ) ) ) )
{
qcoreapplicationa(argc,argv );
//读取a image
matimage=im read (f : (Qt代码) Qtcreator ) opencv_001(1.png );
//matimage=im read (f :/Qt代码/Qt creator/opencv _ 001/1.png );
if(image.empty ) )
{
命名窗口(cannotfindimage :1.png );
等待密钥(5000;
返回- 1;
}
//creatimagewindowsnamed ' my image '
名称窗口(' my image ',1 );
//show the image on window
imshow(myimage )、image );
//wait key for 5000ms
维基(0;
return a.exec (;
}
pro文件:
QT =core
QT -=gui
CONFIG =c 11
TARGET=OpenCV_001
CONFIG =console
CONFIG -=app_bundle
模板=APP
SOURCES =main.cpp
include path=e :opencv-2.4.13opencvbuildincludeopencv
e :opencv-2.4.13opencvbuildincludeopencv2
e :opencv-2.4.13opencvbuildinclude
libs=e :opencv-2.4.13opencvliblib opencv _ calib 3d 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ contrib 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ core 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ features 2d 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ flann 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ GPU 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ highgui 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ img proc 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ legacy 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ ml 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ obj detect 249.dll.a
e :opencv-2.4.13opencvliblib opencv _ video 249.dll.a
遇到的错误:
斜线的方向错了。 与windows路径的正斜线相反
//读取a image
matimage=im read (f : (Qt代码) Qtcreator ) opencv_001(1.png );
//matimage=im read (f :/Qt代码/Qt creator/opencv _ 001/1.png );
imread的各参数如下。
matimread (常数文件名,int flags ) )。
{
马特img; //创建变量
imread_(filename,flags,LOAD_MAT,img ); //大部分功能都是用imread_ ()函数实现的
返回img;
}
c : matimread (一致文件名,intflags=1) ) ) )。
filenamenameoffiletobeloaded .要加载的文件的名称
flags-
flagsspecifyingthecolortypeofaloadedimage :指定加载图像的颜色类型的标志
CV_LOAD_IMAGE_ANYDEPTH -
如果设置了If set,return 16-bit/32-bitimagewhentheinputhasthecorrespondingdepth,otherwise convert it to 8-bit .则输入适当的深度
CV_LOAD_IMAGE_COLOR -
如果设置了If set,alwaysconvertimagetothecolorone,请始终将图像转换为
CV_LOAD_IMAGE_GRAYSCALE -
如果设置了If set,alwaysconvertimagetothegrayscaleone,请始终将图像转换为灰度图像
0返回a 3通道颜色图像.返回3通道彩色图像。
note:inthecurrentimplementationthealphachannel,if any,isstrippedfromtheoutputimage.usenegativevalueifyouneedthealphachachage
=0Return a grayscale image .返回灰度图像。
0 returntheloadedimageasis (withalphachannel ) .返回加载的图像(使用alpha通道) ) ) )。