Skip to content

Commit

Permalink
[opti] interactive: optimize image display
Browse files Browse the repository at this point in the history
  • Loading branch information
bgallois committed Feb 8, 2022
1 parent 7eecb88 commit 36b4034
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,7 @@ void Interactive::display(int index, int scale) {
if ((roi.width != 0 || roi.height != 0) && (roi.width != originalImageSize.width() || roi.height != originalImageSize.height())) {
frame = frame(roi);
}

Mat image = frame.getMat(ACCESS_READ);
display(QImage(image.data, image.cols, image.rows, static_cast<int>(image.step), QImage::Format_RGB888));
display(frame);
}
catch (...) {
emit(message(QString("An error occurs on image %1.").arg(index)));
Expand Down Expand Up @@ -728,11 +726,11 @@ void Interactive::display(const QImage &image) {

/**
* @brief This is an overloaded function to display a UMat in the display.
* @param[in] image UMat to display.
* @param[in] format enum QImage::Format.
*/
void Interactive::display(const UMat &image) {
Mat frame = image.getMat(ACCESS_READ);
cvtColor(frame, frame, COLOR_GRAY2RGB);
resizedPix = (QPixmap::fromImage(QImage(frame.data, frame.cols, frame.rows, static_cast<int>(frame.step), QImage::Format_RGB888)).scaled(ui->display->size(), Qt::KeepAspectRatio));
void Interactive::display(const UMat &image, QImage::Format format) {
resizedPix = (QPixmap::fromImage(QImage(image.u->data, image.cols, image.rows, static_cast<int>(image.step), format)).scaled(ui->display->size(), Qt::KeepAspectRatio));
ui->display->setPixmap(resizedPix);
resizedFrame.setWidth(resizedPix.width());
resizedFrame.setHeight(resizedPix.height());
Expand All @@ -756,7 +754,7 @@ void Interactive::computeBackground() {
// After compute background process
QFutureWatcher<UMat> *watcher = new QFutureWatcher<UMat>();
connect(watcher, &QFutureWatcher<UMat>::finished, [this, watcher]() {
background = watcher->result();
background = watcher->result().clone(); // Clone needed for Windows otherwise no initial display and ui buggued afterward, why if UMat is a smartpointer?
if (!background.empty()) {
isBackground = true;
ui->isBin->setCheckable(true);
Expand All @@ -774,7 +772,7 @@ void Interactive::computeBackground() {
ui->interactiveTab->setCurrentIndex(0);
ui->previewButton->setDisabled(false);
ui->trackButton->setDisabled(false);
display(background);
display(background, QImage::Format_Grayscale8);
}
else {
isBackground = false;
Expand Down Expand Up @@ -835,7 +833,7 @@ void Interactive::selectBackground() {
ui->backColor->setCurrentIndex(1);
}

display(background);
display(background, QImage::Format_Grayscale8);
}
else {
isBackground = false;
Expand Down
2 changes: 1 addition & 1 deletion src/interactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Interactive : public QMainWindow {

void display(int index, int scale = 0);
void display(const QImage &image);
void display(const UMat &image);
void display(const UMat &image, QImage::Format format = QImage::Format_RGB888);

void zoomIn();
void zoomOut();
Expand Down

0 comments on commit 36b4034

Please sign in to comment.