intial commit

This commit is contained in:
2023-11-18 14:07:27 +01:00
commit ce321a6e33
9 changed files with 781 additions and 0 deletions

68
webcam.h Normal file
View File

@ -0,0 +1,68 @@
/** Small C++ wrapper around V4L example code to access the webcam
**/
#include <string>
#include <memory> // unique_ptr
#include <cstdint>
#include "image.h"
struct buffer {
void *data;
size_t size;
};
class Webcam {
public:
Webcam(const std::string& device = "/dev/video0",
int width = 640,
int height = 480, bool mjpeg = false);
~Webcam();
/** Captures and returns a frame from the webcam.
*
* The returned object contains a field 'data' with the image data in RGB888
* format (ie, RGB24), as well as 'width', 'height' and 'size' (equal to
* width * height * 3)
*
* This call blocks until a frame is available or until the provided
* timeout (in seconds).
*
* Throws a runtime_error if the timeout is reached.
*/
const Image& frame(int timeout = 2);
private:
void init_mmap();
void open_device();
void close_device();
void init_device();
void uninit_device();
void start_capturing();
void stop_capturing();
bool read_frame();
std::string device;
int fd;
Image rgb_frame;
struct buffer *buffers;
unsigned int n_buffers;
size_t xres, yres;
size_t stride;
bool force_format = true;
uint32_t format;
};