opencv条码(2)图像读入和显示-阿里云开发者社区

开发者社区> 人工智能> 正文
登录阅读全文

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

简介: 查看了opencv中文的网站的简单历程,好多代码是opencv1.0版本,或者C语言的,感觉写的不好理解。。 我觉得实现简单的功能的话可以先不考虑那么多 代码能少就少才好  所以这里贴出我的代码  环境:win7(64位)+opencv2.

查看了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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: