開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC2015
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
1. OpenCV3.0 (載圖用)
2. ZBar條碼函式庫 http://zbar.sourceforge.net/download.html
安裝完後載入其dll和lib檔來使用
問題(Question):
想Trace ZBar 程式的流程是怎麼跑的,但沒有官方CMakelist.txt來產生VC專案
所以想在專案設定的Source Directories加入原始碼路徑以便追蹤
餵入的資料(Input):
餵入圖片
預期的正確結果(Expected Output):
可以用單步執行追完整個解碼流程
錯誤結果(Wrong Output):
追到 scanner.scan(image)裡面就進不了zbar_scan_image了
程式碼(Code):(請善用置底文網頁, 記得排版)
void DecodeByImage(void) {
char file[256] = "qr.png";
int width = 0;
int height = 0;
ImageScanner scanner;
Mat img, imgout;
uchar *raw = NULL;
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
// obtain image data
img = imread(file, 0);
cvtColor(img, imgout, CV_GRAY2RGB);
width = img.cols;
height = img.rows;
raw = (uchar *)img.data;
// wrap image data
Image image(width, height, "Y800", raw, width * height);
// scan the image for barcodes
int n = scanner.scan(image);
// extract results
for (Image::SymbolIterator symbol = image.symbol_begin();
symbol != image.symbol_end();
++symbol) {
vector<Point> vp;
// do something useful with results
cout << "decoded " << symbol->get_type_name()
<< " symbol \"" << symbol->get_data() << '"' << " " << endl;
int n = symbol->get_location_size();
for (int i = 0; i<n; i++) {
vp.push_back(Point(symbol->get_location_x(i),
symbol->get_location_y(i)));
}
RotatedRect r = minAreaRect(vp);
Point2f pts[4];
r.points(pts);
for (int i = 0; i<4; i++) {
line(imgout, pts[i], pts[(i + 1) % 4], Scalar(255, 0, 0), 3);
}
cout << "Angle: " << r.angle << endl;
}
imshow("imgout.jpg", imgout);
// clean up
image.set_data(NULL, 0);
waitKey();
}
補充說明(Supplement):
lib&dll跟專案放在一起 source 的路徑有加入專案設定