我试图使用ZBar库(zbar.sourceforge.net)和opencv找到QR码。
这是我的代码:
string findIDIncircle(Mat img, double* angle)
{
ImageScanner scanner;
zbar_image_scanner_set_config(scanner, ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
int width = img.cols;
int height = img.rows;
uchar *raw = (uchar *)img.data;
Image image(width, height, "Y800", raw, width * height);
scanner.scan(image);
SymbolSet symbols = image.get_symbols();
for(Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); symbol++)
{
string data = symbol->get_data();
vector<Point> vp;
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);
*angle = r.angle;
return data;
}
return "";
}
但是代码没有找到任何东西。我在img上使用imwrite检查了参数,图像是正确且非常清晰的(它是用http://www.qrcode-generator.de/生成的) 谁能告诉我,问题在哪里?
答案 0 :(得分:0)
Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);
uchar *raw = (uchar *)gray.data;