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/vpDisplayGDI.h> 10 #include <visp3/gui/vpDisplayX.h> 12 #if (VISP_HAVE_OPENCV_VERSION >= 0x020100) && (defined(VISP_HAVE_PTHREAD) || defined(_WIN32)) 14 #include <opencv2/highgui/highgui.hpp> 17 typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;
18 t_CaptureState s_capture_state = capture_waiting;
26 cv::VideoCapture cap = *((cv::VideoCapture *)args);
28 if (!cap.isOpened()) {
29 std::cout <<
"Unable to start capture" << std::endl;
35 while ((i++ < 100) && !cap.read(frame_)) {
38 bool stop_capture_ =
false;
48 if (s_capture_state == capture_stopped)
51 s_capture_state = capture_started;
58 s_capture_state = capture_stopped;
61 std::cout <<
"End of capture thread" << std::endl;
72 t_CaptureState capture_state_;
73 bool display_initialized_ =
false;
74 #if defined(VISP_HAVE_X11) 76 #elif defined(VISP_HAVE_GDI) 81 s_mutex_capture.
lock();
82 capture_state_ = s_capture_state;
86 if (capture_state_ == capture_started) {
95 if (!display_initialized_) {
97 #if defined(VISP_HAVE_X11) 99 display_initialized_ =
true;
100 #elif defined(VISP_HAVE_GDI) 102 display_initialized_ =
true;
113 s_capture_state = capture_stopped;
121 }
while (capture_state_ != capture_stopped);
123 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) 127 std::cout <<
"End of display thread" << std::endl;
133 int main(
int argc,
const char *argv[])
138 for (
int i = 0; i < argc; i++) {
139 if (std::string(argv[i]) ==
"--camera_device")
140 opt_device = atoi(argv[i + 1]);
141 else if (std::string(argv[i]) ==
"--help") {
142 std::cout <<
"Usage: " << argv[0] <<
" [--camera_device <camera device (default: 0)>] [--help]" << std::endl;
148 cv::VideoCapture cap;
149 cap.open(opt_device);
156 thread_capture.join();
157 thread_display.join();
166 #ifndef VISP_HAVE_OPENCV 167 std::cout <<
"You should install OpenCV to make this example working..." << std::endl;
168 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX 169 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
171 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)