From 7fe273e8e8bd1ffd4735cb5d6f09ad8e58a39a96 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Mon, 29 Jul 2019 00:07:43 +0800 Subject: [PATCH] add opencv-zbar source code --- ok335xD/program/opencv-zbar/decoder.h | 19 ++++++ ok335xD/program/opencv-zbar/cvzbar.c | 14 ++++ ok335xD/program/opencv-zbar/makefile | 27 +++++++++ ok335xD/program/opencv-zbar/decoder.cpp | 64 +++++++++++++++++++++ 4 files changed, 124 insertions(+), 0 deletions(-) diff --git a/ok335xD/program/opencv-zbar/cvzbar.c b/ok335xD/program/opencv-zbar/cvzbar.c new file mode 100644 index 0000000..812947e --- /dev/null +++ b/ok335xD/program/opencv-zbar/cvzbar.c @@ -0,0 +1,14 @@ +#include<stdio.h> +#include"decoder.h" + +int main() +{ + struct code_msg msg; + + if(decoder(0,&msg)<0) + return -1; + + printf("type:%s\n",msg.get_type_name); + printf("data:%s\n",msg.get_data); + return 0; +} diff --git a/ok335xD/program/opencv-zbar/decoder.cpp b/ok335xD/program/opencv-zbar/decoder.cpp new file mode 100644 index 0000000..79663e0 --- /dev/null +++ b/ok335xD/program/opencv-zbar/decoder.cpp @@ -0,0 +1,64 @@ +#include<string.h> +#include<iostream> +#include<opencv2/core.hpp> +#include<opencv2/highgui.hpp> +#include<opencv2/imgproc.hpp> +#include<zbar.h> +#include"decoder.h" + +using namespace std; +using namespace cv; +using namespace zbar; + +int decoder(int carame_num,struct code_msg* code_msg) +{ + Mat image; + VideoCapture capture(carame_num); + int flag = 0; + + if(!capture.isOpened()) + { + cout<<"Open Camera failure"<<endl; + return -1; + } + cout << "Open Camera ok"<<endl; + + while(!flag) + { + capture >> image;//读取视频帧 + if(!image.empty()) + { + cout << "Get video framer from camera"<<endl; + + +#if 0 //置1打开图形窗口进行对焦等操作 + imshow("source",image); +#endif + cvtColor(image,image,CV_RGB2GRAY);//灰度图 + // imshow("imageGray",image); + // cout << "灰度图转换成功"<<endl; + + //zbar解码 + int width = image.cols; + int heigth = image.rows; + uchar *raw = (uchar *)image.data; + Image imagezbar(width,heigth,"Y800",raw,width*heigth); + ImageScanner scanner; + scanner.scan(imagezbar); + Image::SymbolIterator symbol = imagezbar.symbol_begin(); + for(;symbol != imagezbar.symbol_end();++symbol)//解码成功 + { + //cout << "type:" <<symbol->get_type_name()<<endl; + strcpy(code_msg->get_type_name,symbol->get_type_name().c_str()); + //cout << "data:" <<symbol->get_data()<<endl; + strcpy(code_msg->get_data,symbol->get_data().c_str()); + flag = 1; + } + + } + //if(waitKey(10) == 0x0d) + // break; + } + return 0; +} + diff --git a/ok335xD/program/opencv-zbar/decoder.h b/ok335xD/program/opencv-zbar/decoder.h new file mode 100644 index 0000000..e217754 --- /dev/null +++ b/ok335xD/program/opencv-zbar/decoder.h @@ -0,0 +1,19 @@ +#ifndef _DECODER_H_ +#define _DECODER_H_ + +struct code_msg{ + char get_type_name[10]; + char get_data[20]; +}; + +#ifdef __cplusplus +extern "C"{ +#endif + +int decoder(int carame_num,struct code_msg* code_msg); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ok335xD/program/opencv-zbar/makefile b/ok335xD/program/opencv-zbar/makefile new file mode 100644 index 0000000..1de7f7d --- /dev/null +++ b/ok335xD/program/opencv-zbar/makefile @@ -0,0 +1,27 @@ +APPNAME=cvzbar + +CROSSTOOL=/opt/crosstool/cortex-a7/bin/arm-linux-gnueabi- +GPP=${CROSSTOOL}g++ +GCC=${CROSSTOOL}gcc + +PRJ_PATH=${shell pwd} + +LIBS_PATH=${PRJ_PATH}/../../3rdparty/install +OPENCV_PKGCONFIG=${LIBS_PATH}/lib/pkgconfig + +CPPFLAGS = `export PKG_CONFIG_PATH=${OPENCV_PKGCONFIG} && pkg-config --cflags --libs opencv` +CFLAGS+=-I${LIBS_PATH}/include +LDFLAGS=-L${LIBS_PATH}/lib -lzbar -liconv + +all: + echo $PKG_CONFIG_PATH + ${GPP} ${CFLAGS} -c decoder.cpp -o decoder.o $(CPPFLAGS) -Wall + ${GCC} -c cvzbar.c -Wall + ${GPP} decoder.o cvzbar.o -o ${APPNAME} $(CPPFLAGS) -lstdc++ ${LDFLAGS} + cp ${APPNAME} /tftp + +clean: + rm -f *.o ${APPNAME} + +distclean: clean + rm -f cscope* tags -- Gitblit v1.9.1