一维码ITF 25又称交插25条码,常用在序号,外箱编号等应用。交插25码是一种条和空都表示信息的条码,交插25码有两种单元宽度,每一个条码字符由五个单元组成,其中二个宽单元,三个窄单元。在一个交插25码符号中,组成条码符号的字符个数为偶数,当字符是奇数个时,应在左侧补0变为偶数。条码字符从左到右,奇数位置字符用条表示,偶数位字符用空表示。交插25码的字符集包括数字0到9.

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

#include "funset.hpp"
#include <string>
#include <fstream>
#include <Windows.h>

#include <zxing/LuminanceSource.h>
#include <zxing/common/Counted.h>
#include <zxing/Reader.h>
#include <zxing/aztec/AztecReader.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include <zxing/DecodeHints.h>
#include <zxing/datamatrix/DataMatrixReader.h>
#include <zxing/MultiFormatReader.h>
#include <zxing/pdf417/PDF417Reader.h>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/oned/CodaBarReader.h>
#include <zxing/oned/Code39Reader.h>
#include <zxing/oned/Code93Reader.h>
#include <zxing/oned/Code128Reader.h>
#include <zxing/oned/EAN8Reader.h>
#include <zxing/oned/EAN13Reader.h>
#include <zxing/oned/ITFReader.h>

#include <opencv2/opencv.hpp>

#include "zxing/MatSource.h"

int test_ITF25_decode()
{
	std::string image_name = "E:/GitCode/BarCode_Test/test_images/ITF25.png";
	cv::Mat matSrc = cv::imread(image_name, 1);
	if (!matSrc.data) {
		fprintf(stderr, "read image error: %s", image_name.c_str());
		return -1;
	}

	cv::Mat matGray;
	cv::cvtColor(matSrc, matGray, CV_BGR2GRAY);

	zxing::Ref<zxing::LuminanceSource> source = MatSource::create(matGray);
	int width = source->getWidth();
	int height = source->getHeight();
	fprintf(stderr, "image width: %d, height: %d\n", width, height);

	zxing::Ref<zxing::Reader> reader;
	reader.reset(new zxing::oned::ITFReader);

	zxing::Ref<zxing::Binarizer> binarizer(new zxing::GlobalHistogramBinarizer(source));
	zxing::Ref<zxing::BinaryBitmap> bitmap(new zxing::BinaryBitmap(binarizer));
	zxing::Ref<zxing::Result> result(reader->decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::ITF_HINT)));

	std::string txt = "E:/GitCode/BarCode_Test/test_images/ITF25.txt";
	std::ifstream in(txt);
	if (!in.is_open()) {
		fprintf(stderr, "fail to open file: %s\n", txt.c_str());
		return -1;
	}

	std::string str1;
	std::getline(in, str1);
	fprintf(stderr, "actual        result: %s\n", str1.c_str());
	std::string str2 = result->getText()->getText();
	fprintf(stdout, "recognization result: %s\n", str2.c_str());

	if (str1.compare(str2) == 0) {
		fprintf(stderr, "=====  recognition is correct  =====\n");
	}
	else {
		fprintf(stderr, "=====  recognition is wrong =====\n");
		return -1;
	}

	in.close();

	return 0;
}

测试图像如下:

测试结果如下:

GitHubhttps://github.com/fengbingchun/Barcode_Test

一维码ITF 25简介及其解码实现(zxing-cpp)的更多相关文章

  1. (zxing.net)一维码ITF的简介、实现与解码

    一.简介 一维码ITF 25又称交插25条码,常用在序号,外箱编号等应用.交插25码是一种条和空都表示信息的条码,交插25码有两种单元宽度,每一个条码字符由五个单元组成,其中二个宽单元,三个窄单元.在 ...

  2. 一维码UPC E简介及其解码实现(zxing-cpp)

    UPC(Universal Product Code)码是最早大规模应用的条码,其特性是一种长度固定.连续性的条  码,目前主要在美国和加拿大使用,由于其应用范围广泛,故又被称万用条码. UPC码仅可 ...

  3. 一维码UPC A简介及其解码实现(zxing-cpp)

    UPC(Universal Product Code)码是最早大规模应用的条码,其特性是一种长度固定.连续性的条  码,目前主要在美国和加拿大使用,由于其应用范围广泛,故又被称万用条码. UPC码仅可 ...

  4. 一维码EAN 13简介及其解码实现(zxing-cpp)

    一维码EAN 13:属于国际标准条码, 由13个数字组成,为EAN的标准编码型式(EAN标准码). 依结构的不同,EAN条码可区分为: 1.  EAN 13码: 由13个数字组成,为EAN的标准编码型 ...

  5. 一维码EAN 8简介及其解码实现(zxing-cpp)

    一维码EAN 8:属于国际标准条码,由8个数字组成,属EAN的简易编码形式(EAN缩短码).当包装面积小于120平方公分以下无法使用标准码时,可以申请使用缩短码. 依结构的不同,EAN条码可区分为: ...

  6. 一维码Code 128简介及其解码实现(zxing-cpp)

    一维码Code 128:1981年推出,是一种长度可变.连续性的字母数字条码.与其他一维条码比较起来,相对较为复杂,支持的字元也相对较多,又有不同的编码方式可供交互运用,因此其应用弹性也较大. Cod ...

  7. 一维码Code 93简介及其解码实现(zxing-cpp)

    一维码Code 93: Code 93码与Code 39码的字符集相同,但93码的密度要比39码高,因而在面积不足的情况下,可以用93码代替39码.它没有自校验功能,为了确保数据安全性,采用了双校验字 ...

  8. 一维码Code 39简介及其解码实现(zxing-cpp)

    一维码Code 39:由于编制简单.能够对任意长度的数据进行编码.支持设备广泛等特性而被广泛采用. Code 39码特点: 1. 能够对任意长度的数据进行编码,其局限在于印刷品的长度和条码阅读器的识别 ...

  9. (zxing.net)一维码Codabar的简介、实现与解码

    一.简介 一维码Codabar:由4条黑色线条,3条白色线条,合计7条线条所组成,每一个字元与字元之间有一间隙Gap做区隔. 条形码Codabar包含21个字元: (1).10个数字0~9; (2). ...

随机推荐

  1. [UI] 精美UI界面欣赏[3]

    精美UI界面欣赏[3]

  2. 解决 锁定文件失败 打不开磁盘“D:\ubuntu\Ubuntu 64 位.vmdk”或它所依赖的某个快照磁盘。 模块 Disk”启动失败

    一次在使用虚拟机的过程中,电脑出问题强制关机后,重新打开虚拟机,出现了“文件锁定失败”,打不开虚拟机的情况. 上网百度查相关的解决方案,终于解决了问题.因为虚拟机运行的时候会创建相应的文件,即在虚拟机 ...

  3. 关于strip(切割)和 split(分开) 的区别

    plit(), 以括号里的东西为标准,把字符串分开成一个列表 strip(), "删除",括号里出现的东西,从两头开始往中间删除,直到遇到阻碍.中间就算有,也不会受影响 s10 = ...

  4. 原生JavaScript可以干那些事情

    1.原生JavaScript实现字符串长度截取 function cutstr(str, len) { var temp; var icount = 0; var patrn = /[^\x00-\x ...

  5. 第一次项目冲刺(Alpha版本)2017/11/17

    一.当天站立式会议 会议内容 1.对数据库的设计的进一步讨论 2.讨论SSH一些配置细节 3.分配今天的任务 二.任务分解图 三.燃尽图 四.心得 刚接触冲刺,一开始任务没有分布很多,大家要一些熟悉的 ...

  6. 归并排序(php实现)

    <?php function mergeSort(&$arr){ $len = count($arr); msort($arr,0,$len-1); } function msort(& ...

  7. 解决Struts2 json-plugin Date或Timestamp等日期格式带T的问题

    如果没有对日期时间对象类进行json日期格式声明,会出现类似"2013-06-18T12:08:56.23"日期,在日期中间多出一个T字母: 从通过查询数据,以及调试程序发现直到返 ...

  8. swift的异常处理:本质是错误信息的传递方式

    func response(from resultObject: Any) throws -> Response { guard let dict = resultObject as? [Str ...

  9. juquery去除字符串前后的空格

    1.  去掉字符串前后所有空格: 代码如下: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); }

  10. [国家集训队]小Z的袜子

    嘟嘟嘟 一眼就知道是莫队. 还不带修改,美滋滋. 按莫队的方法排序,然后用小学数学算一下概率,分子分母单独维护. #include<cstdio> #include<iostream ...