首页 > 解决方案 > LNK1107:无效或损坏的文件无法读取 0x458

问题描述

我对 qt 很陌生,我正在尝试创建一个小部件,使用 qt 和 opencv 显示我的网络摄像头。正如标题所说,我被困在 LNK1107:无效或损坏的文件无法读取 0x458。在做了一些研究之后,我发现这个问题已经在多个主题中得到了解决,但特别是 0x458 没有

任何帮助都会非常感激,从我的心底

这是我的代码:.pro:

#-------------------------------------------------
#
# Project created by QtCreator 2019-08-10T12:27:53
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = TutorialOpenCV
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp \
        myvideocapture.cpp

HEADERS += \
        mainwindow.h \
        myvideocapture.h

FORMS += \
        mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../opencv/build/x64/vc15/lib/ -lopencv_world451
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../opencv/build/x64/vc15/lib/ -lopencv_world451d
else:unix: LIBS += -L$$PWD/../../../../../opencv/build/x64/vc15/lib/ -lopencv_world451

INCLUDEPATH += C:\opencv\build\x64\vc15
LIBS += C:\opencv\build\x64\vc15\lib\opencv_world451.lib
LIBS += C:\opencv\build\x64\vc15\lib\opencv_world451d.lib


INCLUDEPATH += $$PWD/../../../../../opencv/build/include
DEPENDPATH += $$PWD/../../../../../opencv/build/include


INCLUDEPATH += C:\opencv\release\install\include


LIBS += C:\opencv\release\bin\libopencv_core451.dll
LIBS += C:\opencv\release\bin\libopencv_highgui451.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc451.dll
LIBS += C:\opencv\release\bin\libopencv_features2d451.dll
LIBS += C:\opencv\release\bin\libopencv_calib3d451.dll

INCLUDEPATH += C:\opencv\release\install\include\opencv2
INCLUDEPATH += C:\opencv\release\install\include\opencv
INCLUDEPATH += C:\opencv\build\include
INCLUDEPATH += C:\opencv\release\include
LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_core451.dll
LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_highgui451.dll
LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_imgproc451.dll
LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_features2d451.dll
LIBS += C:\opencv\release\install\x64\mingw\bin\libopencv_calib3d451.dll

myvideocapture.cpp:

#include "myvideocapture.h"
#include <QDebug>

MyVideoCapture::MyVideoCapture(QObject *parent)
    : QThread { parent }
    , mVideoCap { ID_CAMERA }
{
}
void MyVideoCapture::run()
{
    if (mVideoCap.isOpened())
    {
        while (true)
        {
            mVideoCap >> mFrame;
            if (!mFrame.empty())
            {
                cv::rectangle(mFrame, cv::Point(10, 10), cv::Point(401, 401), cv::Scalar(0, 0, 255), 1);

                mPixmap = cvMatToQPixmap(mFrame);
                emit newPixmapCaptured();
            }
        }
    }
}

QImage MyVideoCapture::cvMatToQImage(const cv::Mat &inMat)
{
    switch (inMat.type())
    {
        // 8-bit, 4 channel
        case CV_8UC4:
        {
            QImage image(inMat.data, inMat.cols, inMat.rows, static_cast<int>(inMat.step), QImage::Format_ARGB32);
            return image;
        }
        // 8-bit, 3 channel
        case CV_8UC3:
        {
            QImage image(inMat.data, inMat.cols, inMat.rows, static_cast<int>(inMat.step), QImage::Format_RGB888);
            return image.rgbSwapped();
        }
        // 8-bit, 1 channel
        case CV_8UC1:
        {
    #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
            QImage image(inMat.data, inMat.cols, inMat.rows, static_cast<int>(inMat.step), QImage::Format_Grayscale8);
    #else
            static QVector<QRgb>  sColorTable;

            // only create our color table the first time
            if (sColorTable.isEmpty())
            {
                sColorTable.resize(256 );

                for (int i = 0; i < 256; ++i )
                {
                    sColorTable[i] = qRgb(i, i, i );
                }
            }

            QImage image(inMat.data,
                         inMat.cols, inMat.rows,
                         static_cast<int>(inMat.step),
                         QImage::Format_Indexed8 );

            image.setColorTable(sColorTable );
    #endif
            return image;
        }
        default:
        {
            qWarning()<< "ASM::cvMatToQImage()- cv::Mat image type not handled in switch:" << inMat.type();
            break;
        }
    }
    return QImage();
}

QPixmap MyVideoCapture::cvMatToQPixmap(const cv::Mat &inMat)
{
    return QPixmap::fromImage(cvMatToQImage(inMat));
}

主窗口.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "myvideocapture.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    mOpenCV_videoCapture = new MyVideoCapture(this);

    connect(mOpenCV_videoCapture, &MyVideoCapture::newPixmapCaptured, this, [&]()
    {
        ui->opencvFrame->setPixmap(mOpenCV_videoCapture->pixmap().scaled(500, 500));
    });
}

MainWindow::~MainWindow()
{
    delete ui;
    mOpenCV_videoCapture->terminate();
}

void MainWindow::on_iniciarOpenCV_button_clicked()
{
    mOpenCV_videoCapture->start(QThread::HighestPriority);
}

主.cpp:

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setStyle("fusion");
    MainWindow w;
    w.show();
    return a.exec();
}

标签: c++qt

解决方案


推荐阅读