converting cv::Mat for tesseract

前端 未结 4 1522
失恋的感觉
失恋的感觉 2020-12-05 03:05

I\'m using OpenCV to extract a subimage of a scanned document and would like to use tesseract to perform OCR over this subimage.

I found out that I can use two meth

4条回答
  •  旧巷少年郎
    2020-12-05 03:55

    For Anybody using the JavaCPP presets of OpenCV/Tesseract, here is what works

    Mat img = imread("file.jpg");
    Mat gray = new Mat();
    cvtColor(img, gray, CV_BGR2GRAY);
    
    // api is a Tesseract client which is initialised
    
    api.SetImage(gray.data().asBuffer(),gray.size().width(),gray.size().height(),gray.channels(),gray.size1())
    

提交回复
热议问题