Robobot camera

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(Use from OpenCV (C++))
(Use from OpenCV (C++))
Line 17: Line 17:
  
 
=== Use from OpenCV (C++) ===
 
=== Use from OpenCV (C++) ===
 +
 +
First open and set camera format:
 +
 +
cv::VideoCapture cap;
  
 
  void setup()
 
  void setup()
Line 54: Line 58:
 
           cap.get(cv::CAP_PROP_FPS));
 
           cap.get(cv::CAP_PROP_FPS));
 
   }
 
   }
 +
 +
Then capture an image:
 +
 +
cv::Mat frame;
 +
bool gotFrame = false;
 +
 +
cap.read(frame);
 +
// mark as available
 +
gotFrame = not frame.empty();
 +
 +
To get the most recent image, it is a good idea to discard unused images by:
 +
 +
cap.grab();
 +
 +
In the template code, this is done in a thread (called loop())

Revision as of 13:21, 6 December 2022

Back to Robobot

camera settings

Data formats

The used camera is a 'Jieli Technology' camera of type 'USB PHY 2.0' (packed by Sandberg).

The camera has limited control capabilities but supports the following data formats.

  • MJPG coded 640 x 320 pixels at 25 or 30 FPS
  • MJPG coded 1280 x 720 pixels at 25 or 30 FPS
  • MJPG coded 1920 x 1080 pixels at 25 or 30 FPS
  • MJPG coded 640 x 480 pixels at 25 or 30 FPS, cuts parts of the image to fit the format

It also supports "raw" format as YUYV 4:2:2, but it seems like data loss occurs (fragmented images), so do not use this format.

Use from OpenCV (C++)

First open and set camera format:

cv::VideoCapture cap;
void setup()
{
 int deviceID = 0;        
 int apiID = cv::CAP_V4L2;
 // open selected camera using selected API
 cap.open(deviceID, apiID);
 // check if we succeeded
 camIsOpen = cap.isOpened();
 if (not camIsOpen)
 {
   cerr << "ERROR! Unable to open camera\n";
 }
 else
 {
   uint32_t fourcc = cv::VideoWriter::fourcc('M','J','P','G'); 
   cap.set(cv::CAP_PROP_FOURCC, fourcc);
   // possible resolutions in JPEG coding
   // (rows x columns) 320x640, 720x1280
   cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
   cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
   cap.set(cv::CAP_PROP_FPS, 25);
   // now the camera is ready for frame capture. 
   // debug print of accepted format:
   union FourChar
   { // the four characters are coded into a 32-bit integer.
     uint32_t cc4;
     char ccc[4];
   } fmt;
   fmt.cc4 = cap.get(cv::CAP_PROP_FOURCC); // get format
   printf("# Video device %d: width=%g, height=%g, format=%c%c%c%c, FPS=%g\n", 
          dev, 
          cap.get(cv::CAP_PROP_FRAME_WIDTH), 
          cap.get(cv::CAP_PROP_FRAME_HEIGHT), 
          fmt.ccc[0], fmt.ccc[1], fmt.ccc[2], fmt.ccc[3], 
          cap.get(cv::CAP_PROP_FPS));
 }

Then capture an image:

cv::Mat frame;
bool gotFrame = false;

cap.read(frame);
// mark as available
gotFrame = not frame.empty();

To get the most recent image, it is a good idea to discard unused images by:

cap.grab();

In the template code, this is done in a thread (called loop())

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox