#include "core/core.hpp"
#include "highgui/highgui.hpp"
#include "imgproc/imgproc.hpp"
#include "video/tracking.hpp"
#include<iostream>
#include <iostream>
#include <zbar.h>
#define STR(s) #s
using namespace zbar;
using namespace cv;
using namespace std;
int main(int argc, char*argv[])
{
ImageScanner scanner;
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
Mat image = imread("../data/2code.jpg");
if (!image.data)
{
cout << "請確認圖片" << endl;
system("pause");
return 0;
}
Mat imageGray;
cvtColor(image, imageGray, CV_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;
}
for (; symbol != imageZbar.symbol_end(); ++symbol)
{
cout << "類型:" << endl << symbol->get_type_name() << endl << endl;
cout << "條碼:" << endl << symbol->get_data() << endl << endl;
}
imshow("Source Image", image);
waitKey();
imageZbar.set_data(NULL, 0);
return 0;
}
|