Hello everybody,
I've got a code where I show a video from a camera, but now I want to take a snapshot when a key is pressed, but I don't know exactly what function I need to use and how.
Could anyone help me please?
Thanks. I post my code.
int main( )
{
VideoCapture vcap;
const std::string VideoStreamAddress ="rtsp://192.168.1.10/MediaInput/mpeg4";
if (!vcap.open(VideoStreamAddress)) {
std::cout << "Error abriendo stream de video o archivo" << std::endl;
return 0;
}
while (true) {
if (!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
imshow("original", image);
if (waitKey(1) >= 0){
//TAKE A PHOTO
TakePhoto();
}
}
return 0;
}
Hi again,
The code to take snapshots it works fine, I can take a photo when a key is pressed, but now I'm trying to recognize text in that photo using tesseract engine and I'm having an error like this:
Error: Illegal min or max specification!
signal_termination_handler:Error:Signal_termination_handler called:Code 5002
I've only just added the code for text recognition within the waitkey if as follows:
if (waitKey(10) >= 0){
imwrite( format("foto_%3d.png",cuenta++), image); //take snapshot when key is pressed
// initilize tesseract OCR engine
tesseract::TessBaseAPI *myOCR = new tesseract::TessBaseAPI();
if (myOCR->Init(NULL, "spa")) {
fprintf( stderr, " Could not intialize tesseract.\n" );
exit(1);
}
// read image
namedWindow("tesseract-opencv", 0);
Mat imagen = imread(format("/home/adrian/workspace/foto_%3d.png",cuenta), 0);
// set region of interest (ROI), i.e. regions that contain text
Rect text1ROI(162, 110, 157 , 129);
// recognize text
myOCR->TesseractRect( imagen.data, 1, imagen.step1(), text1ROI.x, text1ROI.y, text1ROI.width, text1ROI.height);
const char *text1 = myOCR->GetUTF8Text();
// remove "newline"
string t1(text1);
t1.erase( std::remove(t1.begin(), t1.end(), '\n'), t1.end() );
// print found text
printf("text: \n");
printf( "%s",t1.c_str() );
printf("\n");
}
Any idea of that error????
Thanks