39 #include <visp3/ustk_gui/usImageDisplayWidgetQmlOverlayServoing.h>
41 #if (defined(USTK_HAVE_VTK_QT5) || defined(USTK_HAVE_QT5))
49 :
usImageDisplayWidget(), m_qQuickOverlay(), m_useFeatureDisplay(false), m_confidence(), m_plot(), m_startTime()
51 this->setMinimumSize(200, 200);
52 m_qQuickOverlay =
new QQuickWidget(
m_label);
53 m_qQuickOverlay->setAttribute(Qt::WA_AlwaysStackOnTop);
54 m_qQuickOverlay->setClearColor(Qt::transparent);
55 m_qQuickOverlay->setSource(QUrl(
"qrc:/qml/overlay-servoing-rect-centering.qml"));
57 connect(m_qQuickOverlay->rootObject(), SIGNAL(startTracking()),
this, SLOT(
startTrackingSlot()));
58 connect(m_qQuickOverlay->rootObject(), SIGNAL(stopTracking()),
this, SIGNAL(
stopTrackingRect()));
59 connect(m_qQuickOverlay->rootObject(), SIGNAL(startServoing()),
this, SIGNAL(
startServoingRect()));
60 connect(m_qQuickOverlay->rootObject(), SIGNAL(stopServoing()),
this, SIGNAL(
stopServoingRect()));
62 QQuickWidget::Status status(QQuickWidget::Null);
64 while (status != QQuickWidget::Ready) {
65 status = m_qQuickOverlay->status();
69 #if defined(VISP_HAVE_GDI)
70 m_display =
new vpDisplayGDI;
71 #elif defined(VISP_HAVE_OPENCV)
72 m_display =
new vpDisplayOpenCV;
85 if (m_qQuickOverlay->rootObject()) {
86 m_qQuickOverlay->rootObject()->setProperty(
"width", event->size().width());
87 m_qQuickOverlay->rootObject()->setProperty(
"height", event->size().height());
89 QObject *rectItem = m_qQuickOverlay->rootObject()->findChild<QObject *>(
"selectionRectangle");
91 int x = rectItem->property(
"x").toInt() *
event->size().height() / (double)size().height();
92 int y = rectItem->property(
"y").toInt() *
event->size().width() / (double)size().width();
93 rectItem->setProperty(
"x", x);
94 rectItem->setProperty(
"y", y);
108 QImage::Format_Indexed8);
110 m_QImage = QImage(img.bitmap, img.getWidth(), img.getHeight(), img.getWidth(), QImage::Format_Indexed8);
112 QImage I =
m_QImage.convertToFormat(QImage::Format_RGB888);
113 I = I.scaled(this->width(), this->height());
119 if (m_useFeatureDisplay) {
120 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
121 if (m_confidence.getSize() > 0) {
122 if (m_confidence.display == NULL)
123 m_display->init(m_confidence);
124 vpDisplay::display(m_confidence);
130 vpImagePoint usImageDisplayWidgetQmlOverlayServoing::displayImageToRealImageDimentions(
const vpImagePoint displayPoint)
133 unsigned int imageHeight;
134 unsigned int imageWidth;
139 imageHeight =
m_image.getHeight();
140 imageWidth =
m_image.getWidth();
142 p.set_i((displayPoint.get_i() * imageHeight) / (
double)height());
143 p.set_j((displayPoint.get_j() * imageWidth) / (
double)width());
149 usImageDisplayWidgetQmlOverlayServoing::realImageToDisplayImageDimentions(
const vpImagePoint realImagePoint)
152 unsigned int imageHeight;
153 unsigned int imageWidth;
158 imageHeight =
m_image.getHeight();
159 imageWidth =
m_image.getWidth();
161 p.set_i((realImagePoint.get_i() * height()) / (
double)imageHeight);
162 p.set_j((realImagePoint.get_j() * width()) / (
double)imageWidth);
168 usImageDisplayWidgetQmlOverlayServoing::displayImageToRealImageDimentions(
const vpRectOriented displayRectangle)
172 center = displayImageToRealImageDimentions(displayRectangle.getCenter());
175 unsigned int imageHeight;
176 unsigned int imageWidth;
181 imageHeight =
m_image.getHeight();
182 imageWidth =
m_image.getWidth();
185 (displayRectangle.getHeight() * imageHeight / (double)height()) * std::cos(displayRectangle.getOrientation()) +
186 (displayRectangle.getWidth() * imageWidth / (double)width()) * std::sin(displayRectangle.getOrientation());
188 (displayRectangle.getHeight() * imageHeight / (double)height()) * std::sin(displayRectangle.getOrientation()) +
189 (displayRectangle.getWidth() * imageWidth / (double)width()) * std::cos(displayRectangle.getOrientation());
191 return vpRectOriented(center, newWidth, newHeight, displayRectangle.getOrientation());
195 usImageDisplayWidgetQmlOverlayServoing::realImageToDisplayImageDimentions(
const vpRectOriented realRectangle)
199 center = realImageToDisplayImageDimentions(realRectangle.getCenter());
202 unsigned int imageHeight;
203 unsigned int imageWidth;
208 imageHeight =
m_image.getHeight();
209 imageWidth =
m_image.getWidth();
212 (realRectangle.getHeight() * height() / (double)imageHeight) * std::cos(realRectangle.getOrientation()) +
213 (realRectangle.getWidth() * width() / (double)imageWidth) * std::sin(realRectangle.getOrientation());
216 (realRectangle.getHeight() * height() / (double)imageHeight) * std::sin(realRectangle.getOrientation()) +
217 (realRectangle.getWidth() * width() / (double)imageWidth) * std::cos(realRectangle.getOrientation());
219 return vpRectOriented(center, newWidth, newHeight, realRectangle.getOrientation());
229 vpRectOriented displayRectangle;
230 displayRectangle = realImageToDisplayImageDimentions(newRectangle);
232 QObject *rectItem = m_qQuickOverlay->rootObject()->findChild<QObject *>(
"selectionRectangle");
233 rectItem->setProperty(
"x", displayRectangle.getCenter().get_j() - (displayRectangle.getWidth() / 2.0));
234 rectItem->setProperty(
"y", displayRectangle.getCenter().get_i() - (displayRectangle.getHeight() / 2.0));
235 rectItem->setProperty(
"rotation", vpMath::deg(displayRectangle.getOrientation()));
236 rectItem->setProperty(
"height", displayRectangle.getHeight());
237 rectItem->setProperty(
"width", displayRectangle.getWidth());
246 QObject *rectangleObject = m_qQuickOverlay->rootObject()->findChild<QObject *>(
"selectionRectangle");
247 int topLeftX = rectangleObject->property(
"x").toInt();
248 int topLeftY = rectangleObject->property(
"y").toInt();
249 int height = rectangleObject->property(
"height").toInt();
250 int width = rectangleObject->property(
"width").toInt();
251 int centerX = topLeftX + (width / 2.0);
252 int centerY = topLeftY + (height / 2.0);
253 int rotation = rectangleObject->property(
"rotation").toInt();
255 vpRectOriented displayRect(vpImagePoint(centerY, centerX), width, height, vpMath::rad(rotation));
262 m_useFeatureDisplay =
true;
265 m_plot.initGraph(0, 1);
266 m_plot.setTitle(0,
"confidence barycenter error");
267 m_plot.setUnitY(0,
"error");
268 m_plot.setLegend(0, 0,
"time");
269 m_plot.initGraph(1, 1);
270 m_plot.setTitle(1,
"Lateral tracking error");
271 m_plot.setUnitY(1,
"error");
272 m_plot.setLegend(1, 0,
"time");
273 m_startTime = vpTime::measureTimeMs();
280 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
281 if (m_useFeatureDisplay) {
282 vpImagePoint p0 = vpImagePoint(0, scanline);
283 vpImagePoint p1 = vpImagePoint(m_confidence.getHeight() - 1, scanline);
284 vpImagePoint p2 = vpImagePoint(0, m_confidence.getWidth() / 2);
285 vpImagePoint p3 = vpImagePoint(m_confidence.getHeight() - 1, m_confidence.getWidth() / 2);
286 vpDisplay::displayLine(m_confidence, p0, p1, vpColor::red);
287 vpDisplay::displayLine(m_confidence, p2, p3, vpColor::green);
288 vpDisplay::flush(m_confidence);
291 m_plot.plot(0, 0, vpTime::measureTimeMs() - m_startTime,
299 m_confidence = confidence;
304 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))
305 if (m_useFeatureDisplay) {
307 m_plot.plot(1, 0, vpTime::measureTimeMs() - m_startTime, error);
void convert(const usImagePreScan2D< unsigned char > &preScanImage, usImagePostScan2D< unsigned char > &postScanImage, double xResolution=0., double yResolution=0.)
double getFieldOfView() const
double getScanLinePitch() const