Configuration of ZBar Library under Windows System (VS2015+OpenCV3.4.3+ZBar0.10)

Keywords: Windows OpenCV encoding github

Catalog


ZBar is an open source two-dimensional code (including barcode) decoder that recognizes barcodes/two-dimensional codes from video streams, image files, handheld scanners and video devices (such as cameras). It supports EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, QR Code and other common encoding methods..

step1 runtime environment

1. Windows 1064-bit

2,Visual Studio 2015 Professional

3,OpenCV 3.4.3

4,ZBar 0.10

step2 installation

1. Download the installation of the Windows Installer version from the ZBar website at http://zbar.sourceforge.net/download.html.

2. Official download and installation only contains 32-bit lib files, so 64-bit configuration is impossible, so more steps are needed.
Method 1:
Download and unzip the zip package at https://github.com/dani4/ZBarWin64 on this website.
(1) Copy the libzbar64-0.lib file under the ZBarWin64-masterlib folder into the Lib folder under the ZBar installation path.
(2) Copy the libzbar64-0.dll file under the ZBarWin64-master\lib folder into the bin folder under the ZBar installation path.
(3) Copy the libiconv.dll file under the ZBarWin64-masterzbarlibiconvdll_x64 folder to the bin folder under the ZBar installation path.
Method 2:
Download the modified zipped package file directly.
Link: https://pan.baidu.com/s/1EAgiYF5S65QpWAnFWS5CrQ Extraction Code: jesa

step3 configuration

1. Add the bin folder under the ZBar installation directory to the environment variable.

2. Create a new empty project in VS2015 and configure it in the Attribute Manager as follows:
(1) Include directories:

(2) Library directory:

(3) Linker->Input->Additional Dependencies:

step4 test

Add the following test code to the cpp file of the empty project source file to call the camera to locate and decode the QR code.

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

int main(int argc, char*argv[])
{
	zbar::ImageScanner scanner;
	scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);
	cv::VideoCapture capture;
	capture.open(0);  //Turn on the camera
	cv::Mat image;
	cv::Mat imageGray;
	std::vector<cv::Point2f> obj_location;
	bool flag = true;

	if (!capture.isOpened())
	{
		std::cout << "cannot open cam!" << std::endl;
	}
	else
	{
		while (flag)
		{
			capture >> image;
			cv::cvtColor(image, imageGray, CV_RGB2GRAY);
			int width = imageGray.cols;
			int height = imageGray.rows;
			uchar *raw = (uchar *)imageGray.data;
			zbar::Image imageZbar(width, height, "Y800", raw, width * height);
			scanner.scan(imageZbar);  //Scan Barcode
			zbar::Image::SymbolIterator symbol = imageZbar.symbol_begin();
			if (imageZbar.symbol_begin() != imageZbar.symbol_end())  //If Scan to QR Code
			{
				flag = false;
				//Resolve 2D Code
				for (int i = 0; i < symbol->get_location_size(); i++)
				{
					obj_location.push_back(cv::Point(symbol->get_location_x(i), symbol->get_location_y(i)));
				}
				for (int i = 0; i < obj_location.size(); i++)
				{
					cv::line(image, obj_location[i], obj_location[(i + 1) % obj_location.size()], cv::Scalar(255, 0, 0), 3);//Locate Barcode
				}
				for (; symbol != imageZbar.symbol_end(); ++symbol)
				{
					std::cout << "Code Type: " << std::endl << symbol->get_type_name() << std::endl; //Get Barcode Type
					std::cout << "Decode Result: " << std::endl << symbol->get_data() << std::endl;  //Decode
				}
				imageZbar.set_data(NULL, 0);
			}
			cv::imshow("Result", image);
			cv::waitKey(50);
		}
		cv::waitKey();
	}
	return 0;
}

Identify the type of bar code: QR code, CSDN big data WeChat public number.

ZBar currently does not support decoding Chinese and may need to modify the source code to compile.

Reference article:
https://blog.csdn.net/dcrmg/article/details/52108258
https://www.cnblogs.com/gloria-zhang/p/9011776.html
https://www.cnblogs.com/jsxyhelu/p/7371341.html
http://www.pianshen.com/article/1196260020/
https://blog.csdn.net/MengchiCMC/article/details/77871714
https://blog.csdn.net/weixin_41820730/article/details/79695250
https://blog.csdn.net/skillcollege/article/details/38855023
https://www.cnblogs.com/cjqbaba/p/9073908.html

Juliet 2009.9

Posted by crazylegseddie on Wed, 18 Sep 2019 19:53:58 -0700