opencv条码(2)图像读入和显示

  1. 云栖社区>
  2. 博客>
  3. 正文

opencv条码(2)图像读入和显示

lovedan 2013-04-29 15:16:00 浏览419
展开阅读全文

查看了opencv中文的网站的简单历程,好多代码是opencv1.0版本,或者C语言的,感觉写的不好理解。。

我觉得实现简单的功能的话可以先不考虑那么多 代码能少就少才好  所以这里贴出我的代码 

环境:win7(64位)+opencv2.4.3+Qt5.0.1(mingw47_32)

qt的.pro文件中添加:

INCLUDEPATH+=C:/software/opencv/buildForMinGW/install/include\
C:/software/opencv/buildForMinGW/install/include/opencv\
C:/software/opencv/buildForMinGW/install/include/opencv2


LIBS+=C:/software/opencv/buildForMinGW/install/lib/libopencv_calib3d243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_contrib243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_core243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_features2d243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_flann243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_gpu243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_highgui243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_imgproc243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_legacy243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_ml243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_nonfree243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_objdetect243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_photo243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_stitching243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_ts243.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_video243.dll.a\
C:/software/opencv/buildForMinGW/install/lib/libopencv_videostab243.dll.a



今天先贴第一个代码吧:

 1 /*
 2  *environment:opencv2.4.3+Qt5.0.1(mingw47)
 3  *author:ChrisZZ
 4  *功能:读取指定路径下的图片
 5  *     并且在namedWindow中显示
 6  */
 7 #include <cv.h>
 8 #include <highgui.h>
 9 
10 using namespace cv; //下面的所有cv相关类型不用加上前缀了
11 
12 int main(){
13     Mat img = imread("C:/testdir/barcode.bmp"); //声明Mat变量并导入图片
14 
15     if(!img.data) //判断图片调入是否成功
16          return -1; //调入图片失败则退出
17     //创建窗口,并确定其为大小不可变类型窗口
18     namedWindow("myImgWindow", CV_WINDOW_AUTOSIZE);
19 
20     //显示图片。如果你不介意窗口大小可变,可以直接注释掉上一句。因为imshow可以直接创建窗口
21     imshow("loveLena", img);
22 
23     waitKey(); //等待按键
24 
25     return 0;
26 }

本人在做条码所以这里图片都叫做barcode.bmp

网友评论

登录后评论
0/500
评论
lovedan
+ 关注