mirror of
https://github.com/vale981/Taevitas
synced 2025-03-05 09:31:42 -05:00
recording should work now
This commit is contained in:
parent
c9afacd788
commit
98357d3e3b
8 changed files with 366 additions and 264 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.2.1, 2017-03-23T15:54:31. -->
|
||||
<!-- Written by QtCreator 4.2.1, 2017-03-23T16:37:15. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
|
@ -56,7 +56,10 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<widget class="QPushButton" name="startButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
|
@ -98,7 +101,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<widget class="QCheckBox" name="saveFrames">
|
||||
<property name="text">
|
||||
<string> Save Frames</string>
|
||||
</property>
|
||||
|
@ -182,9 +185,9 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<widget class="QPushButton" name="directorySelector">
|
||||
<property name="text">
|
||||
<string>Output Folder</string>
|
||||
<string>Working Directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -8,6 +8,7 @@ void ImageGrabber::run() {
|
|||
FlyCapture2::Image* tmp = new FlyCapture2::Image();
|
||||
FlyCapture2::Image* stored_img = new FlyCapture2::Image();
|
||||
|
||||
// TODO: Errors
|
||||
cam->RetrieveBuffer(tmp);
|
||||
qDebug() << "Image Grabbed!";
|
||||
|
||||
|
|
|
@ -6,134 +6,155 @@
|
|||
#include <QDebug>
|
||||
#include <QTime>
|
||||
#include <QErrorMessage>
|
||||
#include <QFileDialog>
|
||||
|
||||
// TODO: Handle Errors!!
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
cam_man(this),
|
||||
recorder(this)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
MainWindow::MainWindow( QWidget * parent ) :
|
||||
QMainWindow( parent ),
|
||||
ui( new Ui::MainWindow ),
|
||||
camMan( this ),
|
||||
recorder( this, 18, false ) {
|
||||
ui->setupUi( this );
|
||||
|
||||
// Set Scene and Hide Preview Widget
|
||||
ui->preview_widget->hide();
|
||||
adjustSize();
|
||||
|
||||
|
||||
disableRecOptions();
|
||||
|
||||
|
||||
// Try to connect to first cam
|
||||
scanAndUpdateCameras();
|
||||
|
||||
|
||||
// Set default name
|
||||
ui->projectName->setText("Taevitas_Rec_" + QDateTime::currentDateTime().toString("dd_MM_yyyy_hh_mm_ss"));
|
||||
ui->projectName->setText( "Taevitas_Rec_" + QDateTime::currentDateTime().toString( "dd_MM_yyyy_hh_mm_ss" ) );
|
||||
|
||||
// Connect Events
|
||||
connect(ui->preview_button, &QPushButton::clicked, this, &MainWindow::toggle_preview);
|
||||
connect( ui->preview_button, &QPushButton::clicked, this, &MainWindow::togglePreview );
|
||||
|
||||
// Cam ComboBox clicked
|
||||
connect(ui->camScanButton, &QPushButton::clicked, this, &MainWindow::scanAndUpdateCameras);
|
||||
|
||||
connect( ui->camScanButton, &QPushButton::clicked, this, &MainWindow::scanAndUpdateCameras );
|
||||
|
||||
// Camera selected
|
||||
connect(ui->cameraSelector, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainWindow::camera_selected);
|
||||
|
||||
connect( ui->cameraSelector, static_cast<void( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &MainWindow::cameraSelected );
|
||||
|
||||
// File Selector
|
||||
connect( ui->directorySelector, &QPushButton::clicked, this, &MainWindow::directorySelection );
|
||||
|
||||
// Frame Captured
|
||||
connect(&cam_man, &CameraManager::frameCaptured, this, &MainWindow::frameCaptured, Qt::DirectConnection);
|
||||
connect( &camMan, &CameraManager::frameCaptured, this, &MainWindow::frameCaptured, Qt::DirectConnection );
|
||||
|
||||
// Change Project Name
|
||||
connect( ui->projectName, &QLineEdit::editingFinished, this, &MainWindow::enableStart );
|
||||
|
||||
// Change Record Frames
|
||||
connect( ui->saveFrames, &QCheckBox::toggled, &recorder, &Recorder::setCaptureFrames );
|
||||
|
||||
// Start recording
|
||||
connect( ui->startButton, &QPushButton::clicked, this, &MainWindow::startStopRecording );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::updateCameraList(unsigned int num_cameras) {
|
||||
void MainWindow::updateCameraList( unsigned int num_cameras ) {
|
||||
ui->cameraSelector->clear();
|
||||
|
||||
// Fill Combo Box with cameras
|
||||
for (unsigned int i = 0; i < num_cameras; i++) {
|
||||
ui->cameraSelector->addItem(QString(i+'0'));
|
||||
for ( unsigned int i = 0; i < num_cameras; i++ ) {
|
||||
ui->cameraSelector->addItem( QString( i+'0' ) );
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::scanAndUpdateCameras() {
|
||||
unsigned int num_cameras = cam_man.numCameras();
|
||||
updateCameraList(num_cameras);
|
||||
if(num_cameras > 0 && !cam_man.isConnected())
|
||||
camera_selected(0);
|
||||
unsigned int num_cameras = camMan.numCameras();
|
||||
updateCameraList( num_cameras );
|
||||
if( num_cameras > 0 && !camMan.isConnected() )
|
||||
cameraSelected( 0 );
|
||||
};
|
||||
|
||||
void MainWindow::disableRecOptions() {
|
||||
ui->recOptions->setProperty("enabled", false);
|
||||
ui->recOptions->setProperty( "enabled", false );
|
||||
ui->startButton->setProperty( "enabled", false );
|
||||
}
|
||||
|
||||
void MainWindow::enableRecOptions() {
|
||||
ui->recOptions->setProperty("enabled", true);
|
||||
ui->recOptions->setProperty( "enabled", true );
|
||||
enableStart();
|
||||
}
|
||||
|
||||
void MainWindow::showError(QString error) {
|
||||
void MainWindow::enableStart() {
|
||||
if( ui->projectName->text() != "" && recorder.dirSet() && camMan.isConnected() ) {
|
||||
ui->startButton->setProperty( "enabled", true );
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showError( QString error ) {
|
||||
QMessageBox errBox;
|
||||
errBox.critical(0,"Error", "An Error has occured:\n" + error);
|
||||
errBox.setFixedSize(500,200);
|
||||
errBox.critical( 0,"Error", "An Error has occured:\n" + error );
|
||||
errBox.setFixedSize( 500,200 );
|
||||
errBox.show();
|
||||
}
|
||||
|
||||
void MainWindow::showError(FlyCapture2::Error error) {
|
||||
showError(error.GetDescription());
|
||||
void MainWindow::showError( FlyCapture2::Error error ) {
|
||||
showError( error.GetDescription() );
|
||||
}
|
||||
|
||||
void MainWindow::camera_selected(int index) {
|
||||
if(recorder.isRecording() || index < 0)
|
||||
void MainWindow::cameraSelected( int index ) {
|
||||
if( recorder.isRecording() || index < 0 )
|
||||
return;
|
||||
|
||||
|
||||
try {
|
||||
cam_man.connectCamera(index);
|
||||
} catch (FlyCapture2::Error e) {
|
||||
showError(e);
|
||||
camMan.connectCamera( index );
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
enableRecOptions();
|
||||
};
|
||||
|
||||
// Show/Hide Preview
|
||||
void MainWindow::toggle_preview(bool checked) {
|
||||
void MainWindow::togglePreview( bool checked ) {
|
||||
// skip if there is no camera
|
||||
if(!cam_man.isConnected()) {
|
||||
ui->preview_button->setProperty("checked", false);
|
||||
if( !camMan.isConnected() ) {
|
||||
ui->preview_button->setProperty( "checked", false );
|
||||
return;
|
||||
}
|
||||
|
||||
if(checked) {
|
||||
ui->preview_widget->setProperty("enabled", true);
|
||||
|
||||
if( checked ) {
|
||||
ui->preview_widget->setProperty( "enabled", true );
|
||||
|
||||
// Start Capturing for preview
|
||||
try {
|
||||
cam_man.startCapture();
|
||||
} catch (FlyCapture2::Error e) {
|
||||
showError(e);
|
||||
camMan.startCapture();
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
}
|
||||
} else {
|
||||
ui->preview_widget->setProperty("enabled", false);
|
||||
ui->preview_widget->setProperty( "enabled", false );
|
||||
ui->preview_widget->hide();
|
||||
|
||||
//Stop capture
|
||||
if(!recorder.isRecording())
|
||||
cam_man.stopCapture();
|
||||
if( !recorder.isRecording() )
|
||||
camMan.stopCapture();
|
||||
}
|
||||
|
||||
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void MainWindow::frameCaptured(FlyCapture2::Image* image) {
|
||||
void MainWindow::frameCaptured( FlyCapture2::Image * image ) {
|
||||
qDebug() << "Image Captured!";
|
||||
|
||||
// If preview is activated...
|
||||
if(ui->preview_widget->isEnabled())
|
||||
displayPreview(image);
|
||||
if( ui->preview_widget->isEnabled() )
|
||||
displayPreview( image );
|
||||
return;
|
||||
}
|
||||
|
||||
void MainWindow::displayPreview(FlyCapture2::Image* last_capture) {
|
||||
// Render Preview
|
||||
void MainWindow::displayPreview( FlyCapture2::Image * last_capture ) {
|
||||
ui->preview_widget->show();
|
||||
|
||||
FlyCapture2::Image last_image;
|
||||
|
@ -141,13 +162,63 @@ void MainWindow::displayPreview(FlyCapture2::Image* last_capture) {
|
|||
QPixmap last_preview;
|
||||
|
||||
// Convert Pixel Format to RGB
|
||||
FlyCapture2::Error e = last_capture->Convert(FlyCapture2::PIXEL_FORMAT_RGB, &last_image);
|
||||
FlyCapture2::Error e = last_capture->Convert( FlyCapture2::PIXEL_FORMAT_RGB, &last_image );
|
||||
|
||||
last_preview_image = QImage(last_image.GetData(), last_image.GetCols(), last_image.GetRows(), QImage::Format_RGB888);
|
||||
last_preview_image = QImage( last_image.GetData(), last_image.GetCols(), last_image.GetRows(), QImage::Format_RGB888 );
|
||||
|
||||
last_preview_image = last_preview_image.scaledToHeight(500);
|
||||
ui->preview_widget->setFixedSize(last_preview_image.width(), last_preview_image.height());
|
||||
last_preview_image = last_preview_image.scaledToHeight( 500 );
|
||||
ui->preview_widget->setFixedSize( last_preview_image.width(), last_preview_image.height() );
|
||||
|
||||
last_preview.convertFromImage(last_preview_image);
|
||||
ui->preview_widget->setPixmap(last_preview);
|
||||
last_preview.convertFromImage( last_preview_image );
|
||||
ui->preview_widget->setPixmap( last_preview );
|
||||
}
|
||||
|
||||
void MainWindow::directorySelection() {
|
||||
QString dir = QFileDialog::getExistingDirectory( this, tr( "Choose the working Directory." ), ( recorder.dirSet() ? recorder.getProjectDir() : QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ) ), QFileDialog::ShowDirsOnly );
|
||||
try {
|
||||
recorder.setProjectDir( dir );
|
||||
enableStart();
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::startStopRecording() {
|
||||
// TODO: Errors
|
||||
if( recorder.isRecording() ) {
|
||||
if( !camMan.isCapturing() ) {
|
||||
try {
|
||||
camMan.startCapture();
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
recorder.newRecording( ui->projectName->text() );
|
||||
} catch ( RecorderError e ) {
|
||||
showError( "Could not start Recording!" );
|
||||
return;
|
||||
}
|
||||
|
||||
ui->startButton->setText( "Stop" );
|
||||
} else {
|
||||
try {
|
||||
recorder.stopRecording();
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
return;
|
||||
}
|
||||
|
||||
// If no preview
|
||||
if( !ui->preview_button->isChecked() ) {
|
||||
try {
|
||||
camMan.stopCapture();
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,25 +22,28 @@ public:
|
|||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
CameraManager cam_man;
|
||||
CameraManager camMan;
|
||||
Recorder recorder;
|
||||
|
||||
void displayPreview(FlyCapture2::Image *last_capture);
|
||||
void disableRecOptions();
|
||||
void enableRecOptions();
|
||||
void enableStart();
|
||||
|
||||
void showError(FlyCapture2::Error err);
|
||||
void showError(QString error);
|
||||
|
||||
void updateCameraList(unsigned int num_cameras);
|
||||
QMutex test;
|
||||
|
||||
private slots:
|
||||
// Fills Camera Combobox with Cameras
|
||||
void scanAndUpdateCameras();
|
||||
|
||||
void toggle_preview(bool);
|
||||
void togglePreview(bool);
|
||||
void frameCaptured(FlyCapture2::Image *image);
|
||||
void camera_selected(int index);
|
||||
void cameraSelected(int index);
|
||||
void directorySelection();
|
||||
void startStopRecording();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
239
src/recorder.cpp
239
src/recorder.cpp
|
@ -1,162 +1,163 @@
|
|||
#include "recorder.h"
|
||||
using namespace FlyCapture2;
|
||||
|
||||
Recorder::Recorder(QObject* parent) : QObject(parent), frame_number {frame_n}, is_recording {false}, time_captured {time_c}, frame_n {0}, time_c {0} {
|
||||
// No Compression for frame_captures
|
||||
frame_options.compression = frame_options.NONE;
|
||||
};
|
||||
Recorder::Recorder( QObject * parent, unsigned int frame_rate, bool cap_frames ) : QObject( parent ), is_recording {false}, frame_number {frame_n}, time_captured {time_c}, frame_n {0}, time_c {0}, project_dir( "" ) {
|
||||
// No Compression for frame_captures
|
||||
frame_options.compression = frame_options.NONE;
|
||||
options.frameRate = frame_rate;
|
||||
capture_frames = cap_frames;
|
||||
}
|
||||
|
||||
Recorder::~Recorder() {
|
||||
stopRecording();
|
||||
};
|
||||
stopRecording();
|
||||
}
|
||||
|
||||
void Recorder::newRecording(unsigned int framerate, QDir p_dir, QString r_name, bool cap_frames) {
|
||||
stopRecording();
|
||||
void Recorder::setProjectDir( QString &p_dir ) {
|
||||
QFileInfo pDirInfo( p_dir );
|
||||
if( !pDirInfo.isDir() || !pDirInfo.isWritable() ) {
|
||||
throw RecorderError::INVALID_PROJECT_DIRECTORY;
|
||||
return;
|
||||
}
|
||||
|
||||
// check if directory is a directory and is writable
|
||||
project_dir = p_dir;
|
||||
project_dir = QDir( p_dir );
|
||||
}
|
||||
|
||||
QFileInfo pDirInfo(project_dir.path());
|
||||
if(!pDirInfo.isDir() || !pDirInfo.isWritable()) {
|
||||
throw RecorderError::INVALID_PROJECT_DIRECTORY;
|
||||
return;
|
||||
}
|
||||
void Recorder::newRecording( QString r_name ) {
|
||||
stopRecording();
|
||||
|
||||
rec_name = r_name;
|
||||
capture_frames = cap_frames;
|
||||
// If unset.
|
||||
if( !dirSet() ) {
|
||||
throw RecorderError::INVALID_PROJECT_DIRECTORY;
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify Recdir... create directories...
|
||||
QDir record_dir(project_dir.path() + rec_name);
|
||||
RecorderError err = verifyRecDir();
|
||||
if(err != RecorderError::OK) {
|
||||
throw err;
|
||||
return;
|
||||
}
|
||||
rec_name = r_name;
|
||||
|
||||
// get Status file
|
||||
QFile stat_file(project_dir.path() + rec_name + ".stat");
|
||||
if(!stat_file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
throw RecorderError::CANT_OPEN_STATFILE;
|
||||
return;
|
||||
}
|
||||
// Verify Recdir... create directories...
|
||||
QDir record_dir( project_dir.path() + rec_name );
|
||||
RecorderError err = verifyRecDir();
|
||||
if( err != RecorderError::OK ) {
|
||||
throw err;
|
||||
return;
|
||||
}
|
||||
|
||||
// If append, figure out Frame count etc...
|
||||
if(append) {
|
||||
if(!restoreRecording()) {
|
||||
throw RecorderError::STATFILE_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// get Status file
|
||||
QFile stat_file( project_dir.path() + rec_name + ".stat" );
|
||||
if( !stat_file.open( QIODevice::ReadWrite | QIODevice::Text ) ) {
|
||||
throw RecorderError::CANT_OPEN_STATFILE;
|
||||
return;
|
||||
}
|
||||
|
||||
Error f_err;
|
||||
// If append, figure out Frame count etc...
|
||||
if( append ) {
|
||||
if( !restoreRecording() ) {
|
||||
throw RecorderError::STATFILE_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// set recorder options
|
||||
options.frameRate = framerate;
|
||||
Error f_err;
|
||||
|
||||
// open AVI in recorder
|
||||
f_err = recorder.AVIOpen((record_dir.path() + rec_name).toStdString().c_str(), &options);
|
||||
if (f_err != PGRERROR_OK)
|
||||
{
|
||||
throw f_err;
|
||||
return;
|
||||
}
|
||||
// open AVI in recorder
|
||||
f_err = recorder.AVIOpen( ( record_dir.path() + rec_name ).toStdString().c_str(), &options );
|
||||
if ( f_err != PGRERROR_OK ) {
|
||||
throw f_err;
|
||||
return;
|
||||
}
|
||||
|
||||
is_recording = true;
|
||||
};
|
||||
is_recording = true;
|
||||
}
|
||||
|
||||
bool Recorder::restoreRecording() {
|
||||
bool ok;
|
||||
frame_n = stat_file.readLine().toInt(&ok, 10);
|
||||
bool ok;
|
||||
frame_n = stat_file.readLine().toInt( &ok, 10 );
|
||||
|
||||
return ok;
|
||||
return ok;
|
||||
}
|
||||
|
||||
RecorderError Recorder::verifyRecDir() {
|
||||
// check if project with same name exists and append to that
|
||||
// TODO: chech if there is any option to append
|
||||
// TODO: Check for special chars.
|
||||
|
||||
if(rec_name == "") {
|
||||
return RecorderError::INVALID_RECORDING_NAME;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
if(record_dir.exists()) {
|
||||
QMessageBox msgBox;
|
||||
|
||||
msgBox.setText(tr("A recording with this name already exists. Which action should be taken?"));
|
||||
void *appendButton = msgBox.addButton(tr("Append the recording."), QMessageBox::ActionRole);
|
||||
void *removeButton = msgBox.addButton(tr("Overwrite recording."), QMessageBox::ActionRole);
|
||||
void *abortButton = msgBox.addButton(QMessageBox::Abort);
|
||||
// check if project with same name exists and append to that
|
||||
// TODO: chech if there is any option to append
|
||||
// TODO: Check for special chars.
|
||||
|
||||
msgBox.exec();
|
||||
if( rec_name == "" ) {
|
||||
return RecorderError::INVALID_RECORDING_NAME;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
if (msgBox.clickedButton() == appendButton) {
|
||||
append = true;
|
||||
} else if (msgBox.clickedButton() == removeButton) {
|
||||
record_dir.removeRecursively();
|
||||
} else if (msgBox.clickedButton() == abortButton) {
|
||||
return RecorderError::CANCELED;
|
||||
}
|
||||
}
|
||||
if( record_dir.exists() ) {
|
||||
QMessageBox msgBox;
|
||||
|
||||
project_dir.mkdir(rec_name);
|
||||
if(capture_frames)
|
||||
record_dir.mkdir("frames");
|
||||
msgBox.setText( tr( "A recording with this name already exists. Which action should be taken?" ) );
|
||||
void * appendButton = msgBox.addButton( tr( "Append the recording." ), QMessageBox::ActionRole );
|
||||
void * removeButton = msgBox.addButton( tr( "Overwrite recording." ), QMessageBox::ActionRole );
|
||||
void * abortButton = msgBox.addButton( QMessageBox::Abort );
|
||||
|
||||
return RecorderError::OK;
|
||||
msgBox.exec();
|
||||
|
||||
if ( msgBox.clickedButton() == appendButton ) {
|
||||
append = true;
|
||||
} else if ( msgBox.clickedButton() == removeButton ) {
|
||||
record_dir.removeRecursively();
|
||||
} else if ( msgBox.clickedButton() == abortButton ) {
|
||||
return RecorderError::CANCELED;
|
||||
}
|
||||
}
|
||||
|
||||
project_dir.mkdir( rec_name );
|
||||
return RecorderError::OK;
|
||||
}
|
||||
|
||||
void Recorder::stopRecording() {
|
||||
if(is_recording) {
|
||||
// Stop Recorder
|
||||
Error err = recorder.AVIClose();
|
||||
if(err != PGRERROR_OK) {
|
||||
throw err;
|
||||
return;
|
||||
}
|
||||
if( is_recording ) {
|
||||
// Stop Recorder
|
||||
Error err = recorder.AVIClose();
|
||||
if( err != PGRERROR_OK ) {
|
||||
throw err;
|
||||
return;
|
||||
}
|
||||
|
||||
is_recording = false;
|
||||
cleanup();
|
||||
}
|
||||
is_recording = false;
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void Recorder::cleanup() {
|
||||
// Reset Everything
|
||||
if(!is_recording) {
|
||||
frame_n = 0;
|
||||
time_c = 0;
|
||||
project_dir = "";
|
||||
rec_name = "";
|
||||
capture_frames = false;
|
||||
append = false;
|
||||
}
|
||||
// Reset Everything
|
||||
if( !is_recording ) {
|
||||
frame_n = 0;
|
||||
time_c = 0;
|
||||
project_dir = "";
|
||||
rec_name = "";
|
||||
capture_frames = false;
|
||||
append = false;
|
||||
}
|
||||
};
|
||||
|
||||
void Recorder::appendFrame(FlyCapture2::Image *image) {
|
||||
void Recorder::appendFrame( FlyCapture2::Image * image ) {
|
||||
write_lock.lock();
|
||||
// If not recording, just stop.
|
||||
if(!is_recording)
|
||||
return;
|
||||
|
||||
Error app_err = recorder.AVIAppend(image);
|
||||
if(app_err != PGRERROR_OK) {
|
||||
if( !is_recording )
|
||||
return;
|
||||
|
||||
Error app_err = recorder.AVIAppend( image );
|
||||
if( app_err != PGRERROR_OK ) {
|
||||
write_lock.unlock();
|
||||
throw app_err;
|
||||
return;
|
||||
}
|
||||
throw app_err;
|
||||
return;
|
||||
}
|
||||
|
||||
// save image as frame
|
||||
if(capture_frames) {
|
||||
app_err = image->Save((record_dir.path() + "frames/" + frame_n).toStdString().c_str(), &frame_options);
|
||||
if(app_err != PGRERROR_OK) {
|
||||
// save image as frame
|
||||
if( capture_frames ) {
|
||||
app_err = image->Save( ( record_dir.path() + "frames/" + frame_n ).toStdString().c_str(), &frame_options );
|
||||
if( app_err != PGRERROR_OK ) {
|
||||
write_lock.unlock();
|
||||
throw app_err;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw app_err;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
frame_n++;
|
||||
time_c = frame_n / options.frameRate;
|
||||
frame_n++;
|
||||
time_c = frame_n / options.frameRate;
|
||||
write_lock.unlock();
|
||||
}
|
||||
|
|
140
src/recorder.h
140
src/recorder.h
|
@ -16,82 +16,104 @@
|
|||
*/
|
||||
|
||||
enum class RecorderError {
|
||||
INVALID_PROJECT_DIRECTORY,
|
||||
INVALID_RECORDING_NAME,
|
||||
CREATION_RECORD_DIRECTORY_FAILED,
|
||||
CANCELED,
|
||||
CANT_OPEN_STATFILE,
|
||||
STATFILE_ERROR,
|
||||
OK
|
||||
INVALID_PROJECT_DIRECTORY,
|
||||
INVALID_RECORDING_NAME,
|
||||
CREATION_RECORD_DIRECTORY_FAILED,
|
||||
CANCELED,
|
||||
CANT_OPEN_STATFILE,
|
||||
STATFILE_ERROR,
|
||||
OK
|
||||
};
|
||||
|
||||
class Recorder : QObject {
|
||||
Q_OBJECT
|
||||
class Recorder : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Set bitrate to a default of 10Mbit.
|
||||
Recorder(QObject *parent = 0);
|
||||
~Recorder();
|
||||
public:
|
||||
// Set bitrate to a default of 10Mbit.
|
||||
Recorder( QObject * parent = 0, unsigned int frame_rate = 18, bool cap_frames = false );
|
||||
~Recorder();
|
||||
|
||||
// Start a recording. A recording directory with the avi files and evtl. a frame subfolder will be created. Throws RecorderError or FlyCapture2::Error
|
||||
void newRecording(unsigned int framerate, QDir p_dir, QString r_name, bool capture_frames = false);
|
||||
// Start a recording. A recording directory with the avi files and evtl. a frame subfolder will be created. Throws RecorderError or FlyCapture2::Error
|
||||
void newRecording(QString r_name );
|
||||
|
||||
// Append a frame to the recording,
|
||||
void appendFrame(FlyCapture2::Image *image);
|
||||
|
||||
// stops the recording, cleans up, throws FlyCapture2::Error
|
||||
void stopRecording();
|
||||
// Append a frame to the recording,
|
||||
void appendFrame( FlyCapture2::Image * image );
|
||||
|
||||
QString getRecordingFileName() {
|
||||
return rec_name;
|
||||
}
|
||||
// stops the recording, cleans up, throws FlyCapture2::Error
|
||||
void stopRecording();
|
||||
|
||||
QString getRecName() {
|
||||
return rec_name;
|
||||
}
|
||||
QString getProjectDir() {
|
||||
return project_dir.absolutePath();
|
||||
}
|
||||
|
||||
bool isRecording() {
|
||||
return is_recording;
|
||||
}
|
||||
|
||||
const unsigned int& frame_number;
|
||||
const double& time_captured;
|
||||
QString getRecName() {
|
||||
return rec_name;
|
||||
}
|
||||
|
||||
private:
|
||||
FlyCapture2::AVIRecorder recorder;
|
||||
FlyCapture2::AVIOption options;
|
||||
FlyCapture2::TIFFOption frame_options;
|
||||
bool isRecording() {
|
||||
return is_recording;
|
||||
}
|
||||
|
||||
// Basic state Variable, because AVIRecorder doesn't provide it.
|
||||
bool is_recording;
|
||||
unsigned int getFrameRate() {
|
||||
return options.frameRate;
|
||||
}
|
||||
|
||||
// append to existing files
|
||||
bool append;
|
||||
void setProjectDir( QString &p_dir );
|
||||
void setFrameRate( unsigned int frame_rate ) {
|
||||
options.frameRate = frame_rate;
|
||||
}
|
||||
|
||||
// save individual frames as image files
|
||||
bool capture_frames;
|
||||
bool dirSet() {
|
||||
return ( project_dir.path() != "" );
|
||||
}
|
||||
|
||||
// number of frames captured
|
||||
unsigned int frame_n;
|
||||
double time_c;
|
||||
|
||||
QDir project_dir;
|
||||
QDir record_dir;
|
||||
QString rec_name;
|
||||
bool captureFrames() {
|
||||
return capture_frames;
|
||||
}
|
||||
|
||||
// status file for frame count
|
||||
QFile stat_file;
|
||||
const unsigned int &frame_number;
|
||||
const double &time_captured;
|
||||
|
||||
// Check if recording directory exists. If it does ask for Overwrite or cancelation.
|
||||
RecorderError verifyRecDir();
|
||||
public slots:
|
||||
void setCaptureFrames( bool set ) {
|
||||
capture_frames = set;
|
||||
}
|
||||
|
||||
// If appending, check if there are any information about existing frames...
|
||||
bool restoreRecording();
|
||||
private:
|
||||
FlyCapture2::AVIRecorder recorder;
|
||||
FlyCapture2::AVIOption options;
|
||||
FlyCapture2::TIFFOption frame_options;
|
||||
|
||||
// reset Status, only if not recording (is_recording == false).
|
||||
void cleanup();
|
||||
// Basic state Variable, because AVIRecorder doesn't provide it.
|
||||
bool is_recording;
|
||||
|
||||
// lock the appendFrame function.
|
||||
QMutex write_lock;
|
||||
// append to existing files
|
||||
bool append;
|
||||
|
||||
// save individual frames as image files
|
||||
bool capture_frames;
|
||||
|
||||
// number of frames captured
|
||||
unsigned int frame_n;
|
||||
double time_c;
|
||||
|
||||
QDir project_dir;
|
||||
QDir record_dir;
|
||||
QString rec_name;
|
||||
|
||||
// status file for frame count
|
||||
QFile stat_file;
|
||||
|
||||
// Check if recording directory exists. If it does ask for Overwrite or cancelation.
|
||||
RecorderError verifyRecDir();
|
||||
|
||||
// If appending, check if there are any information about existing frames...
|
||||
bool restoreRecording();
|
||||
|
||||
// reset Status, only if not recording (is_recording == false).
|
||||
void cleanup();
|
||||
|
||||
// lock the appendFrame function.
|
||||
QMutex write_lock;
|
||||
};
|
||||
#endif //RECORDER_H
|
||||
|
|
|
@ -38,12 +38,12 @@ public:
|
|||
QFrame *recOptions;
|
||||
QVBoxLayout *verticalLayout;
|
||||
QLineEdit *projectName;
|
||||
QPushButton *pushButton;
|
||||
QPushButton *startButton;
|
||||
QFrame *frame_3;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QLabel *label_2;
|
||||
QSpinBox *fps_box;
|
||||
QCheckBox *checkBox;
|
||||
QCheckBox *saveFrames;
|
||||
QPushButton *preview_button;
|
||||
QSpacerItem *verticalSpacer;
|
||||
QFrame *frame_2;
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
QLabel *label;
|
||||
QComboBox *cameraSelector;
|
||||
QPushButton *camScanButton;
|
||||
QPushButton *pushButton_2;
|
||||
QPushButton *directorySelector;
|
||||
QLabel *preview_widget;
|
||||
|
||||
void setupUi(QMainWindow *MainWindow)
|
||||
|
@ -93,11 +93,12 @@ public:
|
|||
|
||||
verticalLayout->addWidget(projectName);
|
||||
|
||||
pushButton = new QPushButton(recOptions);
|
||||
pushButton->setObjectName(QStringLiteral("pushButton"));
|
||||
pushButton->setFlat(false);
|
||||
startButton = new QPushButton(recOptions);
|
||||
startButton->setObjectName(QStringLiteral("startButton"));
|
||||
startButton->setEnabled(false);
|
||||
startButton->setFlat(false);
|
||||
|
||||
verticalLayout->addWidget(pushButton);
|
||||
verticalLayout->addWidget(startButton);
|
||||
|
||||
frame_3 = new QFrame(recOptions);
|
||||
frame_3->setObjectName(QStringLiteral("frame_3"));
|
||||
|
@ -122,10 +123,10 @@ public:
|
|||
|
||||
verticalLayout->addWidget(frame_3);
|
||||
|
||||
checkBox = new QCheckBox(recOptions);
|
||||
checkBox->setObjectName(QStringLiteral("checkBox"));
|
||||
saveFrames = new QCheckBox(recOptions);
|
||||
saveFrames->setObjectName(QStringLiteral("saveFrames"));
|
||||
|
||||
verticalLayout->addWidget(checkBox);
|
||||
verticalLayout->addWidget(saveFrames);
|
||||
|
||||
preview_button = new QPushButton(recOptions);
|
||||
preview_button->setObjectName(QStringLiteral("preview_button"));
|
||||
|
@ -177,10 +178,10 @@ public:
|
|||
|
||||
verticalLayout_2->addWidget(camScanButton);
|
||||
|
||||
pushButton_2 = new QPushButton(frame_2);
|
||||
pushButton_2->setObjectName(QStringLiteral("pushButton_2"));
|
||||
directorySelector = new QPushButton(frame_2);
|
||||
directorySelector->setObjectName(QStringLiteral("directorySelector"));
|
||||
|
||||
verticalLayout_2->addWidget(pushButton_2);
|
||||
verticalLayout_2->addWidget(directorySelector);
|
||||
|
||||
|
||||
gridLayout->addWidget(frame_2, 0, 0, 1, 1);
|
||||
|
@ -204,14 +205,14 @@ public:
|
|||
{
|
||||
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "Taevitas", Q_NULLPTR));
|
||||
projectName->setPlaceholderText(QApplication::translate("MainWindow", "Project Name", Q_NULLPTR));
|
||||
pushButton->setText(QApplication::translate("MainWindow", "Start", Q_NULLPTR));
|
||||
startButton->setText(QApplication::translate("MainWindow", "Start", Q_NULLPTR));
|
||||
label_2->setText(QApplication::translate("MainWindow", "FPS: ", Q_NULLPTR));
|
||||
checkBox->setText(QApplication::translate("MainWindow", " Save Frames", Q_NULLPTR));
|
||||
saveFrames->setText(QApplication::translate("MainWindow", " Save Frames", Q_NULLPTR));
|
||||
preview_button->setText(QApplication::translate("MainWindow", "Preview Camera", Q_NULLPTR));
|
||||
label->setText(QApplication::translate("MainWindow", "Camera:", Q_NULLPTR));
|
||||
cameraSelector->setCurrentText(QString());
|
||||
camScanButton->setText(QApplication::translate("MainWindow", "Rescan Cameras", Q_NULLPTR));
|
||||
pushButton_2->setText(QApplication::translate("MainWindow", "Output Folder", Q_NULLPTR));
|
||||
directorySelector->setText(QApplication::translate("MainWindow", "Working Directory", Q_NULLPTR));
|
||||
preview_widget->setText(QString());
|
||||
} // retranslateUi
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue