-1

I wish to combine Magick++ with Tesseract OCR. I couldn't send Magick++

Image

object to Tesseract

setImage(const uchar*,int width,int height,int byte_per_pixel,int byte_per_line);

method. It doesnt have byte_per_line information.

Thanks for any help.

Edit: with the help of emcconville i organized my code and it seems working.

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;
Grayowl
  • 77
  • 3
  • 12
  • Please provide [mcve], at the moment it's not enough information to help you. – Nikita Oct 25 '16 at 12:40
  • 1
    Quick note: `CharPixel` is a data type. To calculate the size would be `sizeof(unsigned char)`. So `3 * sizeof(unsigned char)` – emcconville Oct 25 '16 at 14:00

1 Answers1

2

Magick++ has a data-export method of...

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_)

Before exporting data, you need to determine which color channels in the &map_ argument (e.g "RGBA"), and the size of the each color channel type_ (e.g. CharPixel). You'll then be responsible for allocating a buffer pixels_ large enough to hold all the data (number of channels * sizeof storage type * area of image).

After exporting, you should be able to pass the buffer to TessBaseAPI::SetImage with byte_per_pixel being the number of channels * storage type size, and byte_per_line usually byte_per_pixel * width of area.

emcconville
  • 23,800
  • 4
  • 50
  • 66