Ask Your Question
0

How to take an snapshot from a ethernet cam?

asked 2013-10-01 05:06:17 -0600

akoo gravatar image

updated 2013-10-01 06:56:13 -0600

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

edit retag flag offensive close merge delete

Comments

// have a counter var above the while loop:

int count = 0;

// then:

if ( waitKey(10) >=0 ) { imwrite( format("shot_%03d.png", count++), image); }

berak gravatar imageberak ( 2013-10-01 05:20:11 -0600 )edit

Thank you berak! It works fine!

akoo gravatar imageakoo ( 2013-10-01 05:30:15 -0600 )edit
1

[concerning your edit:]

  • you don't have to read it from disk again:

    Mat imagen = imread(format("/home/adrian/workspace/foto_%3d.png",cuenta), 0);

    cuenta got increased above, right ? so it's no more the same number... and imagen will most likely be empty ( it does not exist )

    just convert the original image to gray:

    `Mat imagen; cvtConvert(image,imagen,CV_BGR2GRAY);

    and use that instead.

  • the actual error does not seem to come from opencv, more from tesseract, so please check the args here carefully:

    myOCR->TesseractRect( imagen.data, 1, imagen.step1(), text1ROI.x, text1ROI.y,

berak gravatar imageberak ( 2013-10-01 07:16:44 -0600 )edit

I know cuenta is not the same value now, I have changed that just after post the code here.

akoo gravatar imageakoo ( 2013-10-01 07:20:03 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-10-01 05:22:09 -0600

//TAKE A PHOTO

if(image.empty())
{
  std::cerr << "Something is wrong with the webcam, ....." << std::endl;
}
imwrite("snapshot.jpg", image);

http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-10-01 05:06:17 -0600

Seen: 833 times

Last updated: Oct 01 '13