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 #include <visp3/ustk_core/usImagePostScan2D.h>
14 #if defined(VISP_HAVE_V4L2) && defined(VISP_HAVE_PTHREAD)
17 typedef enum { capture_waiting, capture_started, capture_stopped } t_CaptureState;
18 t_CaptureState s_capture_state = capture_waiting;
19 vpImage<unsigned char> s_frame;
20 vpMutex s_mutex_capture;
24 vpThread::Return captureFunction(vpThread::Args args)
26 vpV4l2Grabber cap = *((vpV4l2Grabber *)args);
27 vpImage<unsigned char> frame_;
28 bool stop_capture_ =
false;
32 vpRect roi(vpImagePoint(48, 90), vpImagePoint(416, 550));
34 while (!stop_capture_) {
36 cap.acquire(frame_, roi);
40 vpMutex::vpScopedLock lock(s_mutex_capture);
41 if (s_capture_state == capture_stopped)
44 s_capture_state = capture_started;
50 vpMutex::vpScopedLock lock(s_mutex_capture);
51 s_capture_state = capture_stopped;
53 std::cout <<
"End of capture thread" << std::endl;
59 vpThread::Return displayFunction(vpThread::Args args)
62 vpImage<unsigned char> I_;
65 t_CaptureState capture_state_;
66 bool display_initialized_ =
false;
67 #if defined(VISP_HAVE_X11)
68 vpDisplayX *d_ = NULL;
72 s_mutex_capture.lock();
73 capture_state_ = s_capture_state;
74 s_mutex_capture.unlock();
77 if (capture_state_ == capture_started) {
80 vpMutex::vpScopedLock lock(s_mutex_capture);
93 if (!display_initialized_) {
95 #if defined(VISP_HAVE_X11)
96 d_ =
new vpDisplayX(postScan_);
97 display_initialized_ =
true;
102 vpDisplay::display(postScan_);
105 vpDisplay::displayText(postScan_, 10, 10,
"Click to exit...", vpColor::red);
106 if (vpDisplay::getClick(postScan_,
false)) {
107 vpMutex::vpScopedLock lock(s_mutex_capture);
108 s_capture_state = capture_stopped;
112 vpDisplay::flush(postScan_);
116 }
while (capture_state_ != capture_stopped);
118 #if defined(VISP_HAVE_X11)
122 std::cout <<
"End of display thread" << std::endl;
128 int main(
int argc,
const char *argv[])
130 unsigned int opt_input = 1;
133 for (
int i = 0; i < argc; i++) {
134 if (std::string(argv[i]) ==
"--input")
135 opt_input = (
unsigned int)atoi(argv[i + 1]);
136 else if (std::string(argv[i]) ==
"--help") {
137 std::cout <<
"Usage: " << argv[0] <<
" [--input <number>] [--help]" << std::endl;
145 g.setInput(opt_input);
149 vpThread thread_capture((vpThread::Fn)captureFunction, (vpThread::Args)&g);
150 vpThread thread_display((vpThread::Fn)displayFunction);
153 thread_capture.join();
154 thread_display.join();
163 #ifndef VISP_HAVE_V4L2
164 std::cout <<
"You should enable V4L2 to make this example working..." << std::endl;
165 #elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
166 std::cout <<
"You should enable pthread usage and rebuild ViSP..." << std::endl;
168 std::cout <<
"Multi-threading seems not supported on this platform" << std::endl;
void setData(const vpImage< Type > &image)
void setTransducerConvexity(const bool isTransducerConvex)
void setScanLinePitch(const double scanLinePitch)
void setProbeName(std::string probeName)
void setTransducerRadius(const double transducerRadius)
void setScanLineNumber(unsigned int scanLineNumber)