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)
20 t_CaptureState s_capture_state = capture_waiting;
30 bool stop_capture_ =
false;
42 if (s_capture_state == capture_stopped)
45 s_capture_state = capture_started;
52 s_capture_state = capture_stopped;
54 std::cout <<
"End of capture thread" << std::endl;
65 t_CaptureState capture_state_;
66 bool display_initialized_ =
false;
67 #if defined(VISP_HAVE_X11)
72 s_mutex_capture.
lock();
73 capture_state_ = s_capture_state;
77 if (capture_state_ == capture_started) {
85 if (! display_initialized_) {
87 #if defined(VISP_HAVE_X11)
89 display_initialized_ =
true;
100 s_capture_state = capture_stopped;
109 }
while(capture_state_ != capture_stopped);
111 #if defined(VISP_HAVE_X11)
115 std::cout <<
"End of display thread" << std::endl;
121 int main(
int argc,
const char* argv[])
123 unsigned int opt_device = 0;
124 unsigned int opt_scale = 2;
127 for (
int i=0; i<argc; i++) {
128 if (std::string(argv[i]) ==
"--device")
129 opt_device = (
unsigned int)atoi(argv[i+1]);
130 else if (std::string(argv[i]) ==
"--scale")
131 opt_scale = (
unsigned int)atoi(argv[i+1]);
132 else if (std::string(argv[i]) ==
"--help") {
133 std::cout <<
"Usage: " << argv[0] <<
" [--device <camera device>] [--scale <subsampling factor>] [--help]" << std::endl;
140 std::ostringstream device;
141 device <<
"/dev/video" << opt_device;
150 thread_capture.join();
151 thread_display.join();
160 # ifndef VISP_HAVE_V4L2
161 std::cout <<
"You should enable V4L2 to make this example working..." << std::endl;
162 # elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
163 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
165 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.