Windows + Qt and how to capture webcam feed without OpenCV

I have been struggling with this problem since ancient times. I cannot get OpenCV to work, and I am following many tutorials about this and how to use it in Qt, so I get tired and I want to avoid using OpenCV for this.

Now, my requirement or question ... I need to show the webcam channel (real-time video without sound) in the Qt GUI application with just one button: "Take Snapshot", which, obviusly, take a picture from the current channel and save it .

What all.

Anyway, to do this without using OpenCV?

System Specification:

  • Qt 4.8

  • 32-bit version of Windows XP

  • USB 2.0.1.3M UVC WebCam (the one I'm using now, it must also support other models)

Hope someone can help me because I'm crazy.

Thanks in advance!

+6
source share
1 answer

Well, I finally did it, so I will post my decision here so that we have something clear.

I used a library called "ESCAPI": http://sol.gfxile.net/escapi/index.html

This provides an extremely easy way to capture frames from the device. Using this source data, I simply create a QImage, which is later displayed in QLabel.

I created a simple object to handle this.

#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; } 

And the header file:

 #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 

It is so simple, but just for the purpose. Use should be something like this:

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

Of course, you can use QTimer and update the frame in QLabel, and you will have a video ...

Hope this helps! and thanks to Nicholas for your help!

+8
source

All Articles