30 #include <QMouseEvent>
33 #include <QActionGroup>
34 #include <QInputDialog>
44 setAttribute(Qt::WA_StaticContents);
50 menu_ =
new QMenu(tr(
""),
this);
57 QMenu * colorMap =
menu_->addMenu(
"Depth color map");
70 QActionGroup * group =
new QActionGroup(
this);
81 UASSERT(depth.type() == CV_32FC1 ||
82 depth.type() == CV_16UC1);
105 if( depth.cols != rgb.cols ||
106 depth.rows != rgb.rows)
123 image_.height() == modifiedImage.rows);
124 UASSERT(modifiedImage.type() == CV_32FC1 ||
125 modifiedImage.type() == CV_16UC1);
134 if(modifiedImage.type() == CV_32FC1)
136 modifiedImage.at<
float>(
j,
i) = 0.0
f;
140 modifiedImage.at<
unsigned short>(
j,
i) = 0;
146 return modifiedImage;
189 if (event->button() == Qt::LeftButton) {
190 float scale, offsetX, offsetY;
201 if ((event->buttons() & Qt::LeftButton) &&
scribbling_)
203 float scale, offsetX, offsetY;
206 to.setX((event->pos().x()-offsetX)/
scale);
207 to.setY((event->pos().y()-offsetY)/
scale);
214 if (event->button() == Qt::LeftButton &&
scribbling_) {
215 float scale, offsetX, offsetY;
218 to.setX((event->pos().x()-offsetX)/
scale);
219 to.setY((event->pos().y()-offsetY)/
scale);
235 float widthRatio =
float(targetRect.width()) /
w;
236 float heightRatio =
float(targetRect.height()) /
h;
239 if(widthRatio < heightRatio)
253 if(
w < targetRect.width())
255 offsetX = (targetRect.width() -
w)/2.0
f;
257 if(
h < targetRect.height())
259 offsetY = (targetRect.height() -
h)/2.0
f;
268 float ratio, offsetX, offsetY;
270 QPainter painter(
this);
272 painter.translate(offsetX, offsetY);
277 painter.setOpacity(0.5);
278 painter.drawImage(QPoint(0,0),
imageRGB_);
281 painter.drawImage(QPoint(0,0),
image_);
286 QWidget::resizeEvent(event);
289 void floodfill(QRgb * bits,
const cv::Mat & depthImage,
int x,
int y,
float lastDepthValue,
float error,
int &iterations)
292 if(
x>=0 &&
x<depthImage.cols &&
293 y>=0 &&
y<depthImage.rows)
296 if(depthImage.type() == CV_32FC1)
298 currentValue = depthImage.at<
float>(
y,
x);
302 currentValue =
float(depthImage.at<
unsigned short>(
y,
x))/1000.0f;
304 if(currentValue == 0.0
f)
309 QRgb & rgb =
bits[
x+
y*depthImage.cols];
310 if(qRed(rgb) == 0 && qGreen(rgb) == 0 && qBlue(rgb) == 0)
314 if(lastDepthValue>=0.0
f &&
fabs(lastDepthValue - currentValue) >
error*lastDepthValue)
320 if(
y+1<depthImage.rows)
322 QRgb & rgb =
bits[
x+(
y+1)*depthImage.cols];
323 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
330 QRgb & rgb =
bits[
x+(
y-1)*depthImage.cols];
331 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
336 if(
x+1<depthImage.cols)
338 QRgb & rgb =
bits[
x+1+
y*depthImage.cols];
339 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
346 QRgb & rgb =
bits[
x-1+
y*depthImage.cols];
347 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
364 float scale, offsetX, offsetY;
367 pixel.setX((
e->pos().x()-offsetX)/
scale);
368 pixel.setY((
e->pos().y()-offsetY)/
scale);
381 double error = QInputDialog::getDouble(
this, tr(
"Set Cluster Error"), tr(
"Error:"),
clusterError(), 0.001, 1, 3, &ok);
391 int width = QInputDialog::getInt(
this, tr(
"Set Pen Width"), tr(
"Width (pixels):"),
penWidth(), 1, 999, 1, &ok);
425 QPainter painter(&
image_);
426 painter.setPen(QPen(Qt::black,
myPenWidth_, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));