30 #include <QMouseEvent> 33 #include <QInputDialog> 43 setAttribute(Qt::WA_StaticContents);
49 menu_ =
new QMenu(tr(
""),
this);
56 QMenu * colorMap =
menu_->addMenu(
"Depth color map");
69 QActionGroup * group =
new QActionGroup(
this);
80 UASSERT(depth.type() == CV_32FC1 ||
81 depth.type() == CV_16UC1);
104 if( depth.cols != rgb.cols ||
105 depth.rows != rgb.rows)
122 image_.height() == modifiedImage.rows);
123 UASSERT(modifiedImage.type() == CV_32FC1 ||
124 modifiedImage.type() == CV_16UC1);
125 for(
int j=0; j<
image_.height(); ++j)
127 for(
int i=0; i<
image_.width(); ++i)
129 if(qRed(
image_.pixel(i, j)) == 0 &&
130 qGreen(
image_.pixel(i, j)) == 0 &&
131 qBlue(
image_.pixel(i, j)) == 0)
133 if(modifiedImage.type() == CV_32FC1)
135 modifiedImage.at<
float>(j,i) = 0.0
f;
139 modifiedImage.at<
unsigned short>(j,i) = 0;
145 return modifiedImage;
188 if (event->button() == Qt::LeftButton) {
189 float scale, offsetX, offsetY;
191 lastPoint_.setX((event->pos().x()-offsetX)/scale);
192 lastPoint_.setY((event->pos().y()-offsetY)/scale);
200 if ((event->buttons() & Qt::LeftButton) &&
scribbling_)
202 float scale, offsetX, offsetY;
205 to.setX((event->pos().x()-offsetX)/scale);
206 to.setY((event->pos().y()-offsetY)/scale);
213 if (event->button() == Qt::LeftButton &&
scribbling_) {
214 float scale, offsetX, offsetY;
217 to.setX((event->pos().x()-offsetX)/scale);
218 to.setY((event->pos().y()-offsetY)/scale);
233 float h =
image_.height();
234 float widthRatio = float(targetRect.width()) / w;
235 float heightRatio = float(targetRect.height()) / h;
238 if(widthRatio < heightRatio)
252 if(w < targetRect.width())
254 offsetX = (targetRect.width() - w)/2.0
f;
256 if(h < targetRect.height())
258 offsetY = (targetRect.height() - h)/2.0
f;
267 float ratio, offsetX, offsetY;
269 QPainter painter(
this);
271 painter.translate(offsetX, offsetY);
272 painter.scale(ratio, ratio);
276 painter.setOpacity(0.5);
277 painter.drawImage(QPoint(0,0),
imageRGB_);
280 painter.drawImage(QPoint(0,0),
image_);
285 QWidget::resizeEvent(event);
288 void floodfill(QRgb * bits,
const cv::Mat & depthImage,
int x,
int y,
float lastDepthValue,
float error,
int &iterations)
291 if(x>=0 && x<depthImage.cols &&
292 y>=0 && y<depthImage.rows)
295 if(depthImage.type() == CV_32FC1)
297 currentValue = depthImage.at<
float>(y, x);
301 currentValue = float(depthImage.at<
unsigned short>(y, x))/1000.0f;
303 if(currentValue == 0.0
f)
308 QRgb & rgb = bits[x+y*depthImage.cols];
309 if(qRed(rgb) == 0 && qGreen(rgb) == 0 && qBlue(rgb) == 0)
313 if(lastDepthValue>=0.0
f && fabs(lastDepthValue - currentValue) > error*lastDepthValue)
319 if(y+1<depthImage.rows)
321 QRgb & rgb = bits[x+(y+1)*depthImage.cols];
322 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
324 floodfill(bits, depthImage, x, y+1, currentValue, error, iterations);
329 QRgb & rgb = bits[x+(y-1)*depthImage.cols];
330 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
332 floodfill(bits, depthImage, x, y-1, currentValue, error, iterations);
335 if(x+1<depthImage.cols)
337 QRgb & rgb = bits[x+1+y*depthImage.cols];
338 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
340 floodfill(bits, depthImage, x+1, y, currentValue, error, iterations);
345 QRgb & rgb = bits[x-1+y*depthImage.cols];
346 if(qRed(rgb) != 0 || qGreen(rgb) != 0 || qBlue(rgb) != 0)
348 floodfill(bits, depthImage, x-1, y, currentValue, error, iterations);
356 QAction * action =
menu_->exec(e->globalPos());
363 float scale, offsetX, offsetY;
366 pixel.setX((e->pos().x()-offsetX)/scale);
367 pixel.setY((e->pos().y()-offsetY)/scale);
380 double error = QInputDialog::getDouble(
this, tr(
"Set Cluster Error"), tr(
"Error:"),
clusterError(), 0.001, 1, 3, &ok);
390 int width = QInputDialog::getInt(
this, tr(
"Set Pen Width"), tr(
"Width (pixels):"),
penWidth(), 1, 999, 1, &ok);
424 QPainter painter(&
image_);
425 painter.setPen(QPen(Qt::black,
myPenWidth_, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
void setImage(const cv::Mat &depth, const cv::Mat &rgb=cv::Mat())
EditDepthArea(QWidget *parent=0)
QAction * colorMapRedToBlue_
void drawLineTo(const QPoint &endPoint)
void setPenWidth(int newWidth)
QAction * clusterErrorCluster_
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack, float depthMin=0, float depthMax=0)
GLM_FUNC_DECL genType e()
void setColorMap(uCvQtDepthColorMap type)
virtual void resizeEvent(QResizeEvent *event)
virtual void contextMenuEvent(QContextMenuEvent *e)
virtual void mouseMoveEvent(QMouseEvent *event)
QAction * colorMapWhiteToBlack_
#define UASSERT(condition)
virtual void mouseReleaseEvent(QMouseEvent *event)
void floodfill(QRgb *bits, const cv::Mat &depthImage, int x, int y, float lastDepthValue, float error, int &iterations)
QAction * colorMapBlackToWhite_
virtual void mousePressEvent(QMouseEvent *event)
cv::Mat getModifiedImage() const
QAction * colorMapBlueToRed_
double clusterError() const
ULogger class and convenient macros.
virtual void paintEvent(QPaintEvent *event)
void computeScaleOffsets(const QRect &targetRect, float &scale, float &offsetX, float &offsetY) const