Exemplo n.º 1
0
void imageCollectionThread(void* arg)
{
  
  VideoDispatcher* dispatcher = (VideoDispatcher*) arg;

  while (dispatcher->active)
  {
    try
    {
      cv::VideoCapture cap=cv::VideoCapture();
      cap.open(dispatcher->mjpeg_url);
      
      if (cap.isOpened())
      {
	getALPRImages(cap, dispatcher);
      }
      else
      {
	std::stringstream ss;
	ss << "Stream " << dispatcher->mjpeg_url << " failed to open.";
	dispatcher->log_error(ss.str());
      }

    }
    catch (const std::runtime_error& error)
    {
      // Error occured while trying to gather image.  Retry, don't exit.
      std::stringstream ss;
      ss << "VideoBuffer exception: " << error.what();
      dispatcher->log_error( ss.str() );
    }
    catch (cv::Exception e)
    {
      // OpenCV Exception occured while trying to gather image.  Retry, don't exit.
      std::stringstream ss;
      ss << "VideoBuffer OpenCV exception: " << e.what();
      dispatcher->log_error( ss.str() );
    }
    
    // Delay 1 second
    usleep(1000000);
    
  }

  
}
Exemplo n.º 2
0
void imageCollectionThread(void* arg)
{
  
  VideoDispatcher* dispatcher = (VideoDispatcher*) arg;

  while (dispatcher->active)
  {
    try
    {
      cv::VideoCapture cap=cv::VideoCapture();
      dispatcher->log_info("Video stream connecting...");

      // Check if it's a webcam, if so, pass the device ID
      std::string video_prefix = "/dev/video";
      if (startsWith(dispatcher->mjpeg_url, video_prefix))
      {
        std::string device_number_str = dispatcher->mjpeg_url.substr(video_prefix.length());
        dispatcher->log_info("Opening webcam video device " + device_number_str);
        
        int webcam_number = atoi(device_number_str.c_str());
        cap.open(webcam_number);
      }
      else if (dispatcher->mjpeg_url == "webcam")
      {
        cap.open(0);
      }
      else
      {
        cap.open(dispatcher->mjpeg_url);
      }
      
      if (cap.isOpened())
      {
        dispatcher->log_info("Video stream connected");
        getALPRImages(cap, dispatcher);
      }
      else
      {
	std::stringstream ss;
	ss << "Stream " << dispatcher->mjpeg_url << " failed to open.";
	dispatcher->log_error(ss.str());
      }

    }
    catch (const std::runtime_error& error)
    {
      // Error occured while trying to gather image.  Retry, don't exit.
      std::stringstream ss;
      ss << "VideoBuffer exception: " << error.what();
      dispatcher->log_error( ss.str() );
    }
    catch (cv::Exception e)
    {
      // OpenCV Exception occured while trying to gather image.  Retry, don't exit.
      std::stringstream ss;
      ss << "VideoBuffer OpenCV exception: " << e.what();
      dispatcher->log_error( ss.str() );
    }
    
    // Delay 1 second
    sleep_ms(1000);
    
  }

  
}