我希望将Magick ++与Tesseract OCR结合起来。我无法发送Magick ++
图像
对象Tesseract
setImage(const uchar *,int width,int height,int byte_per_pixel,int byte_per_line);
方法。它没有byte_per_line信息。
感谢您的帮助。
编辑:在emcconville的帮助下,我组织了我的代码,看起来很有效。
Magick::Image* imgptr = mat2Image(frame); // cv::Mat
Geometry size = imgptr->size();
imgptr->density(Geometry(300,300));
size_t area = frame.rows * frame.cols;
uchar* data = new uchar[3 * CharPixel * area];
imgptr->write(0,0,frame.cols,frame.rows, "BGR",CharPixel,data);
api- >SetImage(data,size.width(),size.height(),3*CharPixel,3*CharPixel*size.width());
delete [] data;
delete imgptr;
答案 0 :(得分:2)
Magick ++有一个数据导出方法......
Magick::Image.write(const ssize_t x_,
const ssize_t y_,
const size_t columns_,
const size_t rows_,
const std::string &map_,
const StorageType type_, void *pixels_)
在导出数据之前,您需要确定&map_
参数中的哪些颜色通道(例如" RGBA"),以及每个颜色通道type_
的大小(例如{ {1}})。然后,您将负责分配足够大的缓冲区CharPixel
以容纳所有数据(通道数*存储类型的大小*图像区域)。
导出后,您应该能够将缓冲区传递给pixels_
,其中TessBaseAPI::SetImage
为通道数*存储类型大小,byte_per_pixel
通常为byte_per_line
*宽度区域。