Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3047149
  • 博文数量: 396
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4209
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-04 13:04
文章分类

全部博文(396)

文章存档

2022年(1)

2021年(2)

2020年(8)

2019年(24)

2018年(135)

2017年(158)

2016年(68)

我的朋友

分类: 嵌入式

2017-12-21 10:48:26

一维码Codabar:由4条黑色线条,3条白色线条,合计7条线条所组成,每一个字元与字元之间有一间隙Gap做区隔。

         条形码Codabar包含21个字元:

(1)、10个数字0~9;

(2)、”+”, ”-”,”*”, ”/”, ”$”, .”, ”:”等7个特殊符号;

(3)、A、B、C、D四个英文字母。

Codabar编码方式与125码及Code 39码相同,只有二种粗细比例。

Codabar其起始码/结束码有4*4=16种组合。

         Codabar一般应用于物料管理、图书馆、血站和当前的机场包裹发送中,空白区比窄条宽10,非连续性条形码,每个字符表示为4条3空。

以下是通过zxing-cpp开源库实现的对一维码Codabar进行解码的测试代码:


[cpp] view plain copy
  1. #include "funset.hpp"  
  2. #include   
  3. #include   
  4. #include   
  5.   
  6. #include   
  7. #include   
  8. #include   
  9. #include   
  10. #include   
  11. #include   
  12. #include   
  13. #include   
  14. #include   
  15. #include   
  16. #include   
  17.   
  18. #include   
  19.   
  20. #include "zxing/MatSource.h"  
  21.   
  22. int test_Codabar_decode()  
  23. {  
  24.     std::string image_name = "E:/GitCode/BarCode_Test/test_images/Codabar.png";  
  25.     cv::Mat matSrc = cv::imread(image_name, 1);  
  26.     if (!matSrc.data) {  
  27.         fprintf(stderr, "read image error: %s", image_name.c_str());  
  28.         return -1;  
  29.     }  
  30.   
  31.     cv::Mat matGray;  
  32.     cv::cvtColor(matSrc, matGray, CV_BGR2GRAY);  
  33.   
  34.     zxing::Ref source = MatSource::create(matGray);  
  35.     int width = source->getWidth();  
  36.     int height = source->getHeight();  
  37.     fprintf(stderr, "image width: %d, height: %d\n", width, height);  
  38.   
  39.     zxing::Ref reader;  
  40.     reader.reset(new zxing::oned::CodaBarReader);  
  41.   
  42.     zxing::Ref binarizer(new zxing::GlobalHistogramBinarizer(source));  
  43.     zxing::Ref bitmap(new zxing::BinaryBitmap(binarizer));  
  44.     zxing::Ref result(reader->decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::CODABAR_HINT)));  
  45.   
  46.     std::string txt = "E:/GitCode/BarCode_Test/test_images/Codabar.txt";  
  47.     std::ifstream in(txt);  
  48.     if (!in.is_open()) {  
  49.         fprintf(stderr, "fail to open file: %s\n", txt.c_str());  
  50.         return -1;  
  51.     }  
  52.   
  53.     std::string str1;  
  54.     std::getline(in, str1);  
  55.     fprintf(stderr, "actual        result: %s\n", str1.c_str());  
  56.     std::string str2 = result->getText()->getText();  
  57.     fprintf(stdout, "recognization result: %s\n", str2.c_str());  
  58.   
  59.     if (str1.compare(str2) == 0) {  
  60.         fprintf(stderr, "=====  recognition is correct  =====\n");  
  61.     }  
  62.     else {  
  63.         fprintf(stderr, "=====  recognition is wrong =====\n");  
  64.         return -1;  
  65.     }  
  66.   
  67.     in.close();  
  68.   
  69.     return 0;  
  70. }  
测试图像如下:


测试结果如下:


GitHub

阅读(2844) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~