Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
manDisplay.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Display example.
32 */
33
40
41#include <visp3/core/vpColor.h>
42#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpImage.h>
44#include <visp3/core/vpImagePoint.h>
45#include <visp3/gui/vpDisplayGTK.h>
46#include <visp3/io/vpImageIo.h>
47
48int main()
49{
50#ifdef ENABLE_VISP_NAMESPACE
51 using namespace VISP_NAMESPACE_NAME;
52#endif
53
54 try {
55 // Create a grey level image
57
58 // Create image points for pixel coordinates
59 vpImagePoint ip, ip1, ip2;
60
61 // Load a grey image from the disk. Klimt.ppm image is part of the ViSP
62 // image data set available from
63 // http://www.irisa.fr/lagadic/visp/download.html
64 std::string filename = "./Klimt.ppm";
65 vpImageIo::read(I, filename);
66
67#ifdef VISP_HAVE_GTK
68 // Create a display using GTK
69 vpDisplayGTK display;
70
71 // For this grey level image, open a GTK display at position 100,100
72 // in the screen, and with title "GTK display"
73 display.init(I, 100, 100, "GTK display");
74
75 // Display the image
77
78 // Display in overlay a red cross at position 100,10 in the
79 // image. The lines are 20 pixels long
80 ip.set_i(200);
81 ip.set_j(200);
83
84 // Display in overlay a horizontal red line
85 ip1.set_i(10);
86 ip1.set_j(0);
87 ip2.set_i(10);
88 ip2.set_j(I.getWidth());
89 vpDisplay::displayLine(I, ip1, ip2, vpColor::red, 3);
90
91 // Display in overlay a vertical green dot line
92 ip1.set_i(0);
93 ip1.set_j(20);
94 ip2.set_i(I.getWidth());
95 ip2.set_j(20);
97
98 // Display in overlay a blue arrow
99 ip1.set_i(0);
100 ip1.set_j(0);
101 ip2.set_i(100);
102 ip2.set_j(100);
103 vpDisplay::displayArrow(I, ip1, ip2, vpColor::blue, 8, 4, 3);
104
105 // Display in overlay some circles. The position of the center is 200, 200
106 // the radius is increased by 20 pixels for each circle
107 for (unsigned i = 0; i < 5; i++) {
108 ip.set_i(200);
109 ip.set_j(200);
110 vpDisplay::displayCircle(I, ip, 20 * i, vpColor::white, false, 3);
111 }
112
113 // Display in overlay a rectangle.
114 // The position of the top left corner is 300, 200.
115 // The width is 200. The height is 100.
116 ip.set_i(280);
117 ip.set_j(150);
118 vpDisplay::displayRectangle(I, ip, 270, 30, vpColor::purple, false, 3);
119
120 // Display in overlay a yellow string
121 ip.set_i(300);
122 ip.set_j(160);
123 vpDisplay::displayText(I, ip, "ViSP is a marvelous software", vpColor::black);
124 // Flush the display : without this line nothing will appear on the screen
126
127 // Create a color image
128 vpImage<vpRGBa> Ioverlay;
129 // Updates the color image with the original loaded image and the overlay
130 vpDisplay::getImage(I, Ioverlay);
131
132 // Write the color image on the disk
133 filename = "./Klimt.overlay.ppm";
134 vpImageIo::write(Ioverlay, filename);
135
136 // If click is allowed, wait for a mouse click to close the display
137 std::cout << "\nA click to close the windows..." << std::endl;
138 // Wait for a blocking mouse click
140
141 // Close the display
143#endif
144
145 return EXIT_SUCCESS;
146 }
147 catch (const vpException &e) {
148 std::cout << "Catch an exception: " << e << std::endl;
149 return EXIT_FAILURE;
150 }
151}
static const vpColor white
Definition vpColor.h:193
static const vpColor red
Definition vpColor.h:198
static const vpColor blue
Definition vpColor.h:204
static const vpColor purple
Definition vpColor.h:209
static const vpColor black
Definition vpColor.h:192
static const vpColor green
Definition vpColor.h:201
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") VP_OVERRIDE
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void close(vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
Definition vpException.h:60
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_j(double jj)
void set_i(double ii)
Definition of the vpImage class member functions.
Definition vpImage.h:131