CV算子之识别条形码,将其做在相机一直拿图程序里面,看看效率以及延迟
测试zbar识别一帧图像215ms左右,优化zbar识别程序,减少它识别的类别,一帧图像 165ms左右
该程序基于QT写的
ubuntu安装zbar
sudo apt-get install libzbar-dev
.pro
LIBS += /usr/lib/x86_64-linux-gnu/libzbar.so.0.2.0
.cpp
#include <zbar.h>
using namespace zbar;
#ifdef cvTool
QDateTime current_date_time = QDateTime::currentDateTime();
QString start_time = current_date_time.toString("yyyy.MM.dd hh:mm:ss.zzz");
qDebug() << "start_time:" << start_time << endl;
long long MSec_time = QDateTime::currentDateTime().toMSecsSinceEpoch();
cv::Mat grayImg;
//output_img是相机的原始图像
pyrDown(output_img,output_img);
cvtColor(output_img,grayImg,cv::COLOR_BGR2GRAY);
int cv_width = grayImg.cols;
int cv_height = grayImg.rows;
uchar *raw = (uchar *)(grayImg.data);
Image image( cv_width, cv_height, "Y800", raw, cv_width*cv_height);
ImageScanner scanner;
scanner.set_config(ZBAR_NONE,ZBAR_CFG_ENABLE,0);
scanner.set_config(ZBAR_EAN13,ZBAR_CFG_ENABLE,1);
scanner.scan((image));
int counter =0;
int i=0;
for(Image::SymbolIterator symbol = image.symbol_begin();symbol!=image.symbol_end();++symbol)
{
string text =to_string(counter++)+"-" +symbol->get_type_name()+": "+symbol->get_data();
putText(output_img,text,cv::Point(10,50*counter),cv::FONT_HERSHEY_PLAIN,5,cv::Scalar(0,0,255),1);
i++;
}
qDebug() << "Processing speed:" << QDateTime::currentDateTime().toMSecsSinceEpoch() - MSec_time << "ms" << endl;
#endif