Reading video and using tesseract

asked 2018-03-03 16:18:22 -0500

baku gravatar image
VideoCapture cap1("City Traffic Surveillance.mp4");
Mat frame1;
for (;;) { 
    cap1.read(frame1);
    Mat edges;
    cvtColor(frame1, edges, CV_BGR2GRAY);
Canny(edges, edges, 100, 300, 3);

    tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();
    ocr->TesseractRect(edges.data, 1, edges.step1(), findGroup.at(j).at(i).x, findGroup.at(j).at(i).y, findGroup.at(j).at(i).width, findGroup.at(j).at(i).height);
    char* text = ocr->GetUTF8Text();
     putText(frame1, text, Point(findGroup.at(j).at(i).x, findGroup.at(j).at(i).y + 20), FONT_HERSHEY_SIMPLEX, 2, Scalar(0, 255, 0), 2, 8);

  imshow("Video", frame1);
    imshow("Video2", edges);

    if (waitKey(20) == 27) break;
}

I'm trying to use tesseract with video file like code above. I didn't write code about findGroup in above code but my original has it. The problem is that when I call ocr->TesseractRect(edges.data, 1, edges.step1(), findGroup.at(j).at(i).x, findGroup.at(j).at(i).y, findGroup.at(j).at(i).width, findGroup.at(j).at(i).height), edges.data is pointing null character. Because of that error pop up. So I check the value and I found out that frame1 and edges ' data always pointing null character. I guess the way to read video file is wrong but I dont know how to fix this. image description

edit retag flag offensive close merge delete

Comments

1
  1. Please remove screen shot
  2. "Because of that error pop up" give error message
  3. ocr->TesseractRect is not an opencv function : off topics
LBerger gravatar imageLBerger ( 2018-03-04 02:56:17 -0500 )edit
1

you never check the result from cap1.read(frame1);

it will be false for the last frame of your video file, and you're trying to process an empty Mat() then.

berak gravatar imageberak ( 2018-03-04 19:21:58 -0500 )edit