mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
switched video capture to QCamera and removed opencv dependency
This commit is contained in:
parent
4b34c73cf8
commit
0de9c877b8
@ -53,7 +53,6 @@ linux-* {
|
|||||||
|
|
||||||
PKGCONFIG += libavcodec libavutil
|
PKGCONFIG += libavcodec libavutil
|
||||||
PKGCONFIG += speex speexdsp
|
PKGCONFIG += speex speexdsp
|
||||||
PKGCONFIG += opencv4
|
|
||||||
} else {
|
} else {
|
||||||
LIBS += -lspeex -lspeexdsp -lavcodec -lavutil
|
LIBS += -lspeex -lspeexdsp -lavcodec -lavutil
|
||||||
}
|
}
|
||||||
@ -66,37 +65,10 @@ win32 {
|
|||||||
INCLUDEPATH += . $$INC_DIR
|
INCLUDEPATH += . $$INC_DIR
|
||||||
|
|
||||||
USE_PRECOMPILED_LIBS =
|
USE_PRECOMPILED_LIBS =
|
||||||
for(lib, RS_LIB_DIR) {
|
|
||||||
#message(Scanning $$lib)
|
|
||||||
isEmpty(USE_PRECOMPILED_LIBS) {
|
|
||||||
exists($$lib/opencv/libopencv_core.a) {
|
|
||||||
message(Get pre-compiled opencv libraries here:)
|
|
||||||
message($$lib/opencv)
|
|
||||||
LIBS += -L"$$lib/opencv"
|
|
||||||
USE_PRECOMPILED_LIBS = 1
|
|
||||||
}
|
|
||||||
exists($$lib/libopencv_core.dll.a) {
|
|
||||||
message(Get pre-compiled opencv libraries here:)
|
|
||||||
message($$lib)
|
|
||||||
LIBS += -L"$$lib"
|
|
||||||
USE_PRECOMPILED_LIBS = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isEmpty(USE_PRECOMPILED_LIBS) {
|
|
||||||
message(Use system opencv libraries.)
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBS += -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_videoio -lopencv_imgcodecs -llibwebp -llibtiff -llibpng -llibopenjp2 -lIlmImf
|
# Should we keep these after removing opencv??
|
||||||
LIBS += -lole32 -loleaut32 -luuid -lvfw32
|
LIBS += -lole32 -loleaut32 -luuid -lvfw32
|
||||||
|
LIBS += -llibjpeg-turbo -lzlib
|
||||||
# Check for msys2
|
|
||||||
!isEmpty(PREFIX_MSYS2) {
|
|
||||||
message(Use msys2 opencv4.)
|
|
||||||
INCLUDEPATH += "$${PREFIX_MSYS2}/include/opencv4"
|
|
||||||
} else {
|
|
||||||
LIBS += -llibjpeg-turbo -lzlib
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#################################### MacOSX #####################################
|
#################################### MacOSX #####################################
|
||||||
@ -105,30 +77,6 @@ macx {
|
|||||||
|
|
||||||
DEPENDPATH += . $$INC_DIR
|
DEPENDPATH += . $$INC_DIR
|
||||||
INCLUDEPATH += . $$INC_DIR
|
INCLUDEPATH += . $$INC_DIR
|
||||||
|
|
||||||
#OPENCV_VERSION = "249"
|
|
||||||
USE_PRECOMPILED_LIBS =
|
|
||||||
for(lib, LIB_DIR) {
|
|
||||||
#message(Scanning $$lib)
|
|
||||||
exists( $$lib/opencv/libopencv_core*.dylib) {
|
|
||||||
isEmpty(USE_PRECOMPILED_LIBS) {
|
|
||||||
message(Get pre-compiled opencv libraries here:)
|
|
||||||
message($$lib)
|
|
||||||
LIBS += -L"$$lib/opencv"
|
|
||||||
LIBS += -lopencv_core -lopencv_highgui -lopencv_imgproc
|
|
||||||
USE_PRECOMPILED_LIBS = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exists( $$lib/libopencv_videoio*.dylib) {
|
|
||||||
message(videoio found in opencv libraries.)
|
|
||||||
message($$lib)
|
|
||||||
LIBS += -lopencv_videoio
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isEmpty(USE_PRECOMPILED_LIBS) {
|
|
||||||
message(Use system opencv libraries.)
|
|
||||||
LIBS += -lopencv_core -lopencv_highgui -lopencv_imgproc
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include "gui/SoundManager.h"
|
#include "gui/SoundManager.h"
|
||||||
#include "gui/chat/ChatWidget.h"
|
#include "gui/chat/ChatWidget.h"
|
||||||
|
|
||||||
#include <opencv2/opencv.hpp>
|
|
||||||
#include <speex/speex.h>
|
#include <speex/speex.h>
|
||||||
|
|
||||||
#define IMAGE_VOIP ":/images/talking_on.svg"
|
#define IMAGE_VOIP ":/images/talking_on.svg"
|
||||||
@ -188,8 +187,6 @@ std::string VOIPPlugin::getPluginName() const
|
|||||||
|
|
||||||
void VOIPPlugin::getLibraries(std::list<RsLibraryInfo> &libraries)
|
void VOIPPlugin::getLibraries(std::list<RsLibraryInfo> &libraries)
|
||||||
{
|
{
|
||||||
libraries.push_back(RsLibraryInfo("OpenCV", CV_VERSION));
|
|
||||||
|
|
||||||
const char *speexVersion = NULL;
|
const char *speexVersion = NULL;
|
||||||
if (speex_lib_ctl(SPEEX_LIB_GET_VERSION_STRING, &speexVersion) == 0 && speexVersion) {
|
if (speex_lib_ctl(SPEEX_LIB_GET_VERSION_STRING, &speexVersion) == 0 && speexVersion) {
|
||||||
libraries.push_back(RsLibraryInfo("Speex", speexVersion));
|
libraries.push_back(RsLibraryInfo("Speex", speexVersion));
|
||||||
|
@ -18,12 +18,13 @@
|
|||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <opencv2/opencv.hpp>
|
|
||||||
#include <opencv2/highgui.hpp>
|
|
||||||
#include <opencv2/imgproc/types_c.h>
|
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <QBuffer>
|
||||||
|
#include <QCamera>
|
||||||
|
#include <QCameraInfo>
|
||||||
|
#include <QCameraImageCapture>
|
||||||
#include "QVideoDevice.h"
|
#include "QVideoDevice.h"
|
||||||
#include "VideoProcessor.h"
|
#include "VideoProcessor.h"
|
||||||
|
|
||||||
@ -36,6 +37,16 @@ QVideoInputDevice::QVideoInputDevice(QWidget *parent)
|
|||||||
_echo_output_device = NULL ;
|
_echo_output_device = NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVideoInputDevice::~QVideoInputDevice()
|
||||||
|
{
|
||||||
|
stop() ;
|
||||||
|
_video_processor = NULL ;
|
||||||
|
|
||||||
|
delete _image_capture;
|
||||||
|
delete _capture_device;
|
||||||
|
delete _timer;
|
||||||
|
}
|
||||||
|
|
||||||
bool QVideoInputDevice::stopped()
|
bool QVideoInputDevice::stopped()
|
||||||
{
|
{
|
||||||
return _timer == NULL ;
|
return _timer == NULL ;
|
||||||
@ -45,7 +56,7 @@ void QVideoInputDevice::stop()
|
|||||||
{
|
{
|
||||||
if(_timer != NULL)
|
if(_timer != NULL)
|
||||||
{
|
{
|
||||||
QObject::disconnect(_timer,SIGNAL(timeout()),this,SLOT(grabFrame())) ;
|
_capture_device->stop();
|
||||||
_timer->stop() ;
|
_timer->stop() ;
|
||||||
delete _timer ;
|
delete _timer ;
|
||||||
_timer = NULL ;
|
_timer = NULL ;
|
||||||
@ -53,10 +64,12 @@ void QVideoInputDevice::stop()
|
|||||||
if(_capture_device != NULL)
|
if(_capture_device != NULL)
|
||||||
{
|
{
|
||||||
// the camera will be deinitialized automatically in VideoCapture destructor
|
// the camera will be deinitialized automatically in VideoCapture destructor
|
||||||
_capture_device->release();
|
delete _image_capture ;
|
||||||
delete _capture_device ;
|
delete _capture_device ;
|
||||||
|
|
||||||
_capture_device = NULL ;
|
_capture_device = NULL ;
|
||||||
}
|
_image_capture = NULL ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void QVideoInputDevice::start()
|
void QVideoInputDevice::start()
|
||||||
{
|
{
|
||||||
@ -65,45 +78,78 @@ void QVideoInputDevice::start()
|
|||||||
stop() ;
|
stop() ;
|
||||||
|
|
||||||
// Initialise la capture
|
// Initialise la capture
|
||||||
static const int cam_id = 0 ;
|
QCameraInfo caminfo = QCameraInfo::defaultCamera();
|
||||||
_capture_device = new cv::VideoCapture(cam_id);
|
|
||||||
|
|
||||||
if(!_capture_device->isOpened())
|
if(caminfo.isNull())
|
||||||
{
|
{
|
||||||
std::cerr << "Cannot initialise camera. Something's wrong." << std::endl;
|
std::cerr << "No video camera available in this system!" << std::endl;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
_capture_device = new QCamera(caminfo);
|
||||||
|
|
||||||
_timer = new QTimer ;
|
if(_capture_device->error() != QCamera::NoError)
|
||||||
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(grabFrame())) ;
|
{
|
||||||
|
emit cameraCaptureInfo(CANNOT_INITIALIZE_CAMERA,_capture_device->error());
|
||||||
|
std::cerr << "Cannot initialise camera. Something's wrong." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_capture_device->setCaptureMode(QCamera::CaptureStillImage);
|
||||||
|
|
||||||
_timer->start(50) ; // 10 images per second.
|
if(_capture_device->error() == QCamera::NoError)
|
||||||
|
emit cameraCaptureInfo(CAMERA_IS_READY,QCamera::NoError);
|
||||||
|
|
||||||
|
_image_capture = new QCameraImageCapture(_capture_device);
|
||||||
|
|
||||||
|
if(!_image_capture->isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer))
|
||||||
|
{
|
||||||
|
emit cameraCaptureInfo(CAMERA_IS_READY,QCamera::NoError);
|
||||||
|
|
||||||
|
delete _capture_device;
|
||||||
|
delete _image_capture;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_image_capture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
|
||||||
|
|
||||||
|
QObject::connect(_image_capture,SIGNAL(imageAvailable(int,QVideoFrame)),this,SLOT(grabFrame(int,QVideoFrame)));
|
||||||
|
QObject::connect(this,SIGNAL(cameraCaptureInfo(CameraStatus,QCamera::Error)),this,SLOT(errorHandling(CameraStatus,QCamera::Error)));
|
||||||
|
|
||||||
|
_timer = new QTimer ;
|
||||||
|
QObject::connect(_timer,SIGNAL(timeout()),_image_capture,SLOT(capture())) ;
|
||||||
|
|
||||||
|
_timer->start(50) ; // 10 images per second.
|
||||||
|
|
||||||
|
_capture_device->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QVideoInputDevice::grabFrame()
|
void QVideoInputDevice::errorHandling(CameraStatus status,QCamera::Error error)
|
||||||
{
|
{
|
||||||
if(!_timer)
|
std::cerr << "Received msg from camera capture: status=" << (int)status << " error=" << (int)error << std::endl;
|
||||||
return ;
|
|
||||||
|
|
||||||
cv::Mat frame;
|
if(status == CANNOT_INITIALIZE_CAMERA)
|
||||||
if(!_capture_device->read(frame))
|
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) Cannot capture image from camera. Something's wrong." << std::endl;
|
std::cerr << "Cannot initialize camera. Make sure to install package libqt5multimedia5-plugins, as this is a common cause for camera not being found." << std::endl;
|
||||||
return ;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QVideoInputDevice::grabFrame(int id,QVideoFrame frame)
|
||||||
|
{
|
||||||
|
if(frame.size().isEmpty())
|
||||||
|
{
|
||||||
|
std::cerr << "Empty frame!" ;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the image data
|
frame.map(QAbstractVideoBuffer::ReadOnly);
|
||||||
|
QByteArray data((const char *)frame.bits(), frame.mappedBytes());
|
||||||
|
QBuffer buffer;
|
||||||
|
buffer.setData(data);
|
||||||
|
buffer.open(QIODevice::ReadOnly);
|
||||||
|
QImageReader reader(&buffer, "JPG");
|
||||||
|
reader.setScaledSize(QSize(640,480));
|
||||||
|
QImage image(reader.read());
|
||||||
|
|
||||||
if(frame.channels() != 3)
|
std::cerr << "Frame " << id << ". Pixel format: " << frame.pixelFormat() << ". Size: " << image.size().width() << " x " << image.size().height() << std::endl; // if(frame.pixelFormat() != QVideoFrame::Format_Jpeg)
|
||||||
{
|
|
||||||
std::cerr << "(EE) expected 3 channels. Got " << frame.channels() << std::endl;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert to RGB and copy to new buffer, because cvQueryFrame tells us to not modify the buffer
|
|
||||||
cv::Mat img_rgb;
|
|
||||||
cv::cvtColor(frame, img_rgb, CV_BGR2RGB);
|
|
||||||
QImage image = QImage(img_rgb.data,img_rgb.cols,img_rgb.rows,QImage::Format_RGB888);
|
|
||||||
|
|
||||||
if(_video_processor != NULL)
|
if(_video_processor != NULL)
|
||||||
{
|
{
|
||||||
@ -131,13 +177,6 @@ uint32_t QVideoInputDevice::currentBandwidth() const
|
|||||||
return _video_processor->currentBandwidthOut() ;
|
return _video_processor->currentBandwidthOut() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVideoInputDevice::~QVideoInputDevice()
|
|
||||||
{
|
|
||||||
stop() ;
|
|
||||||
_video_processor = NULL ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVideoOutputDevice::QVideoOutputDevice(QWidget *parent)
|
QVideoOutputDevice::QVideoOutputDevice(QWidget *parent)
|
||||||
: QLabel(parent)
|
: QLabel(parent)
|
||||||
{
|
{
|
||||||
|
@ -21,13 +21,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QCamera>
|
||||||
#include "interface/rsVOIP.h"
|
#include "interface/rsVOIP.h"
|
||||||
|
|
||||||
#include "opencv2/opencv.hpp"
|
|
||||||
|
|
||||||
#include "gui/VideoProcessor.h"
|
#include "gui/VideoProcessor.h"
|
||||||
|
|
||||||
class VideoEncoder ;
|
class VideoEncoder ;
|
||||||
|
class QCameraImageCapture;
|
||||||
|
|
||||||
// Responsible from displaying the video. The source of the video is
|
// Responsible from displaying the video. The source of the video is
|
||||||
// a VideoDecoder object, which uses a codec.
|
// a VideoDecoder object, which uses a codec.
|
||||||
@ -74,16 +74,26 @@ class QVideoInputDevice: public QObject
|
|||||||
void start() ;
|
void start() ;
|
||||||
void stop() ;
|
void stop() ;
|
||||||
bool stopped();
|
bool stopped();
|
||||||
|
|
||||||
|
enum CameraStatus {
|
||||||
|
CAMERA_IS_READY = 0x00,
|
||||||
|
CANNOT_INITIALIZE_CAMERA = 0x01,
|
||||||
|
CAMERA_CANNOT_GRAB_FRAMES = 0x02
|
||||||
|
};
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void grabFrame() ;
|
void grabFrame(int id, QVideoFrame f) ;
|
||||||
|
void errorHandling(CameraStatus status,QCamera::Error error);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void networkPacketReady() ;
|
void networkPacketReady() ;
|
||||||
|
void cameraCaptureInfo(CameraStatus status,QCamera::Error qt_cam_err_code);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoProcessor *_video_processor ;
|
VideoProcessor *_video_processor ;
|
||||||
QTimer *_timer ;
|
QTimer *_timer ;
|
||||||
cv::VideoCapture *_capture_device ;
|
QCamera *_capture_device;
|
||||||
|
QCameraImageCapture *_image_capture;
|
||||||
|
|
||||||
QVideoOutputDevice *_echo_output_device ;
|
QVideoOutputDevice *_echo_output_device ;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user