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) 15 typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;
16 t_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;
116 int 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>]" 139 std::ostringstream device;
140 device <<
"/dev/video" << opt_device;
149 thread_capture.join();
150 thread_display.join();
159 #ifndef VISP_HAVE_V4L2 160 std::cout <<
"You should enable V4L2 to make this example working..." << std::endl;
161 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 162 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
164 std::cout <<
"Multi-threading seems not supported on this platform" << std::endl;
Class that allows protection by mutex.
VISP_EXPORT int wait(double t0, double t)
void acquire(vpImage< unsigned char > &I)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void open(vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeSecond()
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void setDevice(const std::string &devname)
static void flush(const vpImage< unsigned char > &I)
static void display(const vpImage< unsigned char > &I)
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
Class that is a wrapper over the Video4Linux2 (V4L2) driver.