mirror of
https://github.com/vale981/Taevitas
synced 2025-03-05 17:41: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,15 +6,15 @@
|
|||
#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)
|
||||
{
|
||||
camMan( this ),
|
||||
recorder( this, 18, false ) {
|
||||
ui->setupUi( this );
|
||||
|
||||
// Set Scene and Hide Preview Widget
|
||||
|
@ -30,16 +30,28 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
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 );
|
||||
|
||||
// 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() {
|
||||
|
@ -56,18 +68,26 @@ void MainWindow::updateCameraList(unsigned int num_cameras) {
|
|||
}
|
||||
|
||||
void MainWindow::scanAndUpdateCameras() {
|
||||
unsigned int num_cameras = cam_man.numCameras();
|
||||
unsigned int num_cameras = camMan.numCameras();
|
||||
updateCameraList( num_cameras );
|
||||
if(num_cameras > 0 && !cam_man.isConnected())
|
||||
camera_selected(0);
|
||||
if( num_cameras > 0 && !camMan.isConnected() )
|
||||
cameraSelected( 0 );
|
||||
};
|
||||
|
||||
void MainWindow::disableRecOptions() {
|
||||
ui->recOptions->setProperty( "enabled", false );
|
||||
ui->startButton->setProperty( "enabled", false );
|
||||
}
|
||||
|
||||
void MainWindow::enableRecOptions() {
|
||||
ui->recOptions->setProperty( "enabled", true );
|
||||
enableStart();
|
||||
}
|
||||
|
||||
void MainWindow::enableStart() {
|
||||
if( ui->projectName->text() != "" && recorder.dirSet() && camMan.isConnected() ) {
|
||||
ui->startButton->setProperty( "enabled", true );
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showError( QString error ) {
|
||||
|
@ -81,12 +101,12 @@ void MainWindow::showError(FlyCapture2::Error error) {
|
|||
showError( error.GetDescription() );
|
||||
}
|
||||
|
||||
void MainWindow::camera_selected(int index) {
|
||||
void MainWindow::cameraSelected( int index ) {
|
||||
if( recorder.isRecording() || index < 0 )
|
||||
return;
|
||||
|
||||
try {
|
||||
cam_man.connectCamera(index);
|
||||
camMan.connectCamera( index );
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
return;
|
||||
|
@ -96,9 +116,9 @@ void MainWindow::camera_selected(int index) {
|
|||
};
|
||||
|
||||
// Show/Hide Preview
|
||||
void MainWindow::toggle_preview(bool checked) {
|
||||
void MainWindow::togglePreview( bool checked ) {
|
||||
// skip if there is no camera
|
||||
if(!cam_man.isConnected()) {
|
||||
if( !camMan.isConnected() ) {
|
||||
ui->preview_button->setProperty( "checked", false );
|
||||
return;
|
||||
}
|
||||
|
@ -108,7 +128,7 @@ void MainWindow::toggle_preview(bool checked) {
|
|||
|
||||
// Start Capturing for preview
|
||||
try {
|
||||
cam_man.startCapture();
|
||||
camMan.startCapture();
|
||||
} catch ( FlyCapture2::Error e ) {
|
||||
showError( e );
|
||||
}
|
||||
|
@ -118,7 +138,7 @@ void MainWindow::toggle_preview(bool checked) {
|
|||
|
||||
//Stop capture
|
||||
if( !recorder.isRecording() )
|
||||
cam_man.stopCapture();
|
||||
camMan.stopCapture();
|
||||
}
|
||||
|
||||
adjustSize();
|
||||
|
@ -133,6 +153,7 @@ void MainWindow::frameCaptured(FlyCapture2::Image* image) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Render Preview
|
||||
void MainWindow::displayPreview( FlyCapture2::Image * last_capture ) {
|
||||
ui->preview_widget->show();
|
||||
|
||||
|
@ -151,3 +172,53 @@ void MainWindow::displayPreview(FlyCapture2::Image* last_capture) {
|
|||
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
|
||||
|
|
|
@ -1,29 +1,37 @@
|
|||
#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} {
|
||||
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();
|
||||
};
|
||||
}
|
||||
|
||||
void Recorder::newRecording(unsigned int framerate, QDir p_dir, QString r_name, bool cap_frames) {
|
||||
stopRecording();
|
||||
|
||||
// check if directory is a directory and is writable
|
||||
project_dir = p_dir;
|
||||
|
||||
QFileInfo pDirInfo(project_dir.path());
|
||||
void Recorder::setProjectDir( QString &p_dir ) {
|
||||
QFileInfo pDirInfo( p_dir );
|
||||
if( !pDirInfo.isDir() || !pDirInfo.isWritable() ) {
|
||||
throw RecorderError::INVALID_PROJECT_DIRECTORY;
|
||||
return;
|
||||
}
|
||||
|
||||
project_dir = QDir( p_dir );
|
||||
}
|
||||
|
||||
void Recorder::newRecording( QString r_name ) {
|
||||
stopRecording();
|
||||
|
||||
// If unset.
|
||||
if( !dirSet() ) {
|
||||
throw RecorderError::INVALID_PROJECT_DIRECTORY;
|
||||
return;
|
||||
}
|
||||
|
||||
rec_name = r_name;
|
||||
capture_frames = cap_frames;
|
||||
|
||||
// Verify Recdir... create directories...
|
||||
QDir record_dir( project_dir.path() + rec_name );
|
||||
|
@ -50,19 +58,15 @@ void Recorder::newRecording(unsigned int framerate, QDir p_dir, QString r_name,
|
|||
|
||||
Error f_err;
|
||||
|
||||
// set recorder options
|
||||
options.frameRate = framerate;
|
||||
|
||||
// open AVI in recorder
|
||||
f_err = recorder.AVIOpen( ( record_dir.path() + rec_name ).toStdString().c_str(), &options );
|
||||
if (f_err != PGRERROR_OK)
|
||||
{
|
||||
if ( f_err != PGRERROR_OK ) {
|
||||
throw f_err;
|
||||
return;
|
||||
}
|
||||
|
||||
is_recording = true;
|
||||
};
|
||||
}
|
||||
|
||||
bool Recorder::restoreRecording() {
|
||||
bool ok;
|
||||
|
@ -101,9 +105,6 @@ RecorderError Recorder::verifyRecDir() {
|
|||
}
|
||||
|
||||
project_dir.mkdir( rec_name );
|
||||
if(capture_frames)
|
||||
record_dir.mkdir("frames");
|
||||
|
||||
return RecorderError::OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,16 +25,16 @@ enum class RecorderError {
|
|||
OK
|
||||
};
|
||||
|
||||
class Recorder : QObject {
|
||||
class Recorder : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Set bitrate to a default of 10Mbit.
|
||||
Recorder(QObject *parent = 0);
|
||||
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);
|
||||
void newRecording(QString r_name );
|
||||
|
||||
// Append a frame to the recording,
|
||||
void appendFrame( FlyCapture2::Image * image );
|
||||
|
@ -42,8 +42,8 @@ public:
|
|||
// stops the recording, cleans up, throws FlyCapture2::Error
|
||||
void stopRecording();
|
||||
|
||||
QString getRecordingFileName() {
|
||||
return rec_name;
|
||||
QString getProjectDir() {
|
||||
return project_dir.absolutePath();
|
||||
}
|
||||
|
||||
QString getRecName() {
|
||||
|
@ -54,9 +54,31 @@ public:
|
|||
return is_recording;
|
||||
}
|
||||
|
||||
unsigned int getFrameRate() {
|
||||
return options.frameRate;
|
||||
}
|
||||
|
||||
void setProjectDir( QString &p_dir );
|
||||
void setFrameRate( unsigned int frame_rate ) {
|
||||
options.frameRate = frame_rate;
|
||||
}
|
||||
|
||||
bool dirSet() {
|
||||
return ( project_dir.path() != "" );
|
||||
}
|
||||
|
||||
bool captureFrames() {
|
||||
return capture_frames;
|
||||
}
|
||||
|
||||
const unsigned int &frame_number;
|
||||
const double &time_captured;
|
||||
|
||||
public slots:
|
||||
void setCaptureFrames( bool set ) {
|
||||
capture_frames = set;
|
||||
}
|
||||
|
||||
private:
|
||||
FlyCapture2::AVIRecorder recorder;
|
||||
FlyCapture2::AVIOption options;
|
||||
|
|
|
@ -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