我无法在QLabel上显示图像

时间:2018-08-04 12:57:00

标签: qt opencv qt5

我有一个带有列表小部件和一个按钮以及两个QLabel的UI。一个小的QLabel显示图像的预览,一个更大的QLabel显示相同的图像,但是更大。 当我单击按钮时,我将图像列表上传到列表小部件上,而当我单击时,我想以小预览和大标签形式显示图像,但没有成功。我不知道错误在哪里,代码如下:

void windowingDialog::on_loadCaliCamA_clicked()
{
    loadImagesCamA();
}

void windowingDialog::update_image_A()
{
    QPixmap imgIn = cvMatToQPixmap(image_A);

    ui->labelShowCamA->setPixmap(imgIn);
    ui->labelShowPreviewCamA->setPixmap(imgIn);
    ui->labelShowPreviewCamA->show();
    ui->labelShowCamA->show();
}

void windowingDialog::loadImagesCamA()
{
    QString main_camA_Dir = QFileDialog::getExistingDirectory(this, tr("Choose an image directory to load"),
                                                     fileCamA, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);

    QDir myDirCamA(main_camA_Dir);
    QStringList fileListA = myDirCamA.entryList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst);
    for (int i = 0; i < fileListA.size(); i++)
    {
        ui->listWidgetCamA->addItem(fileListA.at(i));
    }
    QString selected_item = "";
    QListWidgetItem* item = ui->listWidgetCamA->currentItem();
    if(NULL == item) return;
    selected_item = ui->listWidgetCamA->currentItem()->text();
    QString path = main_camA + selected_item;
    original_image_camA = cv::imread(path.toStdString());
    image_A = original_image_camA;
    update_image_A();
}

void windowingDialog::on_listWidgetCamA_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    QString dir = camCalibDirA + QString("/") + current->text();
    QImage image;
    if(QString::compare(dir, QString()) != 0) {
        image = QImage(dir);
        currentLeftImageCamCalibA = dir;
        ui->labelShowPreviewCamA->setScaledContents(true);
        ui->labelShowPreviewCamA->setPixmap(QPixmap::fromImage(image.scaled(125, 125, Qt::KeepAspectRatio,Qt::SmoothTransformation)));
        QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
        leftPix.append(item);
        ui->labelShowPreviewCamA->show();
        ui->labelShowCamA->show();
    }
}

对于openCV的转换格式,我使用了以下source和这个resource。我想我很亲密,但抓不到错误

0 个答案:

没有答案