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/gui/vpDisplayGDI.h>
12 #if (VISP_HAVE_OPENCV_VERSION >= 0x020100) && (defined(VISP_HAVE_PTHREAD) || defined(_WIN32))
14 #include <opencv2/highgui/highgui.hpp>
22 t_CaptureState s_capture_state = capture_waiting;
30 cv::VideoCapture cap = *((cv::VideoCapture *) args);
33 std::cout <<
"Unable to start capture" << std::endl;
39 while ((i++ < 100) && !cap.read(frame_)) {};
41 bool stop_capture_ =
false;
51 if (s_capture_state == capture_stopped)
54 s_capture_state = capture_started;
61 s_capture_state = capture_stopped;
64 std::cout <<
"End of capture thread" << std::endl;
75 t_CaptureState capture_state_;
76 bool display_initialized_ =
false;
77 #if defined(VISP_HAVE_X11)
79 #elif defined(VISP_HAVE_GDI)
84 s_mutex_capture.
lock();
85 capture_state_ = s_capture_state;
89 if (capture_state_ == capture_started) {
97 if (! display_initialized_) {
99 #if defined(VISP_HAVE_X11)
101 display_initialized_ =
true;
102 #elif defined(VISP_HAVE_GDI)
104 display_initialized_ =
true;
115 s_capture_state = capture_stopped;
124 }
while(capture_state_ != capture_stopped);
126 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
130 std::cout <<
"End of display thread" << std::endl;
136 int main(
int argc,
const char* argv[])
141 for (
int i=0; i<argc; i++) {
142 if (std::string(argv[i]) ==
"--device")
143 opt_device = atoi(argv[i+1]);
144 else if (std::string(argv[i]) ==
"--help") {
145 std::cout <<
"Usage: " << argv[0] <<
" [--device <camera device>] [--help]" << std::endl;
151 cv::VideoCapture cap;
152 cap.open(opt_device);
159 thread_capture.join();
160 thread_display.join();
169 # ifndef VISP_HAVE_OPENCV
170 std::cout <<
"You should install OpenCV to make this example working..." << std::endl;
171 # elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
172 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
174 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)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
VISP_EXPORT double measureTimeSecond()
Display for windows using GDI (available on any windows 32 platform).
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...
static void flush(const vpImage< unsigned char > &I)
static void display(const vpImage< unsigned char > &I)