Skip to content

Commit

Permalink
improve handling of new projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jveitchmichaelis committed Jun 12, 2019
1 parent 758298c commit 10d12f1
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 38 deletions.
14 changes: 11 additions & 3 deletions src/imagedisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ void ImageDisplay::setImagePath(QString path){
}
}

void ImageDisplay::clearPixmap(void){
pixmap = QPixmap();
imageLabel->setPixmap(pixmap);
}

void ImageDisplay::convert16(cv::Mat &source, double minval, double maxval){

if(minval < 0 || maxval < 0){
Expand All @@ -80,6 +85,9 @@ cv::Mat ImageDisplay::getOriginalImage(void){

void ImageDisplay::loadPixmap(){

if(current_imagepath == "")
return;

original_image = cv::imread(current_imagepath.toStdString(), cv::IMREAD_UNCHANGED|cv::IMREAD_ANYDEPTH);

if(original_image.empty()){
Expand Down Expand Up @@ -174,6 +182,7 @@ void ImageDisplay::resetZoom(){

void ImageDisplay::updateDisplay()
{
if(pixmap.isNull()) return;

fit_to_window = ui->fitToWindowButton->isChecked();

Expand All @@ -184,9 +193,8 @@ void ImageDisplay::updateDisplay()
// or leave it full-size
imageLabel->setScaledContents(fit_to_window);

if(!pixmap.isNull()){
imageLabel->setPixmap(pixmap);
}
imageLabel->setPixmap(pixmap);

}


1 change: 1 addition & 0 deletions src/imagedisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public slots:

void toggleColourMap(bool enable);
cv::Mat getOriginalImage();
void clearPixmap();
private:
cv::Mat display_image;
cv::Mat original_image;
Expand Down
6 changes: 6 additions & 0 deletions src/imagelabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void ImageLabel::zoom(double factor){
QPixmap ImageLabel::scaledPixmap(void)
{

if(base_pixmap.isNull())
return QPixmap();

if(shouldScaleContents){
scaled_pixmap = base_pixmap.scaled( size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}else if(zoom_factor != 1.0){
Expand Down Expand Up @@ -197,6 +200,9 @@ void ImageLabel::drawBoundingBox(BoundingBox bbox){
}

void ImageLabel::drawBoundingBox(BoundingBox bbox, QColor colour){

if(scaled_pixmap.isNull()) return;

QPainter painter;
painter.begin(&scaled_pixmap);
QPen pen(colour, 2);
Expand Down
80 changes: 46 additions & 34 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,15 @@ void MainWindow::setSelectMode(){
currentImage->setSelectMode();
}

void MainWindow::openProject()
void MainWindow::openProject(QString fileName)
{
QString openDir = settings->value("project_folder", QDir::homePath()).toString();
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Project"),
openDir,
tr("Label database (*.lbldb)"));

if(fileName == ""){
QString openDir = settings->value("project_folder", QDir::homePath()).toString();
fileName = QFileDialog::getOpenFileName(this, tr("Open Project"),
openDir,
tr("Label database (*.lbldb)"));
}

if(fileName != ""){
settings->setValue("project_folder", QFileInfo(fileName).absoluteDir().absolutePath());
Expand Down Expand Up @@ -343,20 +346,27 @@ void MainWindow::addImageFolders(void){
void MainWindow::updateImageList(){
project->getImageList(images);
number_images = images.size();
ui->imageProgressBar->setMaximum(number_images);
ui->imageNumberSpinbox->setMaximum(number_images);

if(number_images == 0){
ui->changeImageButton->setDisabled(true);
ui->imageNumberSpinbox->setDisabled(true);
ui->imageProgressBar->setDisabled(true);
ui->propagateCheckBox->setDisabled(true);
ui->imageGroupBox->setDisabled(true);
ui->labelGroupBox->setDisabled(true);
ui->navigationGroupBox->setDisabled(true);
ui->actionExport->setDisabled(true);
ui->imageIndexLabel->setText(QString("-"));
}else{
ui->changeImageButton->setEnabled(true);
ui->imageNumberSpinbox->setEnabled(true);
ui->imageProgressBar->setEnabled(true);
ui->propagateCheckBox->setEnabled(true);
ui->imageGroupBox->setEnabled(true);
ui->labelGroupBox->setEnabled(true);
ui->navigationGroupBox->setEnabled(true);
ui->actionExport->setEnabled(true);
}

ui->imageProgressBar->setValue(0);
ui->imageProgressBar->setMaximum(number_images);

ui->imageNumberSpinbox->setMaximum(number_images);
ui->imageNumberSpinbox->setValue(1);


}

void MainWindow::updateClassList(){
Expand Down Expand Up @@ -440,17 +450,14 @@ void MainWindow::removeClass(){

void MainWindow::initDisplay(){

display->clearPixmap();

updateImageList();
updateClassList();

if(number_images != 0){
current_index = 0;
ui->imageGroupBox->setEnabled(true);
ui->labelGroupBox->setEnabled(true);
ui->navigationGroupBox->setEnabled(true);
updateDisplay();
ui->actionExport->setEnabled(true);
}
current_index = 0;

updateDisplay();
}

void MainWindow::nextUnlabelled(){
Expand Down Expand Up @@ -734,21 +741,25 @@ void MainWindow::previousImage(){
updateDisplay();
}

void MainWindow::updateCurrentIndex(int index){
current_index = index;
updateDisplay();
}

void MainWindow::updateDisplay(){

if(images.size() == 0){
return;
}

current_index = ui->imageNumberSpinbox->value()-1;
current_imagepath = images.at(current_index);
display->setImagePath(current_imagepath);

updateLabels();
}else{
current_index = ui->imageNumberSpinbox->value()-1;
current_imagepath = images.at(current_index);
display->setImagePath(current_imagepath);

ui->imageProgressBar->setValue(current_index+1);
ui->imageIndexLabel->setText(QString("%1/%2").arg(current_index+1).arg(number_images));
updateLabels();

ui->imageProgressBar->setValue(current_index+1);
ui->imageIndexLabel->setText(QString("%1/%2").arg(current_index+1).arg(number_images));
}
}

void MainWindow::updateImageInfo(void){
Expand All @@ -769,11 +780,12 @@ void MainWindow::newProject()
tr("Label database (*.lbldb)"));

if(fileName != ""){
free(project);
project = new LabelProject;
project->createDatabase(fileName);
openProject(fileName);
}

updateDisplay();

return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private slots:

void updateDisplay(void);

void openProject(void);
void openProject(QString filename = "");
void newProject(void);

void addClass(void);
Expand Down Expand Up @@ -129,6 +129,7 @@ private slots:
void setNMSThreshold();


void updateCurrentIndex(int index);
signals:
void selectedClass(QString);

Expand Down

0 comments on commit 10d12f1

Please sign in to comment.