目前,我使用zxing(c++端口)扫描条形码,该端口使用stbi泳load从路径读取图像:
filePath = "..\\data\\qr_t2.bmp";
int width, height, channels;
unsigned char *bytes;
bytes = stbi_load(filePath.c_str(), &width, &height, &channels, 4);
std::unique_ptr<stbi_uc, void(*)(void*)> buffer(bytes, stbi_image_free);
但是我想用stbi_load_from_memory从内存读取图像,我的图像数据是使用opencv的Mat,我的代码如下:
typedef unsigned char BYTE;
Mat img_barcode = imread("..\\data\\qr_t2.bmp", 1);
int width = img_barcode.cols;
int height = img_barcode.rows;
BYTE *pImg;
int nFlag = img_barcode .channels() * 8;
int nBytes = width * height * nFlag / 8;
pImg = new BYTE[nBytes];
memcpy(pImg, srcImg.data, nBytes);
std::unique_ptr<stbi_uc, void(*)(void*)> buffer1(stbi_load_from_memory(pImg, 100*100*3, &width, &height, &channels, 3), stbi_image_free);
buffer1总是空的!有人能帮忙吗?
my test img Qr code