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