OpenCV4.2.0 + Zbar条形码识别

https://opencv.org/releases/       source code download

 

1. lib file

F:\openCV\lib_debug

opencv_imgproc420d.lib
opencv_calib3d420d.lib
opencv_core420d.lib
opencv_dnn420d.lib
opencv_features2d420d.lib
opencv_flann420d.lib
opencv_highgui420d.lib
opencv_imgcodecs420d.lib
opencv_ml420d.lib
opencv_objdetect420d.lib
opencv_photo420d.lib
opencv_stitching420d.lib
opencv_ts420d.lib
opencv_video420d.lib
opencv_videoio420d.lib
libzbar-0.lib

 

2. header file

   F:\openCV\include\opencv2

   F:\openCV\include

 

#include <opencv2/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>  // OpenCV window I/O
#include <opencv2/features2d.hpp>
#include <opencv2/objdetect.hpp>

#include <opencv2/opencv.hpp>
#include <iostream>
#include <zbar.h>

using namespace cv;
using namespace std;
using namespace zbar;

int main(int argc, char* argv[])
{
    ImageScanner scanner;
    scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    Mat image = imread("F:\\EAN13.jpg");
    //Mat image = imread("F:\\Code39.jpg");
    //Mat image = imread("F:\\Code93.jpg");
    //Mat image = imread("F:\\Code128.jpg");

    Mat imageGray;
    cvtColor(image, imageGray, COLOR_BGR2GRAY);
    int width = imageGray.cols;
    int height = imageGray.rows;
    uchar *raw = (uchar *)imageGray.data;
    Image imageZbar(width, height, "Y800", raw, width * height);
    scanner.scan(imageZbar); //扫描条码  dyxx5zxx
    Image::SymbolIterator symbol = imageZbar.symbol_begin();
    if (imageZbar.symbol_begin() == imageZbar.symbol_end())
    {
        cout << "查询条码失败,请检查图片!" << endl;
    }
    for (; symbol != imageZbar.symbol_end(); ++symbol)
    {
        cout << "类型:" << endl << symbol->get_type_name() << endl << endl;
        cout << "条码:" << endl << symbol->get_data() << endl << endl;
    }
    imshow("Source Image", image);
    waitKey();
    imageZbar.set_data(NULL, 0);
    return 0;

}

 

Zbar支持的条形码格式有:

EAN-13

UPC-A

UPC-E

EAN-8

Code128

Code39

Interleaved 2 / 5

 

 

      EAN13.jpg  /   Code39.jpg / Code93.jpg  / Code128.jpg

 

   

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值