Nonoptimal image drawing function (Bug #2356)


Added by Alexander Naumov over 12 years ago. Updated over 12 years ago.


Status:Done Start date:2012-09-14
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:highgui-gui
Target version:2.4.3
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I've found a bug in highgui module with Qt support.
To draw image the data is firstly scaled to the current window size.
Then it is drawing with "painter->drawImage" function which also scales image according to the zoom level.
If the cvWindow is created with CV_WINDOW_NORMAL flag, zoom level > 1 and the image size is greater then window size, that leads to loss of data.

Current code in "window_QT.cpp":

void DefaultViewPort::draw2D(QPainter *painter)
{
    image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows,image2Draw_mat->step,QImage::Format_RGB888);
    image2Draw_qt_resized = image2Draw_qt.scaled(viewport()->width(),viewport()->height(),Qt::IgnoreAspectRatio,Qt::FastTransformation);//Qt::SmoothTransformation);
    painter->drawImage(0,0,image2Draw_qt_resized);
}

Proposed code:

void DefaultViewPort::draw2D(QPainter *painter)
{
    image2Draw_qt = QImage(image2Draw_mat->data.ptr, image2Draw_mat->cols, image2Draw_mat->rows,image2Draw_mat->step,QImage::Format_RGB888);
    painter->drawImage(QRect(0,0,viewport()->width(),viewport()->height()), image2Draw_qt, QRect(0,0, image2Draw_qt.width(), image2Draw_qt.height()) );
}


Associated revisions

Revision d9e801fb
Added by Vadim Pisarevsky over 12 years ago

improved image rendering performance in Qt backend for highgui UI (bug #2356)

Revision bcf43073
Added by Roman Donchenko about 11 years ago

Merge pull request #2356 from SpecLad:merge-2.4

History

Updated by Vadim Pisarevsky over 12 years ago

thanks! your patch was applied in d9e801

  • Status changed from Open to Done

Also available in: Atom PDF