#include <iostream>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpMutex.h>
#include <visp3/core/vpThread.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
#if (VISP_HAVE_OPENCV_VERSION >= 0x020100) && (defined(VISP_HAVE_PTHREAD) || defined(_WIN32))
#include <opencv2/highgui/highgui.hpp>
typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;
t_CaptureState s_capture_state = capture_waiting;
cv::Mat s_frame;
{
cv::VideoCapture cap = *((cv::VideoCapture *)args);
if (!cap.isOpened()) {
std::cout << "Unable to start capture" << std::endl;
return 0;
}
cv::Mat frame_;
int i = 0;
while ((i++ < 100) && !cap.read(frame_)) {
};
bool stop_capture_ = false;
cap >> frame_;
{
if (s_capture_state == capture_stopped)
stop_capture_ = true;
else
s_capture_state = capture_started;
s_frame = frame_;
}
}
{
s_capture_state = capture_stopped;
}
std::cout << "End of capture thread" << std::endl;
return 0;
}
{
(void)args;
t_CaptureState capture_state_;
bool display_initialized_ = false;
#if defined(VISP_HAVE_X11)
#elif defined(VISP_HAVE_GDI)
#endif
do {
capture_state_ = s_capture_state;
if (capture_state_ == capture_started) {
{
}
if (!display_initialized_) {
#if defined(VISP_HAVE_X11)
display_initialized_ = true;
#elif defined(VISP_HAVE_GDI)
display_initialized_ = true;
#endif
}
s_capture_state = capture_stopped;
}
} else {
}
} while (capture_state_ != capture_stopped);
#if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
delete d_;
#endif
std::cout << "End of display thread" << std::endl;
return 0;
}
int main(int argc, const char *argv[])
{
int opt_device = 0;
for (int i = 0; i < argc; i++) {
if (std::string(argv[i]) == "--camera_device")
opt_device = atoi(argv[i + 1]);
else if (std::string(argv[i]) == "--help") {
std::cout << "Usage: " << argv[0] << " [--camera_device <camera device (default: 0)>] [--help]" << std::endl;
return 0;
}
}
cv::VideoCapture cap;
cap.open(opt_device);
return 0;
}
#else
int main()
{
#ifndef VISP_HAVE_OPENCV
std::cout << "You should install OpenCV to make this example working..." << std::endl;
#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
std::cout << "You should enable pthread usage and rebuild ViSP..." << std::endl;
#else
std::cout << "Multi-threading seems not supported on this platform" << std::endl;
#endif
}
#endif