精华内容
下载资源
问答
  • 本文是上篇博文的进阶,Zbar+ROS+opencv二维码识别与定位研究(一) 1.首先下载Zbar的源代码源代码链接 在ubuntu下,用命令行的方式在官网下载 $wget http://downloads.sourceforge.net/zbar/0.10/zbar-0.10.tar.bz2...

    本文是上篇博文的进阶,Zbar+ROS+opencv二维码识别与定位研究(一)

    1.首先下载Zbar的源代码源代码链接

    在ubuntu下,用命令行的方式在官网下载

    $wget http://downloads.sourceforge.net/zbar/0.10/zbar-0.10.tar.bz2

    2.安装相关包

    $sudo apt install python-gtk2 python-gtk2-dev libmagickwand-dev imagemagick autoconf libv4l-dev

    3.设置和编译

    $sudo ln -s /usr/include/libv4l1-videodev.h   /usr/include/linux/videodev.h
    $tar xf zbar-0.10.tar.bz2
    $cd zbar-0.10
    $sed -i 's|linux/videodev.h|libv4l1-videodev.h|g' zbar/video/v4l1.c include/config.h.in configure.ac configure
    $./configure --prefix=/usr --without-gtk --without-python
    $make
    $sudo make install

    注意:如果make的时候报错:

    在./configure上增加一行

    $export CFLAGS=""  

     

    4.测试一下

     

    $zbarimg 111.jpeg//111.jpeg为测试二维码

    显示结果:

    ubuntu@xxxx:~/图片$ zbarimg 111.jpeg

    QR-Code:http://weixin.qq.com/r/d0iJkerEhrf5ra7y9x1l
    scanned 1 barcode symbols from 1 images in 0.06 seconds

     

    1)工程环境:QT+C++

    2)编译方法:CMake

    3)用到的opencv和zbar库

    CMakeList.txt文件:

    cmake_minimum_required(VERSION 2.8.3)
    project(zbar_opencv)
    set(CMAKE_MODULE_PATH ${ZBARCV_SOURCE_DIR})
    find_package (OpenCV)
    find_package(catkin REQUIRED COMPONENTS
      cv_bridge##ros的数据转化成opencv数据,再用opencv处理
      image_transport
      roscpp
      sensor_msgs
      std_msgs
    )
    
    find_package(PkgConfig)
    pkg_check_modules(PC_ZBAR QUIET zbar)
    set(ZBAR_DEFINITIONS ${PC_ZBAR_CFLAGS_OTHER})
    find_library(ZBAR_LIBRARIES NAMES zbar
                 HINTS ${PC_ZBAR_LIBDIR} ${PC_ZBAR_LIBRARY_DIRS} )
    find_path(ZBAR_INCLUDE_DIR Decoder.h
              HINTS ${PC_ZBAR_INCLUDEDIR} ${PC_ZBAR_INCLUDE_DIRS}
              PATH_SUFFIXES zbar )
    include(FindPackageHandleStandardArgs)
    find_package_handle_standard_args(ZBAR  DEFAULT_MSG  ZBAR_LIBRARIES ZBAR_INCLUDE_DIR)
    catkin_package(
     INCLUDE_DIRS include
      LIBRARIES zbar_opencv
    )
    include_directories(
        include
      ${catkin_INCLUDE_DIRS}
    )
    
    add_executable(zbar_opencv src/zbar_opencv.cpp)
    target_link_libraries(zbar_opencv
      ${catkin_LIBRARIES}
      ${OpenCV_LIBRARIES}
     # ${Zbar_LIBRARIES}
      /usr/lib/libzbar.so##最重要的添加编译用的共享库
    
    )

    1)在主程序zbar_opencv.cpp里面自定义类,实现将usb摄像头采集回来的/usb_cam/image_raw,通过cv_ptr=cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::BGR8);使用image_transport订阅图像话题“in” 和 发布图像话题“out” /camera/rgb/image_raw

    2)转换完了以后,用opencv的方法,调用gradient.cpp,查看具体实现在开头链接

    3)最后用定位好的图像传入zbarscanner()里面进行扫描识别

    zbar_opencv.cpp如下:

    class ImageConverter
    {
        ros::NodeHandle nh;
    
        image_transport::ImageTransport it;
        image_transport::Subscriber image_sub;
        image_transport::Publisher image_pub;
    
      public:
        ImageConverter():it(nh)
        {
            //使用image_transport订阅图像话题“in” 和 发布图像话题“out” /camera/rgb/image_raw
            image_sub=it.subscribe("/usb_cam/image_raw",1,&ImageConverter::imageCb,this);
            image_pub=it.advertise("zbar_opencv",1);
    
        }
    
        ~ImageConverter(){}
    
        //订阅回调函数
        void imageCb(const sensor_msgs::ImageConstPtr& msg)
        {
            cv_bridge::CvImagePtr cv_ptr;
            try
            {
                //将ROS图像消息转化为适合Opencv的CvImage
                cv_ptr=cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::BGR8);
    
            }
            catch(cv_bridge::Exception& e)
            {
                ROS_ERROR("cv_bridge exception: %s",e.what());
                return;
            }
            //梯度运算
            cv_ptr=gradient(cv_ptr);
            //水平投影法
            // projection(cv_ptr);
            zbarscanner(cv_ptr);
            // printf("OK1\n");
            image_pub.publish(cv_ptr->toImageMsg());
        }
    };
    

     

    展开全文
  • ROS:zbar+opencv 二维码识别

    千次阅读 热门讨论 2017-03-28 17:18:40
    zbar+opencv

    一、zbar安装
    1.下载zabr:zbar官网
    GitHub
    或命令行直接下载

    wget http://downloads.sourceforge.net/zbar/0.10/zbar-0.10.tar.bz2

    2.解压安装
    预先安装以下包

    sudo apt install python-gtk2 python-gtk2-dev libmagickwand-dev imagemagick autoconf libv4l-dev

    设置

    sudo ln -s /usr/include/libv4l1-videodev.h   /usr/include/linux/videodev.h

    安装

    tar xf zbar-0.10.tar.bz2
    cd zbar-0.10
    sed -i 's|linux/videodev.h|libv4l1-videodev.h|g' zbar/video/v4l1.c include/config.h.in configure.ac configure
    export CFLAGS=""
    ./configure --prefix=/usr --without-gtk --without-python
    make
    sudo make install

    二、代码
    1.zbar_opencv.cpp

    #include <ros/ros.h>
    #include <image_transport/image_transport.h>
    #include <cv_bridge/cv_bridge.h>
    #include <sensor_msgs/image_encodings.h>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <zbar.h>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    using namespace cv;
    using namespace zbar;
    //static const std::string OPENCV_WINDOW="Image window";
    
    void zbarscanner(cv_bridge::CvImagePtr cv_ptr)
    {
            // Create a zbar reader
        ImageScanner scanner;
    
        // Configure the reader
        scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    
    
            // Capture an OpenCV frame
            cv::Mat frame,frame_grayscale;
            frame=cv_ptr->image;
            // Convert to grayscale
            cvtColor(frame, frame_grayscale, CV_BGR2GRAY);
    
            // Obtain image data
            int width = frame_grayscale.cols;
            int height = frame_grayscale.rows;
            uchar *raw = (uchar *)(frame_grayscale.data);
    
            // Wrap image data
            Image image(width, height, "Y800", raw, width * height);
    
            // Scan the image for barcodes
    //
            scanner.scan(image);
    
            // Extract results
            int counter = 0;
            for (Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
                cout<< symbol->get_data() << endl;
                // Draw location of the symbols found
                if (symbol->get_location_size() == 4) {
    
                    line(frame, Point(symbol->get_location_x(0), symbol->get_location_y(0)), Point(symbol->get_location_x(1), symbol->get_location_y(1)), Scalar(0, 255, 0), 2, 8, 0);
                    line(frame, Point(symbol->get_location_x(1), symbol->get_location_y(1)), Point(symbol->get_location_x(2), symbol->get_location_y(2)), Scalar(0, 255, 0), 2, 8, 0);
                    line(frame, Point(symbol->get_location_x(2), symbol->get_location_y(2)), Point(symbol->get_location_x(3), symbol->get_location_y(3)), Scalar(0, 255, 0), 2, 8, 0);
                    line(frame, Point(symbol->get_location_x(3), symbol->get_location_y(3)), Point(symbol->get_location_x(0), symbol->get_location_y(0)), Scalar(0, 255, 0), 2, 8, 0);
                }
    
                counter++;
            }
    
    }
    
    class ImageConverter
    {
        ros::NodeHandle nh;
    
        image_transport::ImageTransport it;
        image_transport::Subscriber image_sub;
        image_transport::Publisher image_pub;
    
      public:
        ImageConverter():it(nh)
        {
            //使用image_transport订阅图像话题“in” 和 发布图像话题“out”
            image_sub=it.subscribe("/camera/rgb/image_raw",1,&ImageConverter::imageCb,this);
            image_pub=it.advertise("zbar_opencv",1);
    
        }
    
        ~ImageConverter(){}
    
        //订阅回调函数
        void imageCb(const sensor_msgs::ImageConstPtr& msg)
        {
            cv_bridge::CvImagePtr cv_ptr;
            try
            {
                //将ROS图像消息转化为适合Opencv的CvImage
                cv_ptr=cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::BGR8);
            }
            catch(cv_bridge::Exception& e)
            {
                ROS_ERROR("cv_bridge exception: %s",e.what());
                return;
            }
    
            zbarscanner(cv_ptr);
            image_pub.publish(cv_ptr->toImageMsg());
        }
    };
    
    
    int main(int argc, char **argv) {
    
        ros::init(argc,argv,"zbar_opencv");
        ImageConverter ic;
        ros::spin();
        return 0;
    }

    2.CMakeLists.txt

    cmake_minimum_required(VERSION 2.8.3)
    project(zbar_opencv)
    set(CMAKE_MODULE_PATH ${ZBARCV_SOURCE_DIR})
    find_package (OpenCV)
    find_package (ZBar0)
    find_package(catkin REQUIRED COMPONENTS
      cv_bridge
      image_transport
      roscpp
      sensor_msgs
      std_msgs
    )
    
    find_package(PkgConfig)
    pkg_check_modules(PC_ZBAR QUIET zbar)
    set(ZBAR_DEFINITIONS ${PC_ZBAR_CFLAGS_OTHER})
    find_library(ZBAR_LIBRARIES NAMES zbar 
                 HINTS ${PC_ZBAR_LIBDIR} ${PC_ZBAR_LIBRARY_DIRS} )
    find_path(ZBAR_INCLUDE_DIR Decoder.h
              HINTS ${PC_ZBAR_INCLUDEDIR} ${PC_ZBAR_INCLUDE_DIRS}
              PATH_SUFFIXES zbar )
    include(FindPackageHandleStandardArgs)
    find_package_handle_standard_args(ZBAR  DEFAULT_MSG  ZBAR_LIBRARIES ZBAR_INCLUDE_DIR)
    catkin_package(
    #  INCLUDE_DIRS include
    #  LIBRARIES zbar_opencv
      CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
    #  DEPENDS system_lib
    )
    include_directories(
      ${catkin_INCLUDE_DIRS}
    )
    add_executable(zbar_opencv src/zbar_opencv.cpp)
    target_link_libraries(zbar_opencv
      ${catkin_LIBRARIES}
      ${OpenCV_LIBRARIES} 
      ${ZBAR_LIBRARIES}
    )
    展开全文
  • # --coding:utf-8-- from Camera.sdk.Camera import Camera from math import sin,cos,radians,fabs import copy import time import numpy as np import cv2 def prethreatment(gray): thre =...
  • 基于Opencv二维码识别源码!效果比较可以!
  • Opencv:二维码检测与识别Python实现

    千次阅读 2019-12-24 12:10:22
    Opencv:二维码检测与识别Python实现 一、内容 二维码检测与识别 OpenCV在对象检测模块中QRCodeDetector有两个相关API分别实现二维码检测与二维码解析 检测 QRCodeDetector::detect( InputArray img, OutputArray ...

    Opencv:二维码检测与识别Python实现

    一、内容

    二维码检测与识别

    OpenCV在对象检测模块中QRCodeDetector有两个相关API分别实现二维码检测与二维码解析

    检测
    QRCodeDetector::detect(
    InputArray img,
    OutputArray points
    )const
    img 输入图像,灰度或者彩色图像
    points 得到的二维码四个点的坐标信息

    解析
    QRCodeDetector::decode(
    InputArray img,
    InputArray points,
    OutputArray straight_qrcode = noArray()
    )
    img 输入图像,灰度或者彩色图像
    points 二维码ROI最小外接矩形顶点坐标
    qrcode 输出的是二维码区域ROI图像信息
    返回的二维码utf-8字符串

    上述两个API功能,可以通过一个API调用实现,该API如下:
    QRCodeDetector::detectAndDecode(
    InputArray img,
    OutputArray points = noArray(),
    OutputArray straight_qrcode = noArray()
    )

    二、代码

    import cv2 as cv
    import numpy as np
    
    # 读取图像
    src = cv.imread("D:/vsprojects/images/er.jpg")
    cv.imshow("image", src)
    # 灰度转换
    gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
    # 检测
    qrcoder = cv.QRCodeDetector()
    # 解码
    codeinfo, points, straight_qrcode = qrcoder.detectAndDecode(gray)
    print(points)
    result = np.copy(src)
    # 描绘轮廓
    cv.drawContours(result, [np.int32(points)], 0, (0, 0, 255), 2)
    print("qrcode : %s" % codeinfo)
    # 添加文字
    cv.putText(result, "qrcode:" + str(codeinfo), (0, 20), cv.FONT_HERSHEY_SIMPLEX, .5, (255, 0, 0), 1);
    cv.imshow("result", result)
    
    cv.waitKey(0)
    cv.destroyAllWindows()

    三、结果

    1.原始图片

    在这里插入图片描述

    2.结果图片

    在这里插入图片描述
    在这里插入图片描述

    展开全文
  • 二维码识别简陋界面python opencv 该代码使用了opencv与tkinter 可以通过recongnize调用本机的摄像头进行识别,也可以通过recongnize2按钮进行输入本机路径来识别二维码, 返回值出现在终端 # -*- coding:utf-8 –*-...

    二维码识别简陋界面python opencv

    该代码使用了opencv与tkinter
    可以通过recongnize调用本机的摄像头进行识别,也可以通过recongnize2按钮进行输入本机路径来识别二维码,
    返回值出现在终端

    # -*- coding:utf-8 –*-
    import cv2
    import pyzbar.pyzbar as pyzbar
    import numpy as np
    from cv2 import cv2
    import pyzbar.pyzbar as pyzbar
    import tkinter.font as tkFont
    from tkinter import *
     
    def decodeDisplay(video):
        # 转为灰度图像
        gray = cv2.cvtColor(video, cv2.COLOR_BGR2GRAY)
        barcodes = pyzbar.decode(gray)
        for barcode in barcodes:
            # 提取二维码的位置,然后用边框标识出来在视频中
            (x, y, w, h) = barcode.rect
            cv2.rectangle(video, (x, y), (x + w, y + h), (0, 255, 0), 2)
            # 字符串转换
            barcodeData = barcode.data.decode("utf-8")
            barcodeType = barcode.type
            # 在图像上面显示识别出来的内容
            text = "{}".format(barcodeData)
            cv2.putText(video, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,1, (0, 255, 0), 2)
            # 打印识别后的内容
            print("[扫描结果] 二维码类别: {0} 内容: {1}".format(barcodeType, barcodeData))
        cv2.imshow("cam", video)
     
    def detect():
        cv2.namedWindow("cam",cv2.WINDOW_NORMAL)
        cam = cv2.VideoCapture(0)
        while True:
            # 读取当前帧
            ret, frame = cam.read()
            decodeDisplay(frame)
            # 按ESC键退出
            if(cv2.waitKey(5)==27):
                break
        cam.release()
        cv2.destroyAllWindows()
    def decodeDisplay2(path):
        # 转为灰度图像
        gray = cv2.cvtColor(path, cv2.COLOR_BGR2GRAY)
        barcodes = pyzbar.decode(gray)
        for barcode in barcodes:
            # 提取二维码的位置,然后用边框标识出来在视频中
            (x, y, w, h) = barcode.rect
            cv2.rectangle(path, (x, y), (x + w, y + h), (0, 255, 0), 2)
            # 字符串转换
            barcodeData = barcode.data.decode("utf-8")
            barcodeType = barcode.type
            # 在图像上面显示识别出来的内容
            text = "{}".format(barcodeData)
            cv2.putText(path, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,1, (0, 255, 0), 2)
            # 打印识别后的内容
            print("[扫描结果] 二维码类别: {0} 内容: {1}".format(barcodeType, barcodeData))
     
    def detect2(path):
            # 读取当前帧
        frame = cv2.imread(path)
        decodeDisplay2(frame)
        # 按ESC键退出
        cv2.waitKey(0)
        cv2.destroyAllWindows()
    
    if __name__ == '__main__':
        root=Tk()
        root['width']=720
        root['height']=600
        labels=[]
        root.geometry('460x240')
        root.title('摄像头二维码识别')
        ft1 = tkFont.Font(size=20, slant=tkFont.ITALIC)
    
        lb1 = Label(root, text='picture recongnize',bg='yellow',font = ('黑体',30))
        lb1.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.4)
    
        btn2 = Button(root, text='recongnize', command=lambda:detect(),bg='blue',font = ('黑体',18))
        btn2.place(relx=0.35, rely=0.6, relwidth=0.3, relheight=0.2)
    
        inp2 = Entry(root)
        inp2.place(relx=0.35, rely=0.5, relwidth=0.3, relheight=0.1)
    
        btn1 = Button(root, text='recongnize2', command=lambda:detect2(inp2.get()),bg='blue',font = ('黑体',18))
        btn1.place(relx=0.35, rely=0.8, relwidth=0.3, relheight=0.2)
    
        root.mainloop()
    
    展开全文
  • 基于新老版本python opencv二维码位置读取问题解决办法。 在opencv4.4版本以及之前,解码得到数据分别为 data,bbox,straight_qrcode = detector.detectAndDecode(img) #data 二维码里的数据 #bbox 二维码的四个边角...
  • 利用Opencv+Python 实现二维码识别

    千次阅读 2020-04-20 13:29:23
    准备工作: 二维码图片,我这里直接打印在了一张A4纸上,或者直接在草料网站上生成 草料二维码生成器,存放在手机上进行显示。在安装条码扫描库的时候大家注意:zbar库...利用摄像头识别二维码中的内容并打印出来,...
  • 基于ZBar,OpenCVPython二维码识别

    千次阅读 2019-04-25 21:40:39
    0 前言 今天分享一个之前做过的二维码识别,参考:https://www.pyimagesearch.com/2018/05/21/an-opencv-barcode-and-qr-code-scanner-with-zbar/ 上面那个只有Python版本,再推荐一个C++版本的: ...
  • Windows下Python+OpenCV+zbar图像识别二维码识别编译环境安装-附件资源
  • 根据Opencv的描述,OpenCV3.4.4以上版本支持二维码检测和识别! 标题函数 Opencv在对象检测模块中 QRCodeDetector 有两个相关API分别实现二维码检测与二维码解析。 检测API points = QRCodeDetector.detect(img) ...
  • Python + OpenCV4 识别二维码opencv4中集成了识别二维码的库,所以只需要简单的库函数调用就可以就可以实现识别二维码了 废话不多说直接上代码 import cv2 as cv import numpy as np img = cv.imread("D:\\...
  • OpenCV+Python二维码条形码识别

    千次阅读 2019-05-31 19:42:32
    在pycharm里安装opencv-python、pyzbar的包 简版代码识别度高,但是直接使用库函数没有任何意义,但是很实用: import cv2 import pyzbar.pyzbar as pyzbar def decodeDisplay(image): barcodes = pyzbar....
  • 树莓派自带摄像头OpenCV图像识别-二维码识别

    万次阅读 多人点赞 2017-12-23 10:37:57
    5、我们进入正题 二维码识别,我这里我们还需要装一个Python-zbar 输入命令 sudo apt-get install python-zbar 完成后直接使用下面程序运行 #!/usr/bin/env python #-*- coding: UTF-8 -*- # import ...
  • 准备工作: 二维码图片,我这里直接打印在了一张A4纸上,或者直接在草料网站上生成...利用摄像头识别二维码中的内容并打印出来,同时兼容识别条形码内容 打开pycharm开发工具,在项目中新建code.py文件,文件代码...
  • python 摄像头二维码识别
  • 在用Python通过pyzbar、OpenCV识别二维码,对部分中文内容出现乱码,通过几次尝试发现,可以在内容里添加部分中文字符,来解决这个问题!代码如下: # -*- coding:utf-8 -*- # author: Ueliang time:2020/2/11 import...
  • opencv调用微信的二维码识别引擎

    千次阅读 热门讨论 2021-02-21 22:55:29
    导读 用过二维码识别的小伙伴们...腾讯的WeChatCV团队最近开源了微信的二维码识别模型,并将这个功能添加到了opencv_contrib中,只需要简单的三行代码即可完成调用,这篇文章就来教大家如何使用 微信的二维码识别引擎解
  • Opencv+Zbar二维码识别(二维码校正)

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

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,309
精华内容 923
关键字:

opencv二维码识别python

python 订阅