一维码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. Oracle 数据库执行慢SQL

    ) hou, - ))) mini, c.sql_address, c.inst_id,f.full_name,u.user_name, b.user_concurrent_program_name, ...

  2. Flask的错误日志处理和|ORM操作

    flask有个很人性化的处理就是 你的错误的输出是可以通过错误日志来自定义  ,让你输入的错误不再是“大黄页”, 通过 errorhandler()来装饰函数之后你的所有的输入错误的函数你都会进入这个 ...

  3. 显示iOS所有系统字体

    显示iOS所有系统字体 源码地址: https://github.com/YouXianMing/UI-Component-Collection 效果图: 便于你开发中寻找适合自己的字体, demo中 ...

  4. [翻译] GoogleMaterialDesignIcons

    GoogleMaterialDesignIcons Google Material Design Icons Font for iOS GMD图片样式的字体,用于iOS开发. It is based ...

  5. 在虚拟机里安装linux(centos 6.5)系统

    菜鸟一枚,也是接触linux系统没多长时间,前一阵子网上说有一个高级数据库工程师,因为rm -rf / 命令干掉了数据库-(nb),居然还跑路了!厉害了我的哥!也是闲的我蛋疼,在虚拟机里试了一批,本来 ...

  6. 面向对象程序设计__Task3_Calculator

    The initial part of the Calculator program 题目链接:Click Here github链接:Click Here 看到这个题目的话,想到就是有3个任务要去做 ...

  7. 如何确定PHP CLI 的php.ini文件的位置

    当我们安装扩展时,可能需要手动配置php.ini文件,把扩展加进去,所以要确认PHP CLI的php.ini文件的位置.可以运行php --ini查找PHP CLI的ini文件位置,结果类似如下(各个 ...

  8. Scala学习——Brief Scala Tutorial

    因为Spark项目需要,学习Scala编程. 从官网文档入手:http://www.scala-lang.org/documentation/ 首先从他的Older Documentation入手. ...

  9. 8年前,令我窒息的Java socket体验学习

    本来已经放弃编程了,那时我发誓再也不去IT培训班了,如果找不到工作,我就去工地上打工.可心有不甘,老是惦记着,我不想天天面对生产线,做一个丧失思考能力的操作工,可后来呀,还是走上了程序员之路...这么 ...

  10. FWT背板笔记

    板子 背板子.jpg \(Fwt\)用于解决这样的问题 \[C_i=\sum_{j\bigoplus k=i}A_j\times B_k\] 其中\(\bigoplus\)是一种二元运算符,如\(or ...