您的位置:首页 > 运维架构

二维码解析库zbar+openCV的移植和使用

2017-09-21 14:53 423 查看
-----------------------------

1. zbar linux-X86平台编译

-----------------------------

./configure --without-imagemagick --disable-video --without-qt --without-gtk --without-x --without-python --exec-prefix=/mnt/view/dsp_rv1108/app/qrdecoder/install --prefix=/mnt/view/dsp_rv1108/app/qrdecoder/install

make

make install 

---------------------------------

2. zbar linux-ARM平台交叉编译

---------------------------------

CC=arm-linux-gcc ./configure --host=arm-linux --without-imagemagick --disable-video --without-qt --without-gtk --without-x --without-python --exec-prefix=/mnt/view/dsp_rv1108/app/qrdecoder_cross_compile/install --prefix=/mnt/view/dsp_rv1108/app/qrdecoder_cross_compile/install
LIBS=-L/mnt/view/dsp_rv1108/app/qrdecoder_cross_compile/libs/lib CPPFLAGS=-I/mnt/view/dsp_rv1108/app/qrdecoder_cross_compile/libs/include 

make

make install

其中:
CC 指定交叉gcc编译器名称
CPP 指定交叉g++编译器名称
--host 指定目标平台
--prefix 指定install 路径
LIBS=-L 指定编译时依赖的库路径 (可选)
CFLAGS CPPFLAGS 指定编译时的自定义头文件路径 (可选)

--------------------------------

3. linux-x86平台测试用例编译

--------------------------------

cd 到 release 文件夹下

make
./qrdecoder xxdk.png

对应的Makefile:

备注:确保PC平台已经安装openCV

SRCS = $(wildcard *.cpp)    # wildcard把 指定目录 ./ 下的所有后缀是cpp的文件全部展开。
OBJS = $(SRCS:.cpp = .o)    # OBJS将$(SRCS)下的.cpp文件转化为.o文件
CXX = g++                   # 代表所使用的编译器
INCLUDES = -I/usr/local/include/opencv -I.    # 头文件查找路径
LIBS =  -L/usr/local/lib \
-lzbar \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_imgcodecs                    # 链接库查找地址
CXXFLAGS = -g -Wall -O0   #附加参数
OUTPUT = qrdecoder   	  #输出程序名称

all:$(OUTPUT)
$(OUTPUT) : $(OBJS)
$(CXX) $^ -o $@ $(INCLUDES) $(LIBS)

%.o : %.cpp
$(CXX) -c $< $(CXXFLAGS)

.PHONY:clean
clean:
rm -rf *.out *.o qrdecoder    #清除中间文件及生成文件
--------------------------------

4. linux-ARM平台测试用例编译

--------------------------------

cd 到 release 文件夹下

make

编译完自动拷贝到SD卡

./qrdecoder xxdk.png

对应的Makefile:

注意:此处用到opencv的静态库,以及其他makefile中的静态库需要提前编译

SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp = .o)
CXX = ../../../prebuilts/toolschain/usr/bin/arm-linux-g++
STRIP = ../../../prebuilts/toolschain/usr/bin/arm-linux-strip

INCLUDES = 	-I../../../external/libopencv/include/opencv \
-I../../../external/libopencv/include/opencv2/core \
-I../../../external/libopencv/include/opencv2 \
-I../../../external/libopencv/include \
-I../../../external/libopencv \
-I../libs/include \
-I../libs/include/zbar \
-I.
LIBS =  -L../../../external/libopencv \
-L../libs/lib \
-L../ \
-L. \
-lopencv_imgcodecs \
-lopencv_imgproc \
-lopencv_core \
-lopencv_highgui \
-lzbar \
-lz \
-liconv \
-lpthread \
-ltiff \
-ljpeg \
-llibjasper \
#-llibjpeg \
#-llibtiff \
#-ltiffxx \
#-lpng \

#CXXFLAGS = -g -Wall -O0
OUTPUT = qrdecoder

all:$(OUTPUT)
$(OUTPUT) : $(OBJS)
$(CXX) $^ -o $@ $(INCLUDES) $(LIBS)
$(STRIP) $(OUTPUT)
@if [ -d /media/qfeel/56A0-9C18 ]; then \
rm /media/qfeel/56A0-9C18/qrdecoder; \
mv $(OUTPUT) /media/qfeel/56A0-9C18; \
else \
rm $(OUTPUT); \
echo "please insert sd card!"; \
fi

%.o : %.cpp
$(CXX) -c $< $(CXXFLAGS)

.PHONY:clean
clean:
rm -rf *.out *.o qrdecoder


通用的测试用例:

#include <cv.h>
#include <zbar.h>
#include <iostream>
#include <highgui.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace zbar;
using namespace cv;

int main(int argc, char*argv[])
{
if(argc != 2) {
cout << "usage: qrdecoder <picture-name> " << endl;
return 0;
}
//
// 实例化扫描器对象,并配置
//
ImageScanner scanner;
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
//
// 读取图片
//
Mat imageGray = imread(argv[1], 0);
//
// 图像灰度化
//
//cvtColor(image, imageGray, CV_RGB2GRAY);
int width = imageGray.cols;
cout << "width = "<< width << endl;
cout << 3 << endl;
int height = imageGray.rows;
cout << "height = "<< height << endl;
uchar *raw = (uchar *)imageGray.data;
//
// 实例化Image对象, 按照"Y800"格式构造
// imageZbar 对象, 并讲图像数据传入该对象
//
cout << 4 << endl;
Image imageZbar(width, height, "Y800", raw, width * height);
//
// 调度扫描器扫描Image对象imageZber
//
cout << 5 << endl;
scanner.scan(imageZbar);
Image::SymbolIterator symbol = imageZbar.symbol_begin();
if(imageZbar.symbol_begin() == imageZbar.symbol_end()) {
cout << 6 << endl;
cout<<"decode error, check image!"<<endl;
}

cout << 7 << endl;
for(; symbol != imageZbar.symbol_end(); ++symbol) {
cout << 8 << endl;
cout << "code type: " << symbol->get_type_name() << endl;
cout << "code data: " << symbol->get_data() << endl;
}
//  imshow("XXDK Image", image);
//  waitKey();
imageZbar.set_data(NULL, 0);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  二维码 zbar