内容简介:OpenCV中C++函数imread读取图片的问题及解决方法
今天在用OpenCV实验Image Pyramid的时候发现一个奇怪的问题,就是利用C++函数imread读取图片的时候返回的结果总是空,而利用C函数cvLoadImage时却能读取到图像。代码如下:
//环境:VS2010 + OpenCV 2.3.1
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
Mat src, dst, tmp;
char* window_name = "Pyramids Demo";
int _tmain(int argc, _TCHAR* argv[])
{
printf("\n Zoom In-Out demo \n");
printf("-------------------- \n");
printf("*[u]-> Zoom in \n");
printf("*[d]-> Zoom out \n");
printf("*[ESC]-> Close program \n\n");
src = imread("D:\\fruits.jpg");
if(!src.data)
{
printf("No data!--Exiting the program \n");
return -1;
}
tmp = src;
dst = tmp;
namedWindow(window_name,CV_WINDOW_AUTOSIZE);
imshow(window_name,dst);
while(true)
{
int c;
c = waitKey(10);
if((char)c == 27)
{
break;
}
if((char)c == 'u')
{
pyrUp(tmp,dst,Size(tmp.cols * 2,tmp.rows * 2));
printf("** Zoom In:Image x 2\n");
}
else if((char)c == 'd')
{
pyrDown(tmp,dst,Size(tmp.cols / 2,tmp.rows / 2));
printf("**Zoom Out:Image / 2\n");
}
imshow(window_name,dst);
tmp = dst;
}
return 0;
}
程序很简单,就是直接调用Imgproc中的两个C++函数pyrUp和pyrDown来实现图像金字塔,程序的详细解释可参见 http://www.jb51.net/article/108378.htm 。但在实现的过程中发现imread始终读取不了图像数据和cvLoadImage却可以。几经考证,发现的确是由于库关联的问题。也就是在Debug模式下应该选择带'd'的lib,在Release模式下就选择不带'd'的lib。而实际我们在配置OpenCV环境的时候往往图方便将Debug和Release的目录都一起加了进去,再修改起来也比较麻烦。所以这时候最简单的办法就是在程序的开始加上:
#pragma comment(lib,"opencv_highgui231d.lib")
来告诉程序将采用Debug版本的库函数。
实验结果如下:
以上所述是小编给大家介绍的OpenCV中C++函数imread读取图片的问题及解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
以上所述就是小编给大家介绍的《OpenCV中C++函数imread读取图片的问题及解决方法》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Probability and Computing
Michael Mitzenmacher、Eli Upfal / Cambridge University Press / 2005-01-31 / USD 66.00
Assuming only an elementary background in discrete mathematics, this textbook is an excellent introduction to the probabilistic techniques and paradigms used in the development of probabilistic algori......一起来看看 《Probability and Computing》 这本书的介绍吧!