VC++识别QR-Code格式的二维码

本望断在图像识别QR-Code格式的二维码

根据此编写出的识别QR-Code和Data-Matrix的二维码(库)

http://download.csdn.net/download/wangduanqiugao/10141924

本秋高使用到的软件工具:VS2010  opencv1.0  zbar-0.10  (使用以上现有库直接实现功能)

VS2010就不用说了;使用opencv1.0版本以上的也可以,此部分作基础就不进行阐述

zbar-0.10版本下载网址:
https://sourceforge.net/projects/zbar/files/zbar/0.10/zbar-0.10-setup.exe/download

zbar-0.10需要安装,好了是调用动态库的模式添加到VS2010;存放路径随意的..

一、
1. VS2010工程项目属性中:VC++ Directories\Library Directories 添加路径——..\ZBar\lib
   VS2010工程项目属性中:Linker\Input\ Additional Directories 添加文件——libzbar-0.lib
   VS2010工程项目属性中:C/C++\General\Additional Include Directories 添加路径——..\ZBar\include和..\ZBar\include\zbar

#include "zbar.h"
using namespace std;
using namespace zbar;
bool wangduanqiugao_QR_Code(IplImage *Image, char *Information)
{        
  string mation;
  ImageScanner scanner;    
	
  scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); 
 
  IplImage *pSrcImage = cvCloneImage(Image);
  IplImage *GrayImage = cvCreateImage(cvGetSize(pSrcImage),IPL_DEPTH_8U,1);
  cvCvtColor(pSrcImage,GrayImage,CV_RGB2GRAY);
    
  CvMat matheader;
  CvMat * img = cvGetMat(GrayImage, &matheader);

  int width = img->cols;  
  int height = img->rows;    
  uchar *raw = img->data.ptr;      
 
 zbar::Image imageZbar(width, height, "Y800", raw, width * height);  
    
  scanner.scan(imageZbar); //扫描条码  
  zbar::Image::SymbolIterator symbol = imageZbar.symbol_begin();

   if(imageZbar.symbol_begin()==imageZbar.symbol_end())
    {
        cvReleaseImage(&pSrcImage);
        cvReleaseImage(&GrayImage);
	return false;
     }
	
   for(;symbol != imageZbar.symbol_end();++symbol)  
     {    
	 mation = symbol->get_data(); 
      }    

    strcpy(Information, mation.c_str());
    cvReleaseImage(&pSrcImage);
    cvReleaseImage(&GrayImage);
     return true;
}



你可能感兴趣的:(待雪)