Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testDisplayRoi.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 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
* Test for image roi display.
32
*/
33
40
41
#include <stdlib.h>
42
43
#include <visp3/core/vpImage.h>
44
#include <visp3/core/vpRect.h>
45
#include <visp3/gui/vpDisplayFactory.h>
46
#include <visp3/io/vpParseArgv.h>
47
48
// List of allowed command line options
49
#define GETOPTARGS "cdh"
50
51
#ifdef ENABLE_VISP_NAMESPACE
52
using namespace
VISP_NAMESPACE_NAME
;
53
#endif
54
55
void
usage(
const
char
*name,
const
char
*badparam);
56
bool
getOptions(
int
argc,
const
char
**argv,
bool
&click_allowed,
bool
&display);
57
66
void
usage(
const
char
*name,
const
char
*badparam)
67
{
68
fprintf(stdout,
"\n\
69
Read an image on the disk, display it using X11, display some\n\
70
features (line, circle, characters) in overlay and finally write \n\
71
the image and the overlayed features in an image on the disk.\n\
72
\n\
73
SYNOPSIS\n\
74
%s [-c] [-d] [-h]\n"
,
75
name);
76
77
fprintf(stdout,
"\n\
78
OPTIONS: Default\n\
79
-c\n\
80
Disable the mouse click. Useful to automate the \n\
81
execution of this program without human intervention.\n\
82
\n\
83
-d \n\
84
Disable the image display. This can be useful \n\
85
for automatic tests using crontab under Unix or \n\
86
using the task manager under Windows.\n\
87
\n\
88
-h\n\
89
Print the help.\n\n"
);
90
91
if
(badparam) {
92
fprintf(stderr,
"ERROR: \n"
);
93
fprintf(stderr,
"\nBad parameter [%s]\n"
, badparam);
94
}
95
}
96
112
bool
getOptions(
int
argc,
const
char
**argv,
bool
&click_allowed,
bool
&display)
113
{
114
const
char
*optarg_;
115
int
c;
116
while
((c =
vpParseArgv::parse
(argc, argv, GETOPTARGS, &optarg_)) > 1) {
117
118
switch
(c) {
119
case
'c'
:
120
click_allowed =
false
;
121
break
;
122
case
'd'
:
123
display =
false
;
124
break
;
125
case
'h'
:
126
usage(argv[0],
nullptr
);
127
return
false
;
128
129
default
:
130
usage(argv[0], optarg_);
131
return
false
;
132
}
133
}
134
135
if
((c == 1) || (c == -1)) {
136
// standalone param or error
137
usage(argv[0],
nullptr
);
138
std::cerr <<
"ERROR: "
<< std::endl;
139
std::cerr <<
" Bad argument "
<< optarg_ << std::endl << std::endl;
140
return
false
;
141
}
142
143
return
true
;
144
}
145
146
int
main(
int
argc,
const
char
**argv)
147
{
148
#ifdef VISP_HAVE_DISPLAY
149
bool
opt_click_allowed =
true
;
150
bool
opt_display =
true
;
151
152
// Read the command line options
153
if
(getOptions(argc, argv, opt_click_allowed, opt_display) ==
false
) {
154
return
EXIT_FAILURE;
155
}
156
157
if
(opt_display) {
158
159
vpImage<unsigned char>
I(480, 640, 255);
160
161
#if(VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
162
std::shared_ptr<vpDisplay>
d
=
vpDisplayFactory::createDisplay
();
163
#else
164
vpDisplay
*
d
=
vpDisplayFactory::allocateDisplay
();
165
#endif
166
d
->init(I);
167
vpDisplay::display
(I);
168
vpDisplay::flush
(I);
169
170
I = 0
u
;
171
172
vpRect
roi(I.getWidth() / 4, I.getHeight() / 4, I.getWidth() / 2, I.getHeight() / 2);
173
vpDisplay::displayROI
(I, roi);
174
vpDisplay::flush
(I);
175
if
(opt_click_allowed) {
176
std::cout <<
"A click in the image to continue..."
<< std::endl;
177
vpDisplay::getClick
(I);
178
}
179
vpDisplay::close
(I);
180
181
vpImage<vpRGBa>
C(480, 640,
vpRGBa
(255, 0, 0, 0));
182
183
d
->init(C);
184
vpDisplay::display
(C);
185
vpDisplay::flush
(C);
186
187
C =
vpRGBa
(0, 255, 0, 0);
188
189
vpDisplay::displayROI
(C, roi);
190
vpDisplay::flushROI
(C, roi);
191
if
(opt_click_allowed) {
192
std::cout <<
"A click in the image to exit..."
<< std::endl;
193
vpDisplay::getClick
(C);
194
}
195
#if(VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
196
delete
d
;
197
#endif
198
}
199
#else
200
(void)argc;
201
(void)argv;
202
#endif
203
return
EXIT_SUCCESS;
204
}
vpDisplay
Class that defines generic functionalities for display.
Definition
vpDisplay.h:171
vpDisplay::getClick
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Definition
vpDisplay_uchar.cpp:894
vpDisplay::displayROI
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition
vpDisplay_uchar.cpp:875
vpDisplay::display
static void display(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:869
vpDisplay::flushROI
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
Definition
vpDisplay_uchar.cpp:856
vpDisplay::close
static void close(vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:46
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:845
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
vpParseArgv::parse
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition
vpParseArgv.cpp:70
vpRGBa
Definition
vpRGBa.h:74
vpRect
Defines a rectangle in the plane.
Definition
vpRect.h:79
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
vpDisplayFactory::createDisplay
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:142
vpDisplayFactory::allocateDisplay
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:68
yolo-centering-task-afma6.d
d
Definition
yolo-centering-task-afma6.py:273
yolo-centering-task-afma6.u
u
Definition
yolo-centering-task-afma6.py:303
modules
gui
test
display
testDisplayRoi.cpp
Generated by
1.17.0