Skip to content

Commit

Permalink
Introduce vpDisplayFactory usage, code indentation, harmonize command…
Browse files Browse the repository at this point in the history
… line options
  • Loading branch information
fspindle committed May 19, 2024
1 parent 1e4d079 commit 41d8d3b
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 115 deletions.
7 changes: 4 additions & 3 deletions tutorial/grabber/tutorial-grabber-1394-writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ int main(int argc, char **)
vpDisplay::display(I);
vpDisplay::flush(I);

if (vpDisplay::getClick(I, false))
if (vpDisplay::getClick(I, false)) {
break;
}
#endif
}

if (save)
if (save) {
writer.close();

}
}
catch (const vpException &e) {

Check warning on line 63 in tutorial/grabber/tutorial-grabber-1394-writer.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-grabber-1394-writer.cpp#L63

Added line #L63 was not covered by tests
std::cout << "Catch an exception: " << e << std::endl;
Expand Down
37 changes: 20 additions & 17 deletions tutorial/grabber/tutorial-video-reader.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! \example tutorial-video-reader.cpp
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayFactory.h>
//! [Include]
#include <visp3/core/vpTime.h>
#include <visp3/io/vpVideoReader.h>
Expand All @@ -24,8 +22,8 @@ int main(int argc, char **argv)
videoname = std::string(argv[i + 1]);
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "\nUsage: " << argv[0] << " [--name <video name> (default: " << videoname << ")]"
<< " [--help] [-h]\n"
<< std::endl;
<< " [--help] [-h]\n"

Check warning on line 25 in tutorial/grabber/tutorial-video-reader.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-reader.cpp#L25

Added line #L25 was not covered by tests
<< std::endl;
return EXIT_SUCCESS;
}
}
Expand All @@ -44,20 +42,17 @@ int main(int argc, char **argv)
std::cout << "Video framerate: " << g.getFramerate() << "Hz" << std::endl;
std::cout << "Video dimension: " << I.getWidth() << " " << I.getHeight() << std::endl;

#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(I);
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV d(I);
#ifdef VISP_HAVE_DISPLAY
vpDisplay *d = vpDisplayFactory::displayFactory(I);

Check warning on line 46 in tutorial/grabber/tutorial-video-reader.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-reader.cpp#L46

Added line #L46 was not covered by tests
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
vpDisplay::setTitle(I, "Video reader");

unsigned cpt = 1;
bool quit = false;
//! [vpVideoReader while loop]
while (!g.end()) {
while ((!g.end()) && (!quit)) {
//! [vpVideoReader while loop]
//! [vpVideoReader loop start time]
double t = vpTime::measureTimeMs();
Expand All @@ -68,17 +63,25 @@ int main(int argc, char **argv)
vpDisplay::display(I);
vpDisplay::displayText(I, 20, 20, "Click to quit", vpColor::red);
std::stringstream ss;
ss << "Frame: " << cpt++;
ss << "Frame: " << ++cpt;
std::cout << "Read " << ss.str() << std::endl;

Check warning on line 67 in tutorial/grabber/tutorial-video-reader.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-reader.cpp#L66-L67

Added lines #L66 - L67 were not covered by tests
vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);
vpDisplay::flush(I);
if (vpDisplay::getClick(I, false))
break;
if (vpDisplay::getClick(I, false)) {
quit = true;
}
//! [vpVideoReader loop rate]
vpTime::wait(t, 1000. / g.getFramerate());
//! [vpVideoReader loop rate]
}
std::cout << "End of video was reached" << std::endl;
} catch (const vpException &e) {
if (!quit) {
std::cout << "End of video was reached" << std::endl;
}
#ifdef VISP_HAVE_DISPLAY
delete d;

Check warning on line 81 in tutorial/grabber/tutorial-video-reader.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-reader.cpp#L81

Added line #L81 was not covered by tests
#endif
}
catch (const vpException &e) {

Check warning on line 84 in tutorial/grabber/tutorial-video-reader.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-reader.cpp#L84

Added line #L84 was not covered by tests
std::cout << e.getMessage() << std::endl;
}
#else
Expand Down
41 changes: 19 additions & 22 deletions tutorial/grabber/tutorial-video-recorder.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*! \example tutorial-video-recorder.cpp */
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayGTK.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpVideoWriter.h>
#include <visp3/sensor/vpV4l2Grabber.h>
Expand All @@ -12,36 +10,36 @@
#endif

/*!
This example allows to record a video from a camera.
It only requires that ViSP is build with OpenCV.
This example allows to record a video from a camera.
It only requires that ViSP is build with OpenCV.
Example to save an mpeg video:
Example to save an mpeg video:
./tutorial-video-recorder --device 0 --name myvideo.mp4
Example to save a sequence of png images:
Example to save a sequence of png images:
./tutorial-video-recorder --device 0 --name image%04d.png
Example to save one imags:
Example to save one image:
./tutorial-video-recorder --device 0 --name image.jpeg
*/
int main(int argc, const char *argv [])
int main(int argc, const char *argv[])

Check warning on line 29 in tutorial/grabber/tutorial-video-recorder.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-recorder.cpp#L29

Added line #L29 was not covered by tests
{
#if ((defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && \
(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(HAVE_OPENCV_HIGHGUI) || defined(VISP_HAVE_GTK)))
#if (defined(VISP_HAVE_V4L2) || defined(HAVE_OPENCV_VIDEOIO)) && defined(VISP_HAVE_DISPLAY)
std::string opt_videoname = "video-recorded.mpg";
int opt_device = 0;

for (int i = 0; i < argc; i++) {
if (std::string(argv[i]) == "--device")
opt_device = atoi(argv[i + 1]);
else if (std::string(argv[i]) == "--name")
else if (std::string(argv[i]) == "--recorded-name")

Check warning on line 38 in tutorial/grabber/tutorial-video-recorder.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-recorder.cpp#L38

Added line #L38 was not covered by tests
opt_videoname = std::string(argv[i + 1]);
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "\nUsage: " << argv[0] << " [--device <device number>] [--name <video name>] [--help][-h]\n"
std::cout << "\nUsage: " << argv[0]
<< " [--device <device number>] [--recorded-name <video name>] [--help][-h]\n"

Check warning on line 42 in tutorial/grabber/tutorial-video-recorder.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-recorder.cpp#L42

Added line #L42 was not covered by tests
<< std::endl;
return EXIT_SUCCESS;
}
Expand All @@ -55,6 +53,7 @@ int main(int argc, const char *argv [])
vpImage<unsigned char> I; // for gray images

#if defined(VISP_HAVE_V4L2)
std::cout << "Use v4l2 grabber..." << std::endl;
vpV4l2Grabber g;
std::ostringstream device;
device << "/dev/video" << opt_device;
Expand All @@ -63,6 +62,7 @@ int main(int argc, const char *argv [])
g.open(I);
g.acquire(I);
#elif defined(HAVE_OPENCV_VIDEOIO)
std::cout << "Use OpenCV grabber..." << std::endl;
cv::VideoCapture g(opt_device);
if (!g.isOpened()) { // check if we succeeded
std::cout << "Failed to open the camera" << std::endl;
Expand All @@ -75,16 +75,10 @@ int main(int argc, const char *argv [])

std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;

#if defined(VISP_HAVE_X11)
vpDisplayX d;
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d;
#elif defined(HAVE_OPENCV_HIGHGUI)
vpDisplayOpenCV d;
#elif defined(VISP_HAVE_GTK)
vpDisplayGTK d;
#if defined(VISP_HAVE_DISPLAY)
vpDisplay *d = vpDisplayFactory::displayFactory();
d->init(I, 0, 0, "Camera view");

Check warning on line 80 in tutorial/grabber/tutorial-video-recorder.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-recorder.cpp#L79-L80

Added lines #L79 - L80 were not covered by tests
#endif
d.init(I, 0, 0, "Camera view");
vpVideoWriter writer;

#if defined(HAVE_OPENCV_VIDEOIO)
Expand Down Expand Up @@ -121,6 +115,9 @@ int main(int argc, const char *argv [])
vpDisplay::flush(I);
}
std::cout << "The video was recorded in \"" << opt_videoname << "\"" << std::endl;
#ifdef VISP_HAVE_DISPLAY
delete d;

Check warning on line 119 in tutorial/grabber/tutorial-video-recorder.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/grabber/tutorial-video-recorder.cpp#L119

Added line #L119 was not covered by tests
#endif
}
catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
Expand Down
45 changes: 27 additions & 18 deletions tutorial/image/tutorial-draw-circle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! \example tutorial-draw-circle.cpp
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/core/vpImageCircle.h>
#include <visp3/core/vpImageDraw.h>

Expand All @@ -11,10 +10,10 @@ int main()

try {
{
#if defined(VISP_HAVE_X11)
vpDisplayX d(I, vpDisplay::SCALE_AUTO);
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d(I, vpDisplay::SCALE_AUTO);
#if defined(VISP_HAVE_DISPLAY)
vpDisplay *d = vpDisplayFactory::displayFactory(I, vpDisplay::SCALE_AUTO);

Check warning on line 14 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L14

Added line #L14 was not covered by tests
#else
std::cout << "No gui available to display gray level image..." << std::endl;
#endif

vpDisplay::setTitle(I, "Gray image");
Expand All @@ -25,9 +24,9 @@ int main()
// i.e. does not modify I
vpDisplay::displayCircle(I, circle, vpColor::red, false, 2);
//! [Circle display]
vpDisplay::setTitle(I, "Display a red circle on gray level image overlay");

Check warning on line 27 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L27

Added line #L27 was not covered by tests
vpDisplay::flush(I);
vpDisplay::setTitle(I, "Overlay");
std::cout << "Result of displaying a red circle on overlay on the display..." << std::endl;
std::cout << "Result of displaying a red circle on a gray level image overlay..." << std::endl;
std::cout << "A click to continue..." << std::endl;
vpDisplay::getClick(I);

Expand All @@ -38,11 +37,17 @@ int main()
vpImageDraw::drawCircle(I, circle2, 255, 2);
//! [Circle draw uchar]
vpDisplay::display(I);
vpDisplay::flush(I);
vpDisplay::setTitle(I, "Modification of a uchar image");
std::cout << "Result of the modification of a uchar image..." << std::endl;
vpDisplay::setTitle(I, "Display circle by modifying a gray level image");

Check warning on line 40 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L40

Added line #L40 was not covered by tests
std::cout << "Result of displaying a circle by modifying a gray level image..." << std::endl;
std::cout << "A click to continue..." << std::endl;
vpDisplay::flush(I);

Check warning on line 43 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L43

Added line #L43 was not covered by tests
vpDisplay::getClick(I);

#if defined(VISP_HAVE_DISPLAY)
if (d) {
delete d;

Check warning on line 48 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L48

Added line #L48 was not covered by tests
}
#endif
}

{
Expand All @@ -53,19 +58,23 @@ int main()
vpImageDraw::drawCircle(I_rgb, circle3, vpColor::blue, 2);
//! [Circle draw color]

#if defined(VISP_HAVE_X11)
vpDisplayX d_rgb(I_rgb, vpDisplay::SCALE_AUTO);
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI d_rgb(I_rgb, vpDisplay::SCALE_AUTO);
#if defined(VISP_HAVE_DISPLAY)
vpDisplay *d = vpDisplayFactory::displayFactory(I_rgb, vpDisplay::SCALE_AUTO);

Check warning on line 62 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L62

Added line #L62 was not covered by tests
#else
std::cout << "No gui available to display color image..." << std::endl;
#endif

vpDisplay::setTitle(I_rgb, "Color image");
vpDisplay::display(I_rgb);
vpDisplay::setTitle(I_rgb, "Display blue circle on a modified color image");

Check warning on line 68 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L68

Added line #L68 was not covered by tests
vpDisplay::flush(I_rgb);
vpDisplay::setTitle(I, "Modification of a vpRGBa image");
std::cout << "Result of the modification of a vpRGBa image..." << std::endl;
std::cout << "Result of displaying a blue circle on a modified color image..." << std::endl;
std::cout << "A click to continue..." << std::endl;
vpDisplay::getClick(I_rgb);
#if defined(VISP_HAVE_DISPLAY)
if (d) {
delete d;

Check warning on line 75 in tutorial/image/tutorial-draw-circle.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-circle.cpp#L75

Added line #L75 was not covered by tests
}
#endif
}
}
catch (const vpException &e) {
Expand Down
7 changes: 3 additions & 4 deletions tutorial/image/tutorial-draw-cross.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! \example tutorial-draw-cross.cpp
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayFactory.h>

int main()
{
vpImage<unsigned char> I(2160, 3840, 128);

try {

#if defined(VISP_HAVE_X11)
vpDisplayX d(I, vpDisplay::SCALE_AUTO);
#elif defined(VISP_HAVE_GDI)
Expand All @@ -22,7 +20,8 @@ int main()
vpDisplay::flush(I);
std::cout << "A click to quit..." << std::endl;
vpDisplay::getClick(I);
} catch (const vpException &e) {
}
catch (const vpException &e) {

Check warning on line 24 in tutorial/image/tutorial-draw-cross.cpp

View check run for this annotation

Codecov / codecov/patch

tutorial/image/tutorial-draw-cross.cpp#L24

Added line #L24 was not covered by tests
std::cout << "Catch an exception: " << e.getMessage() << std::endl;
}
std::cout << std::endl;
Expand Down
Loading

0 comments on commit 41d8d3b

Please sign in to comment.