5#include <visp3/core/vpImageConvert.h>
6#include <visp3/core/vpMutex.h>
7#include <visp3/core/vpThread.h>
8#include <visp3/core/vpTime.h>
9#include <visp3/gui/vpDisplayX.h>
10#include <visp3/sensor/vpV4l2Grabber.h>
12#if defined(VISP_HAVE_V4L2) && defined(VISP_HAVE_PTHREAD)
15typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;
16t_CaptureState s_capture_state = capture_waiting;
26 bool stop_capture_ =
false;
38 if (s_capture_state == capture_stopped)
41 s_capture_state = capture_started;
48 s_capture_state = capture_stopped;
50 std::cout <<
"End of capture thread" << std::endl;
61 t_CaptureState capture_state_;
62 bool display_initialized_ =
false;
63#if defined(VISP_HAVE_X11)
68 s_mutex_capture.
lock();
69 capture_state_ = s_capture_state;
73 if (capture_state_ == capture_started) {
81 if (!display_initialized_) {
83#if defined(VISP_HAVE_X11)
85 display_initialized_ =
true;
96 s_capture_state = capture_stopped;
104 }
while (capture_state_ != capture_stopped);
106#if defined(VISP_HAVE_X11)
110 std::cout <<
"End of display thread" << std::endl;
116int main(
int argc,
const char *argv[])
118 unsigned int opt_device = 0;
119 unsigned int opt_scale = 2;
123 for (
int i = 0; i < argc; i++) {
124 if (std::string(argv[i]) ==
"--camera_device")
125 opt_device = (
unsigned int)atoi(argv[i + 1]);
126 else if (std::string(argv[i]) ==
"--scale")
127 opt_scale = (
unsigned int)atoi(argv[i + 1]);
128 else if (std::string(argv[i]) ==
"--help" || std::string(argv[i]) ==
"--h") {
129 std::cout <<
"Usage: " << argv[0]
130 <<
" [--camera_device <camera device (default: 0)>] [--scale <subsampling factor>]"
131 <<
" [--help] [-h]" << std::endl;
138 std::ostringstream device;
139 device <<
"/dev/video" << opt_device;
148 thread_capture.join();
149 thread_display.join();
158#ifndef VISP_HAVE_V4L2
159 std::cout <<
"You should enable V4L2 to make this example working..." << std::endl;
160#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
161 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
163 std::cout <<
"Multi-threading seems not supported on this platform" << std::endl;
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition of the vpImage class member functions.
Class that allows protection by mutex.
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void open(vpImage< unsigned char > &I)
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setDevice(const std::string &devname)
void acquire(vpImage< unsigned char > &I)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeSecond()