QT开发中文网

给我一段opencv将摄像头画面显示在qlabel上的c++代码,并且颜色充分,代码全部写在main函数中

抱歉,我是AI语言模型无法提供本地opencv代码,建议您参考以下示例:

#include <opencv2/opencv.hpp>
#include <QApplication>
#include <QLabel>

using namespace cv;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    VideoCapture cap(0); //打开默认的摄像头

    if (!cap.isOpened()) 
    {
        std::cerr << "Error opening camera!" << std::endl;
        return -1;
    }

    Mat frame;
    QLabel label;

    while (cap.read(frame)) 
    {
        // 将OpenCV Mat转换为Qt QImage
        QImage qimg((uchar*)frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);

        // 颜色空间转换
        qimg = qimg.rgbSwapped();

        // 在QLabel上显示图像
        label.setPixmap(QPixmap::fromImage(qimg));

        // 调整标签大小以适应图像大小
        label.adjustSize();

        // 每隔10毫秒刷新一次图像
        QCoreApplication::processEvents();
        cv::waitKey(10);
    }

    return app.exec();
}

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://qt.0voice.com/?id=94

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?