MYLAF 环境说明 
编程环境:Windows 10(64bit), VS2013, OpenCV 2.4.12; 
编程语言:C/C++;

MYLAF 现象 
在代码中,调用imread读取图片失败,但调用cvLoadImage读取成功。

MYLAF 代码

// MYLAF
#include "opencv2/opencv.hpp" using namespace std;
using namespace cv; int main() { Mat im = imread("D:\\imgSrc.png");//
IplImage* img = cvLoadImage("D:\\imgSrc.png");
if (img) {
im = img;
} imshow("orig",im); waitKey(0); return 0;
}

MYLAF 原来如此 
OpenCV的imread,imshow等等这些函数在编译链接时是认主的,特别忠心不二。 
用人话来说就是:如果你使用Debug模式编译链接,那么请链接Debug模式(opencv_*2412d.lib等)库文件;如果你使用Release模式编译链接,那么请链接Release模式(opencv_*2412.lib)等库文件。 
否则,你就自己玩去吧。 
MYLAF 解决 
在“VS项目–属性–链接器–输入–附加依赖项”添加与项目配置Configuration相对应的lib文件。 
或者使用如下类似代码进行指定对应的lib文件

#if _DEBUG // _DEBUG=Debug模式
#pragma comment(lib, "opencv_core2412d.lib")
#else // NDEBUG=Release模式
#pragma comment(lib, "opencv_core2412.lib")
#endif

MYLAF 小肌肉 
VS项目属性文件*.props中说明:

  <ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(OPENCV_INC_DIR);$(OPENCV_INC_DIR)\opencv;$(OPENCV_INC_DIR)\opencv2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(OPENCV_LIB_DIR);$(OPENCV_BIN_DIR);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies Condition="'$(Configuration)' == 'Debug' ">opencv_core2412d.lib;opencv_flann2412d.lib;opencv_features2d2412d.lib;opencv_ml2412d.lib;opencv_legacy2412d.lib;opencv_photo2412d.lib;opencv_ocl2412d.lib;opencv_contrib2412d.lib;opencv_superres2412d.lib;opencv_videostab2412d.lib;opencv_ts2412d.lib;opencv_stitching2412d.lib;opencv_nonfree2412d.lib;opencv_gpu2412d.lib;opencv_objdetect2412d.lib;opencv_video2412d.lib;opencv_calib3d2412d.lib;opencv_highgui2412d.lib;opencv_imgproc2412d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)' == 'Release' ">opencv_core2412.lib;opencv_flann2412.lib;opencv_features2d2412.lib;opencv_ml2412.lib;opencv_legacy2412.lib;opencv_photo2412.lib;opencv_ocl2412.lib;opencv_contrib2412.lib;opencv_superres2412.lib;opencv_videostab2412.lib;opencv_ts2412.lib;opencv_stitching2412.lib;opencv_nonfree2412.lib;opencv_gpu2412.lib;opencv_objdetect2412.lib;opencv_video2412.lib;opencv_calib3d2412.lib;opencv_highgui2412.lib;opencv_imgproc2412.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>

// MYLAF

05-11 20:50