Zbar Open source project two-dimensional code recognition (test)

Source: Internet
Author: User
Tags scalar

In order to complete the homework assigned by the teacher, we investigated the open source two-dimensional code recognition library. I only checked the zxing, Zbar, which zxing in my machine compile debugging pass, but the effect is not ideal, so changed the Zbar use. (My small partner found the open Source Library of Zxing Mobile end, and debug successfully, I will fill in a few days)


Environment: VS2010, OpenCV2.4.9, Zbar environment configuration

Environment Description:

1. OpenCV is a machine vision open source class library, widely used in image processing, pattern recognition and other fields, it is the core of Zbar project. Here I am using OpenCV2.4.9. (OpenCV1 version is not recommended)

2. Integrated development tools Visual Studio2010. (Visual C + + 6.0 is not recommended because it supports only OpenCV1.0 versions)

3. Zbar Development environment

Zbar Official website: http://zbar.sourceforge.net/download.html

OPENCV Official website: http://opencv.org/

Environment Configuration Reference: http://blog.csdn.net/dcrmg/article/details/52108258


Instructions for use:

1. Installation of OpenCV, Zbar, and environmental configuration

2. Create a new C + + console application, and set the appropriate engineering properties, add include directories, additional links, and so on.

3. The test procedure is as follows:

#include "zbar.h" #include "cv.h" #include "highgui.h" #include <iostream> using namespace std;  
using namespace Zbar;    

using namespace CV;    
	int main (void) {Imagescanner scanner;   
	Scanner.set_config (Zbar_none, zbar_cfg_enable, 1);    
	Char file[256];    
	cin>>file;    
	Mat img = imread (file,0);    
	Mat imgout;    
	Cvtcolor (IMG,IMGOUT,CV_GRAY2RGB);    
	int width = Img.cols;    
	int height = img.rows;       
	Uchar *raw = (Uchar *) Img.data;      
	Image Image (width, height, "Y800", raw, Width * height);      
	int n = scanner.scan (image); for (Image::symboliterator symbol = Image.symbol_begin (); symbol!= image.symbol_end (); symbol++) {vector<point& Gt    
		Vp  
		cout<< "Decoded:êo" <<endl<<symbol->get_type_name () <<endl<<endl;           
		cout<< "Symbol:êo" <<endl<<symbol->get_data () <<endl<<endl;    
		int n = symbol->get_location_size (); for (int i=0;i<n;i++) {Vp.push_back (Point (symbol->get_location_x (i), symbol->get_location_y (i)));    
		} rotatedrect r = Minarearect (VP);    
		POINT2F Pts[4];    
		R.points (pts);  
		Point TextPoint (pts[1]);  
		String Codenum=symbol->get_data ();   
			for (int i=0;i<4;i++) {line (imgout,pts[i],pts[(i+1)%4],scalar (255,0,0), 3);  
			textpoint.x>=pts[i].x?textpoint.x=pts[i].x:textpoint.x=textpoint.x;  
	 textpoint.y>=pts[i].y?textpoint.y=pts[i].y:textpoint.y=textpoint.y;               
		Puttext (Imgout,codenum,textpoint,font_hershey_complex,1,scalar (0,0,255), 1,8,false);    
	} cout<< "Angle:" <<r.angle<<endl;      
	} imshow ("Imgout.jpg", imgout);    
Waitkey ();    
 }

4. Sir into a two-dimensional code with embedded text information



Run the test program, as shown in the following figure:




Change the URL and try again:





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.