30 #include <QMouseEvent> 33 #include <QInputDialog> 44 setAttribute(Qt::WA_StaticContents);
49 menu_ =
new QMenu(tr(
""),
this);
61 UASSERT(depth.type() == CV_32FC1 ||
62 depth.type() == CV_16UC1);
70 if( depth.cols != rgb.cols ||
71 depth.rows != rgb.rows)
88 image_.height() == modifiedImage.rows);
89 UASSERT(modifiedImage.type() == CV_32FC1 ||
90 modifiedImage.type() == CV_16UC1);
91 for(
int j=0; j<
image_.height(); ++j)
93 for(
int i=0; i<
image_.width(); ++i)
95 if(qRed(
image_.pixel(i, j)) == 0 &&
96 qGreen(
image_.pixel(i, j)) == 0 &&
97 qBlue(
image_.pixel(i, j)) == 0)
99 if(modifiedImage.type() == CV_32FC1)
101 modifiedImage.at<
float>(j,i) = 0.0
f;
105 modifiedImage.at<
unsigned short>(j,i) = 0;
111 return modifiedImage;
128 if (event->button() == Qt::LeftButton) {
129 float scale, offsetX, offsetY;
131 lastPoint_.setX((event->pos().x()-offsetX)/scale);
132 lastPoint_.setY((event->pos().y()-offsetY)/scale);
140 if ((event->buttons() & Qt::LeftButton) &&
scribbling_)
142 float scale, offsetX, offsetY;
145 to.setX((event->pos().x()-offsetX)/scale);
146 to.setY((event->pos().y()-offsetY)/scale);
153 if (event->button() == Qt::LeftButton &&
scribbling_) {
154 float scale, offsetX, offsetY;
157 to.setX((event->pos().x()-offsetX)/scale);
158 to.setY((event->pos().y()-offsetY)/scale);
173 float h =
image_.height();
174 float widthRatio = float(targetRect.width()) / w;
175 float heightRatio = float(targetRect.height()) / h;
178 if(widthRatio < heightRatio)
192 if(w < targetRect.width())
194 offsetX = (targetRect.width() - w)/2.0
f;
196 if(h < targetRect.height())
198 offsetY = (targetRect.height() - h)/2.0
f;
207 float ratio, offsetX, offsetY;
209 QPainter painter(
this);
211 painter.translate(offsetX, offsetY);
212 painter.scale(ratio, ratio);
216 painter.setOpacity(0.5);
217 painter.drawImage(QPoint(0,0),
imageRGB_);
220 painter.drawImage(QPoint(0,0),
image_);
225 QWidget::resizeEvent(event);
228 void floodfill(QImage & image,
const cv::Mat & depthImage,
int x,
int y,
float lastDepthValue,
float error)
230 if(x>=0 && x<depthImage.cols &&
231 y>=0 && y<depthImage.rows)
234 if(depthImage.type() == CV_32FC1)
236 currentValue = depthImage.at<
float>(y, x);
240 currentValue = float(depthImage.at<
unsigned short>(y, x))/1000.0f;
243 QRgb rgb = image.pixel(x,y);
244 if(qRed(rgb) == 0 && qGreen(rgb) == 0 && qBlue(rgb) == 0)
248 if(currentValue == 0.0
f)
252 if(lastDepthValue>=0.0
f && fabs(lastDepthValue - currentValue) > error*lastDepthValue)
257 image.setPixel(x, y, 0);
259 floodfill(image, depthImage, x, y+1, currentValue, error);
260 floodfill(image, depthImage, x, y-1, currentValue, error);
261 floodfill(image, depthImage, x-1, y, currentValue, error);
262 floodfill(image, depthImage, x+1, y, currentValue, error);
268 QAction * action =
menu_->exec(e->globalPos());
275 float scale, offsetX, offsetY;
278 pixel.setX((e->pos().x()-offsetX)/scale);
279 pixel.setY((e->pos().y()-offsetY)/scale);
291 int width = QInputDialog::getInt(
this, tr(
"Set Pen Width"), tr(
"Width:"),
penWidth(), 1, 99, 1, &ok);
305 QPainter painter(&
image_);
306 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)
void drawLineTo(const QPoint &endPoint)
void setPenWidth(int newWidth)
GLM_FUNC_DECL genType e()
virtual void resizeEvent(QResizeEvent *event)
virtual void contextMenuEvent(QContextMenuEvent *e)
virtual void mouseMoveEvent(QMouseEvent *event)
#define UASSERT(condition)
cv::Mat getModifiedImage() const
virtual void mouseReleaseEvent(QMouseEvent *event)
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack)
void computeScaleOffsets(const QRect &targetRect, float &scale, float &offsetX, float &offsetY) const
virtual void mousePressEvent(QMouseEvent *event)
void floodfill(QImage &image, const cv::Mat &depthImage, int x, int y, float lastDepthValue, float error)
ULogger class and convenient macros.
virtual void paintEvent(QPaintEvent *event)