Skip to content

Commit

Permalink
Added in functionality to record from video file and added in a QMain…
Browse files Browse the repository at this point in the history
…Window and a main display widget
  • Loading branch information
benhoff committed Apr 14, 2015
1 parent fe468bc commit 995bb7f
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CVOpenGLWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Q_OBJECT
void imageSizeChanged( int out_width, int out_height );

public slots:
bool ImageSlot( QImage* image); /// used to set the image to be viewed
bool ImageSlot(QImage* image); /// used to set the image to be viewed


private:
Expand Down
18 changes: 16 additions & 2 deletions camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Camera::Camera(QObject* parent) : QObject(parent)
cv::String eyeCascadeFilename = "/home/hoff/swdev/opencv_tut/opencv/haarcascade_eye.xml";

loadFiles(faceCascadeFilename, eyeCascadeFilename);
usingVideoCamera_ = true;
}

Camera::~Camera()
Expand Down Expand Up @@ -54,7 +54,11 @@ void Camera::loadFiles(cv::String faceCascadeFilename,
void Camera::runSlot()
{
// TODO: want to be able to select this
capture->open(cameraIndex_);
if (usingVideoCamera_)
capture->open(cameraIndex_);
else
capture->open(videoFileName_);

if( capture->isOpened() )
{
while( true )
Expand All @@ -81,11 +85,21 @@ void Camera::runSlot()
}
}

void Camera::usingVideoCameraSlot(bool value)
{
usingVideoCamera_ = value;
}

void Camera::cameraIndexSlot(int index)
{
cameraIndex_ = index;
}

void Camera::videoFileNameSlot(QString fileName)
{
videoFileName_ = fileName.toStdString().c_str();
}

void Camera::detectAndDisplay( cv::Mat frame )
{
std::vector<cv::Rect> faces;
Expand Down
4 changes: 4 additions & 0 deletions camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Q_OBJECT
public slots:
void runSlot();
void cameraIndexSlot(int index);
void videoFileNameSlot(QString fileName);
void usingVideoCameraSlot(bool value);

signals:
void imageSignal(QImage* image);
Expand All @@ -38,5 +40,7 @@ public slots:
void loadFiles(cv::String faceCascadeFilename, cv::String eyesCascadeFilename);

private:
bool usingVideoCamera_;
int cameraIndex_;
cv::String videoFileName_;
};
59 changes: 59 additions & 0 deletions displaywidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "displaywidget.h"

DisplayWidget::DisplayWidget(QWidget *parent) : QWidget(parent)
{
QStringList cameraOptions;
cameraOptions << "0" << "1" << "2" << "3" << "4" << "5" << "6";
QComboBox* cameraComboBox = new QComboBox;
cameraComboBox->addItems(cameraOptions);

QHBoxLayout* horizontalLayout = new QHBoxLayout();
QPushButton *runButton = new QPushButton("run", this);
QPushButton *fileSelector = new QPushButton("select file");
horizontalLayout->addWidget(cameraComboBox);
horizontalLayout->addWidget(fileSelector);
horizontalLayout->addWidget(runButton);

QVBoxLayout *layout = new QVBoxLayout;
CVOpenGLWidget* openGLWidget = new CVOpenGLWidget(this);
QRadioButton *sourceSelector = new QRadioButton("Stream from video camera", this);
sourceSelector->setDown(true);

layout->addWidget(openGLWidget);
layout->addLayout(horizontalLayout);
layout->addWidget(sourceSelector);

setLayout(layout);

Camera* camera = new Camera(this);

QObject::connect(camera, SIGNAL(imageSignal(QImage*)),
openGLWidget, SLOT(ImageSlot(QImage*)));

// TODO: Add in slot to turn off camera, or something
QObject::connect(runButton, SIGNAL(clicked()),
camera, SLOT(runSlot()));

QObject::connect(cameraComboBox, SIGNAL(currentIndexChanged(int)),
camera, SLOT(cameraIndexSlot(int)));

QObject::connect(fileSelector, SIGNAL(clicked()),
this, SLOT(openFileDialog()));

QObject::connect(sourceSelector, SIGNAL(toggled(bool)),
camera, SLOT(usingVideoCameraSlot(bool)));

QObject::connect(this, SIGNAL(videoFileNameSignal(QString)),
camera, SLOT(videoFileNameSlot(QString)));
}

DisplayWidget::~DisplayWidget()
{

}

void DisplayWidget::openFileDialog()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Video"));
emit videoFileNameSignal(filename);
}
34 changes: 34 additions & 0 deletions displaywidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef DISPLAYWIDGET_H
#define DISPLAYWIDGET_H

#include <QWidget>

#include <QObject>
#include <QVBoxLayout>
#include <QPushButton>
#include <QRadioButton>
#include <QComboBox>
#include <QFileDialog>
#include <QFile>

#include <iostream>
#include <stdio.h>

#include "CVOpenGLWidget.h"
#include "camera.h"

class DisplayWidget : public QWidget
{
Q_OBJECT
public:
explicit DisplayWidget(QWidget *parent = 0);
~DisplayWidget();

signals:
void videoFileNameSignal(QString videoFileName);

public slots:
void openFileDialog();
};

#endif // DISPLAYWIDGET_H
45 changes: 3 additions & 42 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
#include <QApplication>
#include <QObject>
#include <QVBoxLayout>
#include <QPushButton>
#include <QComboBox>

#include <iostream>
#include <stdio.h>

#include "CVOpenGLWidget.h"
#include "camera.h"
#include "mainwindow.h"

using namespace std;

/** @function main */
int main( int argc, char* argv[] )
{
QApplication app(argc, argv);

QStringList cameraOptions;
cameraOptions << "0" << "1" << "2" << "3" << "4" << "5" << "6";
QComboBox cameraComboBox;
cameraComboBox.addItems(cameraOptions);

QHBoxLayout* horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(&cameraComboBox);
QPushButton *runButton = new QPushButton("run");
horizontalLayout->addWidget(runButton);

QVBoxLayout *layout = new QVBoxLayout;
QWidget layoutWidget;
CVOpenGLWidget openGLWidget(&layoutWidget);
layout->addWidget(&openGLWidget);
layout->addLayout(horizontalLayout);

layoutWidget.setLayout(layout);

Camera camera;
QObject::connect(&camera, SIGNAL(imageSignal(QImage*)),
&openGLWidget, SLOT(ImageSlot(QImage*)));


// TODO: Add in slot to turn off camera, or something
QObject::connect(runButton, SIGNAL(clicked()),
&camera, SLOT(runSlot()));

QObject::connect(&cameraComboBox, SIGNAL(currentIndexChanged(int)),
&camera, SLOT(cameraIndexSlot(int)));
layoutWidget.show();

MainWindow window;
window.show();
return app.exec();
}
13 changes: 13 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
DisplayWidget* display = new DisplayWidget(this);
setCentralWidget(display);
}

MainWindow::~MainWindow()
{

}

16 changes: 16 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "displaywidget.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

signals:
};

#endif // MAINWINDOW_H
16 changes: 10 additions & 6 deletions opencv.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
QT += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
TARGET = opencv
TEMPLATE = app
INCLUDEPATH += /usr/include/opencv
LIBS += -L/lib -lopencv_calib3d -lopencv_core -lopencv_cudaarithm -lopencv_cudabgsegm -lopencv_cudacodec -lopencv_cudafeatures2d -lopencv_cudafilters -lopencv_cudaimgproc -lopencv_cudalegacy -lopencv_cudaobjdetect -lopencv_cudaoptflow -lopencv_cudastereo -lopencv_cudawarping -lopencv_cudev -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab

SOURCES += main.cpp
SOURCES += CVOpenGLWidget.cpp
SOURCES += camera.cpp
SOURCES += main.cpp \
mainwindow.cpp \
CVOpenGLWidget.cpp \
camera.cpp \
displaywidget.cpp

HEADERS += CVOpenGLWidget.h
HEADERS += camera.h
HEADERS += CVOpenGLWidget.h \
mainwindow.h \
camera.h \
displaywidget.h

0 comments on commit 995bb7f

Please sign in to comment.