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 defined(HAVE_OPENCV_VIDEOIO) && (defined(VISP_HAVE_PTHREAD) || defined(_WIN32))
14#include <opencv2/highgui.hpp>
15#include <opencv2/videoio.hpp>
18typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;
19t_CaptureState s_capture_state = capture_waiting;
27 cv::VideoCapture cap = *((cv::VideoCapture *)args);
29 if (!cap.isOpened()) {
30 std::cout <<
"Unable to start capture" << std::endl;
36 while ((i++ < 100) && !cap.read(frame_)) {
39 bool stop_capture_ =
false;
49 if (s_capture_state == capture_stopped)
52 s_capture_state = capture_started;
59 s_capture_state = capture_stopped;
62 std::cout <<
"End of capture thread" << std::endl;
73 t_CaptureState capture_state_;
74 bool display_initialized_ =
false;
75#if defined(VISP_HAVE_X11)
77#elif defined(VISP_HAVE_GDI)
82 s_mutex_capture.
lock();
83 capture_state_ = s_capture_state;
87 if (capture_state_ == capture_started) {
96 if (!display_initialized_) {
98#if defined(VISP_HAVE_X11)
100 display_initialized_ =
true;
101#elif defined(VISP_HAVE_GDI)
103 display_initialized_ =
true;
114 s_capture_state = capture_stopped;
123 }
while (capture_state_ != capture_stopped);
125#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
129 std::cout <<
"End of display thread" << std::endl;
135int main(
int argc,
const char *argv [])
140 for (
int i = 0; i < argc; i++) {
141 if (std::string(argv[i]) ==
"--camera_device")
142 opt_device = atoi(argv[i + 1]);
143 else if (std::string(argv[i]) ==
"--help") {
144 std::cout <<
"Usage: " << argv[0] <<
" [--camera_device <camera device (default: 0)>] [--help]" << std::endl;
150 cv::VideoCapture cap;
151 cap.open(opt_device);
158 thread_capture.join();
159 thread_display.join();
168#ifndef VISP_HAVE_OPENCV
169 std::cout <<
"You should install OpenCV videoio module to make this example working..." << std::endl;
170#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
171 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
173 std::cout <<
"Multi-threading seems not supported on this platform" << std::endl;
Display for windows using GDI (available on any windows 32 platform).
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)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
Class that allows protection by mutex.
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double measureTimeSecond()