1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-15 12:51:49 -05:00

ATV Modulator: added camera FPS auto calibration

This commit is contained in:
f4exb 2017-03-12 03:51:22 +01:00
parent 3bda397e7a
commit e24c7bcf2c
4 changed files with 77 additions and 9 deletions

View File

@ -15,6 +15,7 @@
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include <QDebug> #include <QDebug>
#include <time.h>
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
@ -282,6 +283,44 @@ void ATVMod::pullVideo(Real& sample)
else if ((m_running.m_atvModInput == ATVModInputCamera) && (m_running.m_cameraPlay)) else if ((m_running.m_atvModInput == ATVModInputCamera) && (m_running.m_cameraPlay))
{ {
ATVCamera& camera = m_cameras[m_cameraIndex]; // currently selected canera ATVCamera& camera = m_cameras[m_cameraIndex]; // currently selected canera
if (camera.m_videoFPS < 0.0f) // default frame rate when it could not be obtained via get
{
time_t start, end;
cv::Mat frame;
MsgReportCameraData *report;
report = MsgReportCameraData::create(
camera.m_cameraNumber,
0.0f,
camera.m_videoWidth,
camera.m_videoHeight,
1); // open splash screen on GUI side
getOutputMessageQueue()->push(report);
time(&start);
for (int i = 0; i < 120; i++) {
camera.m_camera >> frame;
}
time(&end);
double seconds = difftime (end, start);
camera.m_videoFPS = (120 / seconds) * 0.95; // take a 5% guard
camera.m_videoFPSq = camera.m_videoFPS / m_fps;
camera.m_videoFPSCount = camera.m_videoFPSq;
camera.m_videoPrevFPSCount = 0;
report = MsgReportCameraData::create(
camera.m_cameraNumber,
camera.m_videoFPS,
camera.m_videoWidth,
camera.m_videoHeight,
2); // close splash screen on GUI side
getOutputMessageQueue()->push(report);
}
int grabOK; int grabOK;
int fpsIncrement = (int) camera.m_videoFPSCount - camera.m_videoPrevFPSCount; int fpsIncrement = (int) camera.m_videoFPSCount - camera.m_videoPrevFPSCount;
@ -445,7 +484,8 @@ bool ATVMod::handleMessage(const Message& cmd)
m_cameras[m_cameraIndex].m_cameraNumber, m_cameras[m_cameraIndex].m_cameraNumber,
m_cameras[m_cameraIndex].m_videoFPS, m_cameras[m_cameraIndex].m_videoFPS,
m_cameras[m_cameraIndex].m_videoWidth, m_cameras[m_cameraIndex].m_videoWidth,
m_cameras[m_cameraIndex].m_videoHeight); m_cameras[m_cameraIndex].m_videoHeight,
0);
getOutputMessageQueue()->push(report); getOutputMessageQueue()->push(report);
} }
} }
@ -714,7 +754,7 @@ void ATVMod::scanCameras()
m_cameras.back().m_videoWidth = (int) m_cameras.back().m_camera.get(CV_CAP_PROP_FRAME_WIDTH); m_cameras.back().m_videoWidth = (int) m_cameras.back().m_camera.get(CV_CAP_PROP_FRAME_WIDTH);
m_cameras.back().m_videoHeight = (int) m_cameras.back().m_camera.get(CV_CAP_PROP_FRAME_HEIGHT); m_cameras.back().m_videoHeight = (int) m_cameras.back().m_camera.get(CV_CAP_PROP_FRAME_HEIGHT);
m_cameras.back().m_videoFPS = m_cameras.back().m_videoFPS < 0 ? 25.0f : m_cameras.back().m_videoFPS; //m_cameras.back().m_videoFPS = m_cameras.back().m_videoFPS < 0 ? 16.3f : m_cameras.back().m_videoFPS;
qDebug("ATVMod::scanCameras: [%d] FPS: %f %dx%d", qDebug("ATVMod::scanCameras: [%d] FPS: %f %dx%d",
i, i,
@ -757,7 +797,8 @@ void ATVMod::getCameraNumbers(std::vector<int>& numbers)
m_cameras[0].m_cameraNumber, m_cameras[0].m_cameraNumber,
m_cameras[0].m_videoFPS, m_cameras[0].m_videoFPS,
m_cameras[0].m_videoWidth, m_cameras[0].m_videoWidth,
m_cameras[0].m_videoHeight); m_cameras[0].m_videoHeight,
0);
getOutputMessageQueue()->push(report); getOutputMessageQueue()->push(report);
} }
} }

View File

@ -217,18 +217,21 @@ public:
float getFPS() const { return m_fps; } float getFPS() const { return m_fps; }
int getWidth() const { return m_width; } int getWidth() const { return m_width; }
int getHeight() const { return m_height; } int getHeight() const { return m_height; }
int getStatus() const { return m_status; }
static MsgReportCameraData* create( static MsgReportCameraData* create(
int deviceNumber, int deviceNumber,
int fps, float fps,
int width, int width,
int height) int height,
int status)
{ {
return new MsgReportCameraData( return new MsgReportCameraData(
deviceNumber, deviceNumber,
fps, fps,
width, width,
height); height,
status);
} }
protected: protected:
@ -236,17 +239,20 @@ public:
float m_fps; float m_fps;
int m_width; int m_width;
int m_height; int m_height;
int m_status;
MsgReportCameraData( MsgReportCameraData(
int deviceNumber, int deviceNumber,
float fps, float fps,
int width, int width,
int height) : int height,
int status) :
Message(), Message(),
m_deviceNumber(deviceNumber), m_deviceNumber(deviceNumber),
m_fps(fps), m_fps(fps),
m_width(width), m_width(width),
m_height(height) m_height(height),
m_status(status)
{ } { }
}; };

View File

@ -19,6 +19,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QTime> #include <QTime>
#include <QDebug> #include <QDebug>
#include <QMessageBox>
#include "device/devicesinkapi.h" #include "device/devicesinkapi.h"
#include "dsp/upchannelizer.h" #include "dsp/upchannelizer.h"
@ -168,6 +169,23 @@ bool ATVModGUI::handleMessage(const Message& message)
ui->cameraDeviceNumber->setText(tr("#%1").arg(rpt.getdeviceNumber())); ui->cameraDeviceNumber->setText(tr("#%1").arg(rpt.getdeviceNumber()));
ui->camerFPS->setText(tr("%1 FPS").arg(rpt.getFPS(), 0, 'f', 2)); ui->camerFPS->setText(tr("%1 FPS").arg(rpt.getFPS(), 0, 'f', 2));
ui->cameraImageSize->setText(tr("%1x%2").arg(rpt.getWidth()).arg(rpt.getHeight())); ui->cameraImageSize->setText(tr("%1x%2").arg(rpt.getWidth()).arg(rpt.getHeight()));
int status = rpt.getStatus();
if (status == 1) // camera FPS scan is startng
{
m_camBusyFPSMessageBox = new QMessageBox();
m_camBusyFPSMessageBox->setText("Computing camera FPS. Please wait…");
m_camBusyFPSMessageBox->setStandardButtons(0);
m_camBusyFPSMessageBox->show();
}
else if (status == 2) // camera FPS scan is finished
{
m_camBusyFPSMessageBox->close();
if (m_camBusyFPSMessageBox) delete m_camBusyFPSMessageBox;
m_camBusyFPSMessageBox = 0;
}
return true; return true;
} }
else else
@ -346,7 +364,8 @@ ATVModGUI::ATVModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* pa
m_videoFrameRate(48000), m_videoFrameRate(48000),
m_frameCount(0), m_frameCount(0),
m_tickCount(0), m_tickCount(0),
m_enableNavTime(false) m_enableNavTime(false),
m_camBusyFPSMessageBox(0)
{ {
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);

View File

@ -29,6 +29,7 @@ class DeviceSinkAPI;
class ThreadedBasebandSampleSource; class ThreadedBasebandSampleSource;
class UpChannelizer; class UpChannelizer;
class ATVMod; class ATVMod;
class QMessageBox;
namespace Ui { namespace Ui {
class ATVModGUI; class ATVModGUI;
@ -103,6 +104,7 @@ private:
int m_frameCount; int m_frameCount;
std::size_t m_tickCount; std::size_t m_tickCount;
bool m_enableNavTime; bool m_enableNavTime;
QMessageBox *m_camBusyFPSMessageBox;
explicit ATVModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* parent = NULL); explicit ATVModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* parent = NULL);
virtual ~ATVModGUI(); virtual ~ATVModGUI();