mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Switch self cam view to OpenCV
This commit is contained in:
parent
99a4b03cfd
commit
f4b1b64ae6
2
qtox.pro
2
qtox.pro
|
@ -45,7 +45,7 @@ win32 {
|
||||||
} macx {
|
} macx {
|
||||||
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -lsodium -lvpx -framework OpenAL
|
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -lsodium -lvpx -framework OpenAL
|
||||||
} else {
|
} else {
|
||||||
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -lsodium -lvpx -lopenal
|
LIBS += -L$$PWD/libs/lib/ -ltoxcore -ltoxav -lsodium -lvpx -lopenal -lopencv_core -lopencv_highgui -lopencv_imgproc
|
||||||
}
|
}
|
||||||
|
|
||||||
#### Static linux build
|
#### Static linux build
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include <QVideoEncoderSettings>
|
#include <QVideoEncoderSettings>
|
||||||
#include <QVideoEncoderSettingsControl>
|
#include <QVideoEncoderSettingsControl>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
static inline void fromYCbCrToRGB(
|
static inline void fromYCbCrToRGB(
|
||||||
uint8_t Y, uint8_t Cb, uint8_t Cr,
|
uint8_t Y, uint8_t Cb, uint8_t Cr,
|
||||||
uint8_t& R, uint8_t& G, uint8_t& B)
|
uint8_t& R, uint8_t& G, uint8_t& B)
|
||||||
|
@ -75,7 +77,7 @@ void Camera::suscribe()
|
||||||
if (refcount <= 0)
|
if (refcount <= 0)
|
||||||
{
|
{
|
||||||
refcount = 1;
|
refcount = 1;
|
||||||
camera->start();
|
cap.open(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
refcount++;
|
refcount++;
|
||||||
|
@ -87,16 +89,23 @@ void Camera::unsuscribe()
|
||||||
|
|
||||||
if (refcount <= 0)
|
if (refcount <= 0)
|
||||||
{
|
{
|
||||||
camera->stop();
|
cap.release();
|
||||||
refcount = 0;
|
refcount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVideoFrame Camera::getLastFrame()
|
QVideoFrame Camera::getLastVideoFrame()
|
||||||
{
|
{
|
||||||
return lastFrame;
|
return lastFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mat Camera::getLastFrame()
|
||||||
|
{
|
||||||
|
Mat frame;
|
||||||
|
cap >> frame;
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
bool Camera::start(const QVideoSurfaceFormat &format)
|
bool Camera::start(const QVideoSurfaceFormat &format)
|
||||||
{
|
{
|
||||||
if(supportedFormats.contains(format.pixelFormat()))
|
if(supportedFormats.contains(format.pixelFormat()))
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QVideoFrame>
|
#include <QVideoFrame>
|
||||||
#include <QAbstractVideoSurface>
|
#include <QAbstractVideoSurface>
|
||||||
#include "vpx/vpx_image.h"
|
#include "vpx/vpx_image.h"
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a wrapper to share a camera's captured video frames
|
* This class is a wrapper to share a camera's captured video frames
|
||||||
|
@ -39,7 +40,8 @@ public:
|
||||||
Camera();
|
Camera();
|
||||||
void suscribe(); ///< Call this once before trying to get frames
|
void suscribe(); ///< Call this once before trying to get frames
|
||||||
void unsuscribe(); ///< Call this once when you don't need frames anymore
|
void unsuscribe(); ///< Call this once when you don't need frames anymore
|
||||||
QVideoFrame getLastFrame(); ///< Get the last captured frame
|
cv::Mat getLastFrame(); ///< Get the last captured frame
|
||||||
|
QVideoFrame getLastVideoFrame(); ///< Get the last captured frame
|
||||||
QImage getLastImage(); ///< Convert the last frame to a QImage (can be expensive !)
|
QImage getLastImage(); ///< Convert the last frame to a QImage (can be expensive !)
|
||||||
vpx_image getLastVPXImage(); ///< Convert the last frame to a vpx_image (can be expensive !)
|
vpx_image getLastVPXImage(); ///< Convert the last frame to a vpx_image (can be expensive !)
|
||||||
bool isFormatSupported(const QVideoSurfaceFormat & format) const;
|
bool isFormatSupported(const QVideoSurfaceFormat & format) const;
|
||||||
|
@ -58,6 +60,8 @@ private:
|
||||||
QVideoFrame lastFrame;
|
QVideoFrame lastFrame;
|
||||||
int frameFormat;
|
int frameFormat;
|
||||||
QList<QVideoFrame::PixelFormat> supportedFormats;
|
QList<QVideoFrame::PixelFormat> supportedFormats;
|
||||||
|
|
||||||
|
cv::VideoCapture cap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CAMERA_H
|
#endif // CAMERA_H
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "videosurface.h"
|
#include "videosurface.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
SelfCamView::SelfCamView(Camera* Cam, QWidget* parent)
|
SelfCamView::SelfCamView(Camera* Cam, QWidget* parent)
|
||||||
: QWidget(parent), displayLabel{new QLabel},
|
: QWidget(parent), displayLabel{new QLabel},
|
||||||
mainLayout{new QHBoxLayout()}, cam(Cam)
|
mainLayout{new QHBoxLayout()}, cam(Cam)
|
||||||
|
@ -60,8 +62,22 @@ void SelfCamView::showEvent(QShowEvent* event)
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelfCamView::updateDisplay()
|
QImage Mat2QImage(const cv::Mat3b &src) {
|
||||||
{
|
QImage dest(src.cols, src.rows, QImage::Format_ARGB32);
|
||||||
displayLabel->setPixmap(QPixmap::fromImage(cam->getLastImage()));
|
for (int y = 0; y < src.rows; ++y) {
|
||||||
|
const cv::Vec3b *srcrow = src[y];
|
||||||
|
QRgb *destrow = (QRgb*)dest.scanLine(y);
|
||||||
|
for (int x = 0; x < src.cols; ++x) {
|
||||||
|
destrow[x] = qRgba(srcrow[x][2], srcrow[x][1], srcrow[x][0], 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelfCamView::updateDisplay()
|
||||||
|
{
|
||||||
|
Mat frame = cam->getLastFrame();
|
||||||
|
|
||||||
|
displayLabel->setPixmap(QPixmap::fromImage(Mat2QImage(frame)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user