43 #include <opencv2/highgui/highgui.hpp> 
   44 #include <opencv2/imgproc/imgproc.hpp> 
   45 #include <opencv2/videoio/videoio.hpp> 
   79     std::string file = config.
check(
"movie", 
Value(
""),
 
   80                                     "if present, read from specified file rather than camera").asString();
 
   81     fromFile = (file!=
"");
 
   85         m_cap.open(file.c_str());
 
   86         if (!m_cap.isOpened()) {
 
   87             yCError(OPENCVGRABBER, 
"Unable to open file '%s' for capture!", file.c_str());
 
   92         m_loop = config.
check(
"loop",
"if present, loop movie");
 
   98             config.
check(
"camera",
 
   99                          Value(cv::VideoCaptureAPIs::CAP_ANY),
 
  100                          "if present, read from camera identified by this index").asInt32();
 
  102         m_cap.open(camera_idx);
 
  103         if (!m_cap.isOpened()) {
 
  104             yCError(OPENCVGRABBER, 
"Unable to open camera for capture!");
 
  109             yCInfo(OPENCVGRABBER, 
"Capturing from camera: %d",camera_idx);
 
  112         if ( config.
check(
"framerate",
"if present, specifies desired camera device framerate") ) {
 
  113             double m_fps = config.
check(
"framerate", 
Value(-1)).asFloat64();
 
  114             m_cap.set(cv::VideoCaptureProperties::CAP_PROP_FPS, m_fps);
 
  117         if (config.
check(
"flip_x", 
"if present, flip the image along the x-axis"))         m_flip_x = 
true;
 
  118         if (config.
check(
"flip_y", 
"if present, flip the image along the y-axis"))         m_flip_y = 
true;
 
  119         if (config.
check(
"transpose", 
"if present, rotate the image along of 90 degrees")) m_transpose = 
true;
 
  125     if (config.
check(
"width",
"if present, specifies desired image width")) {
 
  126         m_w = config.
check(
"width", 
Value(0)).asInt32();
 
  127         if (!fromFile && m_w>0) {
 
  128             m_cap.set(cv::VideoCaptureProperties::CAP_PROP_FRAME_WIDTH, m_w);
 
  131         m_w = (size_t)m_cap.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_WIDTH);
 
  134     if (config.
check(
"height",
"if present, specifies desired image height")) {
 
  135         m_h = config.
check(
"height", 
Value(0)).asInt32();
 
  136         if (!fromFile && m_h>0) {
 
  137             m_cap.set(cv::VideoCaptureProperties::CAP_PROP_FRAME_HEIGHT, m_h);
 
  140         m_h = (size_t)m_cap.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_HEIGHT);
 
  145     yCInfo(OPENCVGRABBER, 
"OpenCVGrabber opened");
 
  149     m_config.fromString(config.
toString());
 
  186     image.resize(frame.cols, frame.rows);
 
  189         yCDebug(OPENCVGRABBER, 
"Received image of size %zux%zu", image.width(), image.height());
 
  194     m_laststamp.update();
 
  198     cv::cvtColor(frame, frame_rgb, cv::COLOR_BGR2RGB);
 
  201     memcpy(image.getRawImage(), frame_rgb.data, 
sizeof(
unsigned char) * frame_rgb.rows * frame_rgb.cols * frame_rgb.channels());
 
  207         m_h = image.height();
 
  210         if (m_w>0 && m_h>0) {
 
  211             if (image.width() != m_w || image.height() != m_h) {
 
  213                     yCDebug(OPENCVGRABBER, 
"Software scaling from %zux%zu to %zux%zu",  image.width(), image.height(), m_w, m_h);
 
  216                 image.copy(image, m_w, m_h);
 
  221     yCTrace(OPENCVGRABBER, 
"%zu by %zu image", image.width(), image.height());
 
  230     if (!m_cap.isOpened()) {
 
  239     if (frame.empty() && m_loop) {
 
  240         bool ok = open(m_config);
 
  241         if (!ok) 
return false;
 
  252         cv::transpose(frame, frame);
 
  255     if (m_flip_x && m_flip_y)
 
  257         cv::flip(frame, frame, -1);
 
  261         cv::flip(frame, frame, 0);
 
  265         cv::flip(frame, frame, 1);
 
  268     return sendImage(frame, image);