Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot decode EAN8, code93, UPC-E !!!??? #87

Open
smiler96 opened this issue Apr 22, 2019 · 1 comment
Open

cannot decode EAN8, code93, UPC-E !!!??? #87

smiler96 opened this issue Apr 22, 2019 · 1 comment

Comments

@smiler96
Copy link

i used the zxing c++ version to decode the following images, but it can work for the images about EAN8, UPC-E, but i cropped the barcode ROI for the image to decode and it doesn't work, what's the problem? i am a freshman in this and i hope i can get some help from you! Thank s a lot for your help! The images and their ROIs are listed in the following, and my code also:

EAN8 image:
EAN8
and its ROI:
ROI_EAN8

UPC-E image:
upca
and its ROI:
ROI_upca

#include "zxing_decode.h"

const char* my_code_type[] = {
	"NONE",
	"AZTEC",
	"CODABAR",
	"CODE_39",
	"CODE_93",
	"CODE_128",
	"DATA_MATRIX",
	"EAN_8",
	"EAN_13",
	"ITF"
	"MAXICODE",
	"PDF_417",
	"QR_CODE",
	"RSS_14",
	"RSS_EXPANDED",
	"UPC_A",
	"UPC_E",
	"UPC_EAN_EXTENSION"
};

bool decode_by_zxing(cv::Mat& matGray, std::string& code, std::string& code_type)
{
	zxing::Ref<zxing::LuminanceSource> source(new MatSource(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::EAN13Reader);
	//reader.reset(new zxing::oned::Code128Reader);
	zxing::oned::MultiFormatOneDReader reader(zxing::DecodeHints::DEFAULT_HINT);

	zxing::Ref<zxing::Binarizer> binarizer(new zxing::HybridBinarizer(source));
	//zxing::Ref<zxing::Binarizer> binarizer(new zxing::);
	zxing::Ref<zxing::BinaryBitmap> bitmap(new zxing::BinaryBitmap(binarizer));
	try
	{
		zxing::Ref<zxing::Result> result(reader.decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::DEFAULT_HINT)));
		//zxing::Ref<zxing::Result> result(zxing::MultiFormatReader().decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::EAN_13_HINT)));
		code = result->getText()->getText();
		code_type = my_code_type[result->getBarcodeFormat().value];
		/*fprintf(stdout, "recognization result: %s\n", code.c_str());
		std::cout << "barcode type is: " << my_code_type[result->getBarcodeFormat().value] << "\n\n";
		*/
		return true;
	}
	catch (zxing::Exception& e)
	{
		//std::cout << "Error: " << e.what() << "\n";
		return false;
	}
	
}
@smiler96
Copy link
Author

thanks for your good guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant