gpt4 book ai didi

Windows + Qt 以及如何在没有 OpenCV 的情况下捕获网络摄像头提要

转载 作者:可可西里 更新时间:2023-11-01 13:22:56 25 4
gpt4 key购买 nike

我一直在与这个问题作斗争。我无法让 OpenCV 工作,而且我已经遵循了很多关于它以及如何在 Qt 中使用的教程,所以我感到厌倦,我想避免为此使用 OpenCV。

现在,我的要求或问题...我需要在 Qt GUI 应用程序中显示网络摄像头源(实时视频,无音频),只有一个按钮:“拍摄快照”,显然,从当前提要并存储它。

就这些。

有没有办法不使用 OpenCV 来完成这项工作?

系统规范:

  • Qt 4.8

  • Windows XP 32 位

  • USB 2.0.1.3M UVC WebCam(我现在用的,应该也支持其他型号)

希望有人能帮我解决这个问题,因为我快疯了。

提前致谢!

最佳答案

好的,我终于做到了,所以我会在这里发布我的解决方案,以便我们对此有一些了解。

我使用了一个名为“ESCAPI”的库:http://sol.gfxile.net/escapi/index.html

这提供了一种从设备捕获帧的极其简单的方法。有了这些原始数据,我就创建了一个 QImage,稍后在 QLabel 中显示。

我创建了一个简单的对象来处理这个问题。

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

Camera::Camera(int width, int height, QObject *parent) :
QObject(parent),
width_(width),
height_(height)
{
capture_.mWidth = width;
capture_.mHeight = height;
capture_.mTargetBuf = new int[width * height];

int devices = setupESCAPI();
if (devices == 0)
{
qDebug() << "[Camera] ESCAPI initialization failure or no devices found";
}
}

Camera::~Camera()
{
deinitCapture(0);
}

int Camera::initialize()
{
if (initCapture(0, &capture_) == 0)
{
qDebug() << "[Camera] Capture failed - device may already be in use";
return -2;
}
return 0;
}

void Camera::deinitialize()
{
deinitCapture(0);
}

int Camera::capture()
{
doCapture(0);
while(isCaptureDone(0) == 0);

image_ = QImage(width_, height_, QImage::Format_ARGB32);
for(int y(0); y < height_; ++y)
{
for(int x(0); x < width_; ++x)
{
int index(y * width_ + x);
image_.setPixel(x, y, capture_.mTargetBuf[index]);
}
}
return 1;
}

和头文件:

#ifndef CAMERA_H
#define CAMERA_H

#include <QObject>
#include <QImage>
#include "escapi.h"

class Camera : public QObject
{
Q_OBJECT

public:
explicit Camera(int width, int height, QObject *parent = 0);
~Camera();
int initialize();
void deinitialize();
int capture();
const QImage& getImage() const { return image_; }
const int* getImageRaw() const { return capture_.mTargetBuf; }

private:
int width_;
int height_;
struct SimpleCapParams capture_;
QImage image_;
};

#endif // CAMERA_H

它非常简单,但仅用于示例目的。使用应该是这样的:

Camera cam(320, 240);
cam.initialize();
cam.capture();
QImage img(cam.getImage());
ui->label->setPixmap(QPixmap::fromImage(img));

当然,您可以使用 QTimer 并更新 QLabel 中的帧,您将在那里获得视频...

希望对您有所帮助!并感谢尼古拉斯的帮助!

关于Windows + Qt 以及如何在没有 OpenCV 的情况下捕获网络摄像头提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15458274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com