zbar 二维码_c++ zbar生成二维码 - CSDN
精华内容
参与话题
  • Opencv+Zbar二维码识别(二维码校正)

    万次阅读 热门讨论 2016-08-12 23:43:01
    二维码和车牌识别基本都会涉及到图像的校正,主要是形变和倾斜角度的校正,一种二维码的畸变如下图: 这个码用微信扫了一下,识别不出来,但是用Zbar还是可以准确识别的~~。 这里介绍一种二维码校正方法,思路:...

    二维码和车牌识别基本都会涉及到图像的校正,主要是形变和倾斜角度的校正,一种二维码的畸变如下图:


    这个码用微信扫了一下,识别不出来,但是用Zbar还是可以准确识别的~~。

    这里介绍一种二维码校正方法,通过定位二维码的4个顶点,利用仿射变换校正。基本思路:滤波->二值化->膨胀(腐蚀)操作->形态学边界->寻找直线->定位交点->仿射变换校正->Zbar识别。


    滤波、二值化:


    腐蚀操作:



    形态学边界:



    寻找直线:



    角点定位:



    仿射变换校正:



    Zbar识别:



    Code实现:

    #include "zbar.h"      
    #include "cv.h"      
    #include "highgui.h"      
    #include <iostream>      
    
    using namespace std;      
    using namespace zbar;  //添加zbar名称空间    
    using namespace cv;      
    
    int main(int argc,char*argv[])    
    {  
    	Mat imageSource=imread(argv[1],0);	
    	Mat image;
    	imageSource.copyTo(image);
    	GaussianBlur(image,image,Size(3,3),0);  //滤波
    	threshold(image,image,100,255,CV_THRESH_BINARY);  //二值化
    	imshow("二值化",image);	
    	Mat element=getStructuringElement(2,Size(7,7));	 //膨胀腐蚀核
    	//morphologyEx(image,image,MORPH_OPEN,element);	
    	for(int i=0;i<10;i++)
    	{
    		erode(image,image,element);
    		i++;
    	}	
    	imshow("腐蚀s",image);
    	Mat image1;
    	erode(image,image1,element);
    	image1=image-image1;
    	imshow("边界",image1);
    	//寻找直线 边界定位也可以用findContours实现
    	vector<Vec2f>lines;
    	HoughLines(image1,lines,1,CV_PI/150,250,0,0);
    	Mat DrawLine=Mat::zeros(image1.size(),CV_8UC1);
    	for(int i=0;i<lines.size();i++)
    	{
    		float rho=lines[i][0];
    		float theta=lines[i][1];
    		Point pt1,pt2;
    		double a=cos(theta),b=sin(theta);
    		double x0=a*rho,y0=b*rho;
    		pt1.x=cvRound(x0+1000*(-b));
    		pt1.y=cvRound(y0+1000*a);
    		pt2.x=cvRound(x0-1000*(-b));
    		pt2.y=cvRound(y0-1000*a);
    		line(DrawLine,pt1,pt2,Scalar(255),1,CV_AA);
    	}
    	imshow("直线",DrawLine);
    	Point2f P1[4];
    	Point2f P2[4];
    	vector<Point2f>corners;
    	goodFeaturesToTrack(DrawLine,corners,4,0.1,10,Mat()); //角点检测
    	for(int i=0;i<corners.size();i++)
    	{
    		circle(DrawLine,corners[i],3,Scalar(255),3);
    		P1[i]=corners[i];		
    	}
    	imshow("交点",DrawLine);
    	int width=P1[1].x-P1[0].x;
    	int hight=P1[2].y-P1[0].y;
    	P2[0]=P1[0];
    	P2[1]=Point2f(P2[0].x+width,P2[0].y);
    	P2[2]=Point2f(P2[0].x,P2[1].y+hight);
    	P2[3]=Point2f(P2[1].x,P2[2].y);
    	Mat elementTransf;
    	elementTransf=	getAffineTransform(P1,P2);
    	warpAffine(imageSource,imageSource,elementTransf,imageSource.size(),1,0,Scalar(255));
    	imshow("校正",imageSource);	
    	//Zbar二维码识别
    	ImageScanner scanner;      
    	scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); 
    	int width1 = imageSource.cols;      
    	int height1 = imageSource.rows;      
    	uchar *raw = (uchar *)imageSource.data;         
    	Image imageZbar(width1, height1, "Y800", raw, width * height1);        
    	scanner.scan(imageZbar); //扫描条码    
    	Image::SymbolIterator symbol = imageZbar.symbol_begin();  
    	if(imageZbar.symbol_begin()==imageZbar.symbol_end())  
    	{  
    		cout<<"查询条码失败,请检查图片!"<<endl;  
    	}  
    	for(;symbol != imageZbar.symbol_end();++symbol)    
    	{      
    		cout<<"类型:"<<endl<<symbol->get_type_name()<<endl<<endl;    
    		cout<<"条码:"<<endl<<symbol->get_data()<<endl<<endl;       
    	}      
    	namedWindow("Source Window",0);
    	imshow("Source Window",imageSource);        
    	waitKey();    
    	imageZbar.set_data(NULL,0);  
    	return 0;  
    }


    展开全文
  • 二维码的实现(Zbar) 我这里推荐一个二维码扫描的开源框架——BGAQRCode-Android   QRCode 扫描二维码、扫描条形码、相册获取图片后识别、生成带 Logo 二维码、支持微博微信、QQ 二维码扫描样式。他把Zbar和Zxing,...

    二维码的实现(Zbar)

    我这里推荐一个二维码扫描的开源框架——BGAQRCode-Android
      QRCode 扫描二维码、扫描条形码、相册获取图片后识别、生成带 Logo 二维码、支持微博微信、QQ 二维码扫描样式。他把Zbar和Zxing,都做了优化,扫描速度非常快,用户体验很好,用起来也非常方便
    .

    第一步:
    导入依赖

    implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.2.1'
    或者
    implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.2.1'
    

    第二步:
    布局:

     <cn.bingoogolapple.qrcode.zbar.ZBarView
            android:id="@+id/zbarview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:qrcv_animTime="1000"
            app:qrcv_borderColor="@android:color/white"
            app:qrcv_borderSize="1dp"
            app:qrcv_cornerColor="@color/colorPrimaryDark"
            app:qrcv_cornerLength="20dp"
            app:qrcv_cornerSize="3dp"
            app:qrcv_isShowDefaultScanLineDrawable="true"
            app:qrcv_maskColor="#33FFFFFF"
            app:qrcv_rectWidth="200dp"
            app:qrcv_scanLineColor="@color/colorPrimaryDark"
            app:qrcv_topOffset="90dp" />
    

    第三步:

    public class MainActivity extends AppCompatActivity implements QRCodeView.Delegate{
    private QRCodeView mQRCodeView ;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mQRCodeView  = findViewById(R.id.zbarview);
        mQRCodeView.setDelegate(this);
    
    }
    
    @Override
    public void onScanQRCodeSuccess(String result) {
        vibrate();
        Toast.makeText(this,result,Toast.LENGTH_SHORT).show();
        mQRCodeView.startSpot();
    }
    
    
    
    @Override
    public void onScanQRCodeOpenCameraError() {
        Toast.makeText(this,"错误",Toast.LENGTH_SHORT).show();
    }
    @Override
    protected void onStart() {
        super.onStart();
        mQRCodeView.startCamera();//打开相机
        mQRCodeView.showScanRect();//显示扫描框
        mQRCodeView.startSpot();//开始识别二维码
        //mQRCodeView.openFlashlight();//开灯
        //mQRCodeView.closeFlashlight();//关灯
    }
    
    @Override
    protected void onStop() {
        mQRCodeView.stopCamera();
        super.onStop();
    }
    
    @Override
    protected void onDestroy() {
        mQRCodeView.onDestroy();
        super.onDestroy();
    }
    
    private void vibrate() {
        Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        vibrator.vibrate(200);
    }
    
    }
    

    第四步:
    权限添加

     <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    
    展开全文
  • 更强大的二维码识别工具zBar

    千次阅读 2019-04-24 16:33:05
    代码位置:102-ScannerQRCodeWithZbar.py ...现在我们使用zBar这个开源二维码工具,它自身是C语言编写。支持多个操作系统,在Android和iPhone上支持的也很好。 我们只介绍python版本,这个版本是Open...

    《OpenCV系列教程》
    项目位置:OpenCV-Sample
    代码位置:102-ScannerQRCodeWithZbar.py
    OpenCV自带的二维码识别工具,能力较差,尤其是在如下的情况下经常识别不出来。

    现在我们使用zBar这个开源二维码工具,它自身是C语言编写。支持多个操作系统,在Android和iPhone上支持的也很好。 我们只介绍python版本,这个版本是OpenCV与zBar的结合使用。 安装zBar 首先安装zBar的二进制版本。
    sudo apt-get install libzbar-dev
    

    然后安装zBar的Python包

    pip install pyzbar
    

    实际代码如下:

    from __future__ import print_function
    import pyzbar.pyzbar as pyzbar
    import numpy as np
    import cv2
    
    
    def decode(im):
        # 在这里查找二维码
        decodedObjects = pyzbar.decode(im)
    
        # 打印出结果
        for obj in decodedObjects:
            print('Type : ', obj.type)
            print('Data : ', obj.data, '\n')
    
        return decodedObjects
    
    
    def display(im, decodedObjects):
    
        for decodedObject in decodedObjects:
            points = decodedObject.polygon
    
            if len(points) > 4:
                hull = cv2.convexHull(np.array([point for point in points], dtype=np.float32))
                hull = list(map(tuple, np.squeeze(hull)))
            else:
                hull = points;
    
    
            n = len(hull)
    
            for j in range(0, n):
                cv2.line(im, hull[j], hull[(j + 1) % n], (255, 0, 0), 3)
    
        cv2.imshow("Results", im);
        cv2.waitKey(0);
    
    # Read image
    im = cv2.imread('./res/QR3.jpeg')
    decodedObjects = decode(im)
    display(im, decodedObjects)
    
    展开全文
  • java实现二维码识别(ZBar)

    千次阅读 2019-09-04 13:59:15
    要求:系统Centos7.x 第一步安装Cmake yum install -y gcc gcc-c++ wget wget https://cmake.org/files/v3.14/cmake-3.14.0.tar.gz tar -zxvf cmake-3.14.0.tar.gz cd cmake-3.14.0 ./bootstrap ...rm -r...

    要求:系统Centos7.x

    第一步安装Cmake

    yum install -y gcc gcc-c++ wget
    wget https://cmake.org/files/v3.14/cmake-3.14.0.tar.gz
    tar -zxvf cmake-3.14.0.tar.gz
    cd cmake-3.14.0
    ./bootstrap
    gmake
    gmake install
    
    rm -rf /usr/bin/cmake
    ln -s /usr/local/bin/cmake /usr/bin/cmake

    第二步编译libz

    tar -xvf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    mkdir build
    cd build
    touch build.sh

    build.sh

    cmake -G "Unix Makefiles" \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=/var/SDK/install/zlib \
    -D CMAKE_C_FLAGS="-fPIC" \
    -D CMAKE_CXX_FLAGS="-fPIC" ..
    chmod -R 777 build.sh
    ./build.sh
    make
    make install

    第三步编译libpng

    tar -xvf libpng-1.5.30.tar.xz
    cd libpng-1.5.30
    touch build.sh

     build.sh

    export CFLAGS="-I/var/SDK/install/zlib/include -fPIC"
    export CPPFLAGS="-I/var/SDK/install/zlib/include -fPIC"
    export LDFLAGS="-L/var/SDK/install/zlib/lib"
    ./configure --prefix=/var/SDK/install/libpng
    chmod -R 777 build.sh
    ./build.sh
    make
    make install

    第四步编译opencv

    unzip opencv-4.1.0.zip
    cd opencv-4.1.0
    mkdir build
    cd build
    touch build.sh

    build.sh

    cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/var/SDK/install/opencv \
    -D BUILD_SHARED_LIBS=OFF \
    -D WITH_FFMPEG=ON \
    -D ENABLE_CXX11=1 ..
    chmod -R 777 build.sh
    ./build.sh
    make
    make install

    第四步编译zbar

    tar -xvf zbar-0.10.tar.bz2
    cd zbar-0.10
    touch build.sh

    build.sh

    
    export CFLAGS="-I/var/SDK/install/zlib/include -fPIC"
    export CPPFLAGS="-I/var/SDK/install/zlib/include -fPIC"
    export LDFLAGS="-L/var/SDK/install/zlib/lib"
    ./configure --without-imagemagick --disable-video --without-gtk --without-qt --with-x --prefix=/var/SDK/install/zbar --without-python --without-jpeg --disable-shared --enable-static
    make 
    make install

     

    chmod -R 777 build.sh
    ./build.sh
    make
    make install

    第五步编译c++的二维码识别程序

    mkdir /var/SDK/project/zbar
    cd /var/SDK/project/zbar
    touch CMakeLists.txt
    touch opencv_core.h
    touch opencv_core.cpp
    touch zbar_core.h
    touch zbar_core.cpp
    touch test.cpp

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.4.1)
    set(CMAKE_CXX_STANDARD 11)
     
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
     
    add_library(libittnotify STATIC IMPORTED)
    set_target_properties(libittnotify PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/libittnotify.a)
     
    add_library(libquirc STATIC IMPORTED)
    set_target_properties(libquirc PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/libquirc.a)
     
    add_library(liblibprotobuf STATIC IMPORTED)
    set_target_properties(liblibprotobuf PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/liblibprotobuf.a)
     
    add_library(libIlmImf STATIC IMPORTED)
    set_target_properties(libIlmImf PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/libIlmImf.a)
     
    add_library(liblibjasper STATIC IMPORTED)
    set_target_properties(liblibjasper PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/liblibjasper.a)
     
    add_library(liblibwebp STATIC IMPORTED)
    set_target_properties(liblibwebp PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/liblibwebp.a)
     
    add_library(liblibtiff STATIC IMPORTED)
    set_target_properties(liblibtiff PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/liblibtiff.a)
     
    add_library(liblibjpeg-turbo STATIC IMPORTED)
    set_target_properties(liblibjpeg-turbo PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/opencv4/3rdparty/liblibjpeg-turbo.a)
     
    add_library(libopencv_video STATIC IMPORTED)
    set_target_properties(libopencv_video PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_video.a)
     
    add_library(libopencv_stitching STATIC IMPORTED)
    set_target_properties(libopencv_stitching PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_stitching.a)
     
    add_library(libopencv_objdetect STATIC IMPORTED)
    set_target_properties(libopencv_objdetect PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_objdetect.a)
     
    add_library(libopencv_calib3d STATIC IMPORTED)
    set_target_properties(libopencv_calib3d PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_calib3d.a)
     
    add_library(libopencv_features2d STATIC IMPORTED)
    set_target_properties(libopencv_features2d PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_features2d.a)
     
    add_library(libopencv_dnn STATIC IMPORTED)
    set_target_properties(libopencv_dnn PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_dnn.a)
     
    add_library(libopencv_photo STATIC IMPORTED)
    set_target_properties(libopencv_photo PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_photo.a)
     
    add_library(libopencv_ml STATIC IMPORTED)
    set_target_properties(libopencv_ml PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_ml.a)
     
    add_library(libopencv_flann STATIC IMPORTED)
    set_target_properties(libopencv_flann PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_flann.a)
     
    add_library(libopencv_highgui STATIC IMPORTED)
    set_target_properties(libopencv_highgui PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_highgui.a)
     
    add_library(libopencv_videoio STATIC IMPORTED)
    set_target_properties(libopencv_videoio PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_videoio.a)
     
    add_library(libopencv_imgcodecs STATIC IMPORTED)
    set_target_properties(libopencv_imgcodecs PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_imgcodecs.a)
     
    add_library(libopencv_imgproc STATIC IMPORTED)
    set_target_properties(libopencv_imgproc PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_imgproc.a)
     
    add_library(libopencv_core STATIC IMPORTED)
    set_target_properties(libopencv_core PROPERTIES IMPORTED_LOCATION /var/SDK/install/opencv/lib64/libopencv_core.a)
     
    add_library(libzbar STATIC IMPORTED)
    set_target_properties(libzbar PROPERTIES IMPORTED_LOCATION /var/SDK/install/zbar/lib/libzbar.a)
     
    add_library(libz STATIC IMPORTED)
    set_target_properties(libz PROPERTIES IMPORTED_LOCATION /var/SDK/install/zlib/lib/libz.a)
     
    add_library(libpng15 STATIC IMPORTED)
    set_target_properties(libpng15 PROPERTIES IMPORTED_LOCATION /var/SDK/install/libpng/lib/libpng15.a)
     
    message("include 头文件目录")
    include_directories(/var/SDK/install/opencv/include/opencv4)
    include_directories(/var/SDK/install/zbar/include)
    include_directories(/var/java/jdk1.8.0_221/include)
    include_directories(/var/java/jdk1.8.0_221/include/linux)
    include_directories(${SRC_ROOT_PATH}/)
     
    message("设置源码根路径,即 cpp 目录")
    set(SRC_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
    message(${SRC_ROOT_PATH})
     
    message("定义要编译的文件列表变量")
     file(GLOB CPP_FILES_IN_UTILS "${SRC_ROOT_PATH}/*.cpp")
     
    message("设置要编译的源文件")
    set(SOURCE_FILES ${CPP_FILES_IN_UTILS})
     
    add_library(qrcode2 SHARED ${SOURCE_FILES})
     
    target_link_libraries(
    qrcode2
    libzbar
    libopencv_video
    libopencv_stitching
    libopencv_objdetect
    libopencv_calib3d
    libopencv_features2d
    libopencv_dnn
    libopencv_photo
    libopencv_ml
    libopencv_flann
    libopencv_highgui
    libopencv_videoio
    libopencv_imgcodecs
    libopencv_imgproc
    libopencv_core
    libittnotify
    libquirc
    liblibprotobuf
    libIlmImf
    liblibjasper
    liblibwebp
    liblibtiff
    liblibjpeg-turbo
    libpng15
    libz
    )

     zbar_core.h

    #pragma once
    char * decodeByZbar(const char* fromPath);

    zbar_core.cpp

    #ifndef zxing_parse_h
    #define zxing_parse_h
    #include "zbar.h"      
    #include <iostream>
    #include "zbar_core.h"
    #include "opencv2/opencv.hpp"
    #endif
    using namespace std;
    using namespace zbar;  //添加zbar名称空间    
    using namespace cv;
    char * decodeByZbar(const char* fromPath) {
    	ImageScanner scanner;
    	scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    	cv::Mat image = cv::imread(fromPath, 1);
    	if (!image.data) {
    		return nullptr;
    	}
    	Mat imageGray;
    	cvtColor(image, imageGray, COLOR_RGB2GRAY);
    	int width = imageGray.cols;
    	int height = imageGray.rows;
    	uchar* raw = (uchar*)imageGray.data;
    	Image imageZbar(width, height, "Y800", raw, width * height);
    	scanner.scan(imageZbar); //扫描条码    
    	Image::SymbolIterator symbol = imageZbar.symbol_begin();
    	if (imageZbar.symbol_begin() == imageZbar.symbol_end())
    	{
    		cout << "查询条码失败,请检查图片!" << endl;
    	}
          string result;
    	for (; symbol != imageZbar.symbol_end(); ++symbol)
    	{
    		//cout << "类型:" << endl << symbol->get_type_name() << endl << endl;
    		//cout << "条码:" << endl << symbol->get_data() << endl << endl;
    		result= symbol->get_data();
    	}
    	imageZbar.set_data(NULL, 0);
     
          const int len = result.length();
          char* c=(char *)malloc(sizeof(char *) * len);
    
    	strcpy(c,result.c_str());
          
         return c;
    }

     opencv_core.h

    #pragma once
    int opencv_detail(const char* fromPath,const char* toPath);

    opencv_core.cpp

    #ifndef opencv_core_h
    #define opencv_core_h
     
     
    #include <iostream>
    #include "opencv2/opencv.hpp"
    #include "opencv_core.h"
     
    #endif 
     
    using namespace cv;
    using namespace std;
     
    int opencv_detail(const char* fromPath,const char* toPath)
    {
    	Mat src = imread(fromPath);
    	if (src.empty()) {
    		printf("error");
    		return -1;
    	}
     
    	Mat gray;
    	cvtColor(src, gray, COLOR_RGB2GRAY);
     
     
    	Mat binary;
    	threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU);
     
    	vector<vector<Point>> contours;
    	vector<Vec4i> hireachy;
    	findContours(binary.clone(), contours, hireachy, RETR_TREE, CHAIN_APPROX_NONE, Point());
     
    	vector<vector<Point>> filter1;
     
    	int ic = 0;
    	int parentIdx = -1;
     
    	for (int i = 0; i < contours.size(); i++)
    	{
    		if (hireachy[i][2] != -1 && ic == 0)
    		{
    			parentIdx = i;
    			ic++;
    		}
    		else if (hireachy[i][2] != -1)
    		{
    			ic++;
    		}
    		else if (hireachy[i][2] == -1)
    		{
    			if (ic == 2) {
    				RotatedRect rect1 = minAreaRect(contours[parentIdx]);
    				RotatedRect rect2 = minAreaRect(contours[parentIdx + 1]);
    				RotatedRect rect3 = minAreaRect(contours[parentIdx + 2]);
    				if (rect1.size.width / rect1.size.height > 0.85) {
    					if ((rect1.size.width - rect2.size.width) / 2 + (rect2.size.width - rect3.size.width) / 2 < rect3.size.width) {
    						filter1.push_back(contours[parentIdx]);
    					}
    				}
    			}
    			parentIdx = -1;
    			ic = 0;
    		}
    	}
     
    	if (filter1.size() < 3) {
    		//imshow("input_image", src);
    		imwrite(toPath, src);
     
    	//	waitKey();
    		return 0;
    	}
    	RotatedRect minRect1 = minAreaRect(Mat(filter1[0]));
    	RotatedRect minRect2 = minAreaRect(Mat(filter1[1]));
    	RotatedRect minRect3 = minAreaRect(Mat(filter1[2]));
    	int minLeft = min(min(minRect1.center.x, minRect2.center.x), minRect3.center.x);
    	int maxLeft = max(max(minRect1.center.x, minRect2.center.x), minRect3.center.x);
    	int minTop = min(min(minRect1.center.y, minRect2.center.y), minRect3.center.y);
    	int maxTop = max(max(minRect1.center.y, minRect2.center.y), minRect3.center.y);
    	int rectWidth = minRect1.size.width / 2;
    	Rect rect(minLeft - rectWidth, minTop - rectWidth, maxLeft - minLeft + minRect1.size.width, maxLeft - minLeft + minRect1.size.width);
    	Mat mat = src(rect);
    	//namedWindow("input_image", WINDOW_AUTOSIZE);
    	//imshow("input_image", mat);
    	imwrite(toPath, mat);
     
    	//waitKey();
    	return 0;
    }

     test.cpp

    
    #include "jni.h"
    #ifndef dllmain_h
    #define dllmain_h 
    #include <string.h>
    #include "opencv_core.h"
    #include "zbar_core.h"
    #endif
     
    #define FROM_PATH_NULL -1001
    #define TO_PATH_NULL -1002
     
    #include <iostream>       
    using namespace std;  //这两个支持linux cout
    extern "C" {
    	JNIEXPORT jstring JNICALL Java_com_java_wjs_opencv_qr_QRScan_decodeByZbar(JNIEnv* env, jobject jobj, jstring fromPath) {
                jboolean b=false;
    		const char* fromPathStr = env->GetStringUTFChars(fromPath, &b);
    		if (fromPathStr == NULL || strlen(fromPathStr) == 0 || fromPathStr[0] == '\0') {
    			return env->NewStringUTF("-1001");
    		}
              char* result=decodeByZbar(fromPathStr);
              if (result != NULL) {
    			env->ReleaseStringUTFChars(fromPath, fromPathStr);
                            jstring rt=env->NewStringUTF(result);
                       free(result);
    			return rt;
    	 }
    		return env->NewStringUTF("-1003");
    	}
    }

    编写 QRScan.java

    package com.java.wjs.opencv.qr;
     
    public class QRScan {
        static {
            System.loadLibrary("qrcode2");
        }
        public native String decodeByZbar(String fromPath);
    }

    编写Main.java

    package com.java.wjs.opencv.qr;
    public class Main {
        private static final String PATH_PHOTO="/home/admin/test.png";
        long tempTime = System.currentTimeMillis();
        public static final void main(String[] args){
            QRScan qrScan = new QRScan();
            String result=qrScan.decodeByZbar(PATH_PHOTO);
            System.out.println("result:"+result);
    	  Main main=new Main();
            main.printTime("寻找二维码所用时间");
     
        }
        public void printTime(String time){
            System.out.println(time+ (System.currentTimeMillis() - tempTime));
            tempTime=System.currentTimeMillis();
        }
    }

    配置环境变量LD_LIBRARY_PATH指向so

    展开全文
  • Zxing与 Zbar生成二维码最简单的实现方式 导入依赖 implementation 'cn.bingoogolapple:bga-qrcode-zbar:1.2.1' 或者 implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.2.1' 布局文件只有个ImageView &...
  • zbar二维码识别

    千次阅读 2019-05-26 22:10:15
    // ZBar_test.cpp : 定义控制台应用程序的入口点。 #include "stdafx.h" #include "stdafx.h" #include "include\zbar.h" #include "opencv2/opencv.hpp" #include "opencv2/core.hpp" #include "highgui.h" #...
  • 二维码zbar

    2019-05-10 08:01:07
    权限 ...cn.bingoogolapple.qrcode.zbar.ZBarView android:id="@+id/zxingview" android:layout_width="match_parent" android:layout_height="match_parent" app:qrcv_animTime="1000" app...
  • Opencv+Zbar二维码识别(标准条形码/二维码识别)

    万次阅读 多人点赞 2016-08-05 23:13:40
    使用Opencv+Zbar组合可以很容易的识别图片中的二维码,特别是标准的二维码,这里标准值的是二维码成像清晰,图片中二维码的空间占比在40%~100%之间,这样标准的图片,Zbar识别起来很容易,不需要Opencv额外的处理。...
  • 用zbarxing做的快速扫描识别二维码和生成二维码,里面包括闪光灯的打开关闭,相册选择二维码识别,扫描二维码不到1秒就可扫码出来的完整demo
  • 识别率很高的二维码扫描(优化过的zbar

    万次阅读 热门讨论 2020-04-19 11:45:33
    有需要的朋友可以下载下来测试一下,识别率高、快、准:http://download.csdn.net/detail/l_xiaole/9732495
  • 1、Zbar库安装: windows 10 上安装zbar(python) OpenCV+ZBar实现条码识别(Windows32位和64位) Win10x64+Zbar_0.10+VS2015+Opencv3.0.0 https://sourceforge.net/projects/zbar/files/latest/download ...
  • 目前,许多博客二位码定位与识别是分开的,定位采用单独的图像处理算法识别出三个矩形的中心位置,识别采用开源的二位码识别库,如zbar。本文将着重来介绍一种利用zbar库自带的定位算法来定位二位码的三个定位矩形,...
  • Qt和Zbar的结合使用识别二维码条形码

    千次阅读 热门讨论 2013-09-26 22:21:53
    图像的采集使用Qt5提供的多媒体模块,条形码,二维码等等的识别使用的Zbar。 摄像头用的地摊货,晚上在灯光下的效果还行
  • Android开发之Zbar实现二维码扫描功能

    千次阅读 2017-07-13 16:06:01
    在写这篇文章之前已经写过两篇关于二维码...文章2:Android开发之利用ZXing库实现二维码的生成,这两篇文章中使用到的二维码生成库是ZXing,在本篇文章中将要介绍的是使用另一个库——Zbar来实现二维码扫描功能,至于
  • Zbar开源项目二维码识别(测试)

    万次阅读 2016-11-21 22:48:50
    为了完成大飞哥老师布置的作业,调查了一下开源的二维码识别库。我只查了Zxing、Zbar,其中Zxing在我的机器上编译调试通过,但效果并不理想,所以又换了Zbar使用一下。(我的小伙伴找到了Zxing移动端的开源库,并...
  • VC++识别QR-Code格式的二维码

    千次阅读 2017-12-02 15:54:08
    图像识别QR-Code格式的二维码编写步骤详述
  • PHP识别二维码(php-zbarcode)

    万次阅读 2015-11-06 17:17:11
    说明:扩展需要依赖ImageMagick和zbar,安装前先安装这两个软件 1.安装ImageMagick(http://www.imagemagick.org/) yum install ImageMagick.x86_64 ImageMagick-devel.x86_64 2.安装zbar...
  • c++ zbar opencv 二维码识别

    千次阅读 2016-07-04 16:50:46
    c++ opencv zbar 二维码识别
  • 二维码扫描之zxing与zbar的优劣

    万次阅读 2016-07-13 15:32:24
    之前我有移植过zbar和zxing源码到linux平台,zbar移植的是C源码,zxing移植的是C++代码。两者对比: 1.zxing支持更多的码制:datamatix、PDF417、等,zbar不能很好支持PDF417(但是在源码中有对于Pdf417码处理)...
  • 扫黑色的二维码可以识别,扫蓝色的二维码识别连聚焦都不行. 有没有好的解决方法
1 2 3 4 5 ... 20
收藏数 2,306
精华内容 922
关键字:

zbar 二维码