New functions with QT GUI:
- imgregion (as with Matlab) implemented
This commit is contained in:
@@ -51,6 +51,8 @@ static bool multiThreads = false;
|
||||
static int last_key = -1;
|
||||
QWaitCondition key_pressed;
|
||||
QMutex mutexKey;
|
||||
|
||||
static const unsigned int threshold_zoom_img_region = 15;//the minimum zoom value to start displaying the values' grid
|
||||
//end static and global
|
||||
|
||||
double cvGetRatioWindow_QT(const char* name)
|
||||
@@ -990,6 +992,7 @@ ViewPort::ViewPort(CvWindow* arg, int arg2, int arg3)
|
||||
#endif
|
||||
|
||||
image2Draw_ipl=cvCreateImage(cvSize(centralWidget->width(),centralWidget->height()),IPL_DEPTH_8U,3);
|
||||
nbChannelOriginImage = 0;
|
||||
cvZero(image2Draw_ipl);
|
||||
|
||||
setInteractive(false);
|
||||
@@ -1093,9 +1096,7 @@ void ViewPort::updateImage(void* arr)
|
||||
cvReleaseImage(&image2Draw_ipl);
|
||||
image2Draw_ipl=cvCreateImage(cvGetSize(tempImage),IPL_DEPTH_8U,3);
|
||||
|
||||
ratioX=float(image2Draw_ipl->width)/float(width());
|
||||
ratioY=float(image2Draw_ipl->height)/float(height());
|
||||
|
||||
nbChannelOriginImage = tempImage->nChannels;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
@@ -1163,12 +1164,18 @@ void ViewPort::scaleView(qreal factor,QPointF center)
|
||||
factor/=5;//-0.1 <-> 0.1
|
||||
factor+=1;//0.9 <-> 1.1
|
||||
|
||||
//limit zoom out ---
|
||||
if (matrixWorld.m11()==1 && factor < 1)
|
||||
return;
|
||||
|
||||
if (matrixWorld.m11()*factor<1)
|
||||
factor = 1/matrixWorld.m11();
|
||||
|
||||
|
||||
//limit zoom int ---
|
||||
if (matrixWorld.m11()>100 && factor > 1)
|
||||
return;
|
||||
|
||||
//inverse the transform
|
||||
int a, b;
|
||||
matrixWorld_inv.map(center.x(),center.y(),&a,&b);
|
||||
@@ -1311,8 +1318,8 @@ void ViewPort::icvmouseProcessing(QPointF pt, int cv_event, int flags)
|
||||
//to convert mouse coordinate
|
||||
qreal pfx, pfy;
|
||||
matrixWorld_inv.map(pt.x(),pt.y(),&pfx,&pfy);
|
||||
mouseCoordinate.rx()=floor(pfx*ratioX);
|
||||
mouseCoordinate.ry()=floor(pfy*ratioY);
|
||||
mouseCoordinate.rx()=floor(pfx);
|
||||
mouseCoordinate.ry()=floor(pfy);
|
||||
|
||||
if (on_mouse)
|
||||
on_mouse( cv_event, mouseCoordinate.x(),mouseCoordinate.y(), flags, on_mouse_param );
|
||||
@@ -1333,8 +1340,10 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
||||
{
|
||||
|
||||
controlImagePosition();
|
||||
ratioX=float(image2Draw_ipl->width)/float(width());
|
||||
ratioY=float(image2Draw_ipl->height)/float(height());
|
||||
//ratioX=float(image2Draw_ipl->width)/float(width());
|
||||
//ratioY=float(image2Draw_ipl->height)/float(height());
|
||||
ratioX=width()/float(image2Draw_ipl->width);
|
||||
ratioY=height()/float(image2Draw_ipl->height);
|
||||
|
||||
if(keepRatio == CV_WINDOW_KEEPRATIO)//to keep the same aspect ratio
|
||||
{
|
||||
@@ -1358,7 +1367,6 @@ void ViewPort::resizeEvent ( QResizeEvent *event)
|
||||
return QGraphicsView::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void ViewPort::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter myPainter(viewport());
|
||||
@@ -1379,17 +1387,18 @@ void ViewPort::paintEvent(QPaintEvent* event)
|
||||
//in mode zoom/panning
|
||||
if (matrixWorld.m11()>1)
|
||||
{
|
||||
//if (size()>QSize())
|
||||
|
||||
myPainter.setWorldMatrixEnabled (false );
|
||||
drawOverview(&myPainter);
|
||||
|
||||
if (matrixWorld.m11()>=threshold_zoom_img_region)
|
||||
drawImgRegion(&myPainter);
|
||||
|
||||
drawViewOverview(&myPainter);
|
||||
|
||||
}
|
||||
|
||||
//for statusbar
|
||||
if (mouseCoordinate.x()>=0 && mouseCoordinate.y()>=0 &&
|
||||
mouseCoordinate.x()<image2Draw_ipl->width && mouseCoordinate.y()<image2Draw_ipl->height)
|
||||
{
|
||||
drawStatusBar();
|
||||
}
|
||||
|
||||
//for information overlay
|
||||
if (drawInfo)
|
||||
@@ -1404,14 +1413,24 @@ void ViewPort::paintEvent(QPaintEvent* event)
|
||||
void ViewPort::draw2D(QPainter *painter)
|
||||
{
|
||||
image2Draw_qt = QImage((uchar*) image2Draw_ipl->imageData, image2Draw_ipl->width, image2Draw_ipl->height,QImage::Format_RGB888);
|
||||
// painter->drawImage(0,0,image2Draw_qt.scaled(this->width(),this->height(),Qt::KeepAspectRatio));
|
||||
painter->drawImage(0,0,image2Draw_qt.scaled(this->width(),this->height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ViewPort::drawStatusBar()
|
||||
{
|
||||
//centralWidget->myBar_msg->setMaximumWidth(width());
|
||||
//CvScalar value = cvGet2D(image2Draw_ipl,mouseCoordinate.y(),mouseCoordinate.x());
|
||||
if (mouseCoordinate.x()>=0 &&
|
||||
mouseCoordinate.y()>=0 &&
|
||||
mouseCoordinate.x()<image2Draw_ipl->width &&
|
||||
mouseCoordinate.y()<image2Draw_ipl->height)
|
||||
{
|
||||
QRgb rgbValue = image2Draw_qt.pixel(mouseCoordinate);
|
||||
|
||||
if (nbChannelOriginImage==3)
|
||||
{
|
||||
centralWidget->myBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
|
||||
.arg(mouseCoordinate.x())
|
||||
.arg(mouseCoordinate.y())+
|
||||
@@ -1419,23 +1438,107 @@ void ViewPort::drawStatusBar()
|
||||
tr("<font color='green'>G:%4 </font>").arg(qGreen(rgbValue))+//.arg(value.val[1])+
|
||||
tr("<font color='blue'>B:%5</font>").arg(qBlue(rgbValue))//.arg(value.val[2])
|
||||
);
|
||||
}else{
|
||||
//all the channel have the same value (because of cvconvertimage), so only the r channel is dsplayed
|
||||
centralWidget->myBar_msg->setText(tr("<font color='black'>Coordinate: %1x%2 ~ </font>")
|
||||
.arg(mouseCoordinate.x())
|
||||
.arg(mouseCoordinate.y())+
|
||||
tr("<font color='grey'>grey:%3 </font>").arg(qRed(rgbValue))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewPort::drawOverview(QPainter *painter)
|
||||
void ViewPort::drawImgRegion(QPainter *painter)
|
||||
{
|
||||
qreal offsetX = matrixWorld.dx()/matrixWorld.m11();
|
||||
offsetX = offsetX - floor(offsetX);
|
||||
qreal offsetY = matrixWorld.dy()/matrixWorld.m11();
|
||||
offsetY = offsetY - floor(offsetY);
|
||||
|
||||
QSize view = size();
|
||||
QVarLengthArray<QLineF, 30> linesX;
|
||||
for (qreal x = offsetX*matrixWorld.m11(); x < view.width(); x += matrixWorld.m11() )
|
||||
linesX.append(QLineF(x, 0, x, view.height()));
|
||||
|
||||
QVarLengthArray<QLineF, 30> linesY;
|
||||
for (qreal y = offsetY*matrixWorld.m11(); y < view.height(); y += matrixWorld.m11() )
|
||||
linesY.append(QLineF(0, y, view.width(), y));
|
||||
|
||||
|
||||
QFont f = painter->font();
|
||||
f.setPointSize(threshold_zoom_img_region/3+(matrixWorld.m11()-threshold_zoom_img_region)/6);
|
||||
//f.setStretch(0);
|
||||
painter->setFont(f);
|
||||
QString val;
|
||||
QRgb rgbValue;
|
||||
|
||||
QPointF point1;//sorry, I do not know how to name it
|
||||
QPointF point2;//idem
|
||||
|
||||
|
||||
for (int j=-1;j<view.height()/matrixWorld.m11();j++)
|
||||
for (int i=-1;i<view.width()/matrixWorld.m11();i++)
|
||||
{
|
||||
point1.setX((i+offsetX)*matrixWorld.m11());
|
||||
point1.setY((j+offsetY)*matrixWorld.m11());
|
||||
|
||||
matrixWorld_inv.map(point1.x(),point1.y(),&point2.rx(),&point2.ry());
|
||||
|
||||
if (point2.x() >= 0 && point2.y() >= 0)
|
||||
rgbValue = image2Draw_qt.pixel(QPoint(point2.x(),point2.y()));
|
||||
else
|
||||
rgbValue = qRgb(0,0,0);
|
||||
|
||||
const int margin = 1;
|
||||
if (nbChannelOriginImage==3)
|
||||
{
|
||||
val = tr("%1").arg(qRed(rgbValue));
|
||||
painter->setPen(QPen(Qt::red, 1));
|
||||
painter->drawText(QRect(point1.x(),point1.y()+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
||||
Qt::AlignCenter, val);
|
||||
|
||||
val = tr("%1").arg(qGreen(rgbValue));
|
||||
painter->setPen(QPen(Qt::green, 1));
|
||||
painter->drawText(QRect(point1.x(),point1.y()+matrixWorld.m11()/3+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
||||
Qt::AlignCenter, val);
|
||||
|
||||
val = tr("%1").arg(qBlue(rgbValue));
|
||||
painter->setPen(QPen(Qt::blue, 1));
|
||||
painter->drawText(QRect(point1.x(),point1.y()+2*matrixWorld.m11()/3+margin,matrixWorld.m11(),matrixWorld.m11()/3),
|
||||
Qt::AlignCenter, val);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
val = tr("%1").arg(qRed(rgbValue));
|
||||
painter->drawText(QRect(point1.x(),point1.y(),matrixWorld.m11(),matrixWorld.m11()),
|
||||
Qt::AlignCenter, val);
|
||||
}
|
||||
}
|
||||
|
||||
painter->setPen(QPen(Qt::black, 1));
|
||||
painter->drawLines(linesX.data(), linesX.size());
|
||||
painter->drawLines(linesY.data(), linesY.size());
|
||||
|
||||
}
|
||||
|
||||
void ViewPort::drawViewOverview(QPainter *painter)
|
||||
{
|
||||
QSize viewSize = size();
|
||||
viewSize.scale ( 100, 100,Qt::KeepAspectRatio );
|
||||
|
||||
const int margin = 5;
|
||||
|
||||
//draw the image's location
|
||||
painter->setBrush(QColor(0, 0, 0, 127));
|
||||
painter->setPen(Qt::darkGreen);
|
||||
|
||||
painter->drawRect(QRect(width()-viewSize.width()-margin, 0,viewSize.width(),viewSize.height()));
|
||||
|
||||
//daw the view's location inside the image
|
||||
qreal ratioSize = 1/matrixWorld.m11();
|
||||
qreal ratioWindow = (qreal)(viewSize.height())/(qreal)(size().height());
|
||||
|
||||
painter->setPen(Qt::darkBlue);
|
||||
painter->drawRect(QRectF(width()-viewSize.width()-positionCorners.left()*ratioSize*ratioWindow-margin,
|
||||
-positionCorners.top()*ratioSize*ratioWindow,
|
||||
|
||||
@@ -197,6 +197,7 @@ public:
|
||||
|
||||
IplImage* image2Draw_ipl;
|
||||
QImage image2Draw_qt;
|
||||
int nbChannelOriginImage;
|
||||
void setRatio(int flags);
|
||||
int getRatio();
|
||||
|
||||
@@ -247,7 +248,8 @@ private:
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
void drawInstructions(QPainter *painter);
|
||||
void drawOverview(QPainter *painter);
|
||||
void drawViewOverview(QPainter *painter);
|
||||
void drawImgRegion(QPainter *painter);
|
||||
void draw2D(QPainter *painter);
|
||||
void drawStatusBar();
|
||||
void controlImagePosition();
|
||||
|
||||
Reference in New Issue
Block a user