Commit 11398845 authored by Jeff Niu's avatar Jeff Niu

Added camera selection dropdown

parent a36f6c70
......@@ -60,20 +60,11 @@ endif()
file(GLOB_RECURSE SOURCE_FILES
${PROJECT_SOURCE_DIR}/code/*.cpp
${PROJECT_SOURCE_DIR}/code/controller/*.cpp
${PROJECT_SOURCE_DIR}/code/graphics/*.cpp
${PROJECT_SOURCE_DIR}/code/gui/*.cpp
${PROJECT_SOURCE_DIR}/code/interpreter/*.cpp
${PROJECT_SOURCE_DIR}/code/simulator/*.cpp
${PROJECT_SOURCE_DIR}/code/utility/*.cpp)
${PROJECT_SOURCE_DIR}/code/**/*.cpp)
file(GLOB_RECURSE HEADER_FILES
${PROJECT_SOURCE_DIR}/code/controller/*.h
${PROJECT_SOURCE_DIR}/code/graphics/*.h
${PROJECT_SOURCE_DIR}/code/gui/*.h
${PROJECT_SOURCE_DIR}/code/interpreter/*.h
${PROJECT_SOURCE_DIR}/code/simulator/*.h
${PROJECT_SOURCE_DIR}/code/utility/*.h)
${PROJECT_SOURCE_DIR}/code/*.h
${PROJECT_SOURCE_DIR}/code/**/*.h)
file(GLOB_RECURSE FORM_FILES
${PROJECT_SOURCE_DIR}/code/gui/*.ui)
......
......@@ -102,10 +102,20 @@ From a fresh install, you will need these packages
sudo apt install build-essential cmake python3 python3-dev qt5-default libudev-dev git
```
OpenCV is a requirement. Download and build OpenCV 3.3 from the open-source repo, or
follow [these instructions](https://github.com/BVLC/caffe/wiki/OpenCV-3.3-Installation-Guide-on-Ubuntu-16.04).
OpenCV is a requirement. We are going to download and build OpenCV 3.3 with the additional
modules. Download [opencv-3.3](https://github.com/opencv/opencv/releases) and
[opencv_contrib-3.3](https://github.com/opencv/opencv_contrib/releases). Extract the folders
and create a build directory.
```bash
mkdir opencv-build
cd opencv-build
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules ..
make -j5
```
Then clone the repository and build with
```bash
git clone https://github.com/uwnrg/minotaur-cpp.git
cd minotaur-cpp
......@@ -117,6 +127,12 @@ make
And then run with `./minotaur-cpp`
If Qt is unable to detect cameras, make sure to run
```bash
sudo apt install libqt5multimedia5-plugins
```
### Contributing
Please refer to the [Contributing Guidelines](CONTRIBUTING.md).
......
#include "camera.h"
#include <QDebug>
#include <QtGui/QPainter>
#include <QCamera>
#include <QPainter>
#include <QCameraInfo>
#include <QAction>
Capture::Capture(QObject *parent)
: QObject(parent) {}
......@@ -117,27 +120,43 @@ IThread::~IThread() {
wait();
}
CameraDisplay::CameraDisplay(QWidget *parent, int camera)
CameraDisplay::CameraDisplay(QWidget *parent, int camera_index)
: QDialog(parent),
m_camera(camera),
m_camera(camera_index),
m_converter(nullptr, this) {
m_layout = new QVBoxLayout(this);
m_image_viewer = new ImageViewer(this);
setLayout(m_layout);
m_layout->addWidget(m_image_viewer);
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
#ifndef NDEBUG
qDebug() << "Found " << QCameraInfo::availableCameras().count() << "cameras" << endl;
#endif
m_camera_list = new QComboBox(this);
m_camera_list->setMinimumSize(150, 30);
for (int i = 0; i < cameras.size(); ++i) {
m_camera_list->addItem(cameras[i].deviceName(), QVariant::fromValue(i));
}
m_converter.setProcessAll(false);
m_capture_thread.start();
m_converter_thread.start();
m_capture.moveToThread(&m_capture_thread);
m_converter.moveToThread(&m_converter_thread);
setLayout(m_layout);
m_layout->addWidget(m_camera_list);
m_layout->addWidget(m_image_viewer);
QObject::connect(&m_capture, &Capture::matReady, &m_converter, &Converter::processFrame);
QObject::connect(&m_converter, &Converter::imageReady, m_image_viewer, &ImageViewer::setImage);
connect(m_camera_list, SIGNAL(currentIndexChanged(int)), this, SLOT(selectedCameraChanged(int)));
}
CameraDisplay::~CameraDisplay() {
delete m_layout;
delete m_image_viewer;
delete m_camera_list;
delete m_layout;
}
void CameraDisplay::setCamera(int camera) {
......@@ -166,3 +185,8 @@ void CameraDisplay::reject() {
void CameraDisplay::pauseVideo() {
QMetaObject::invokeMethod(&m_capture, "stop");
}
void CameraDisplay::selectedCameraChanged(int camera_index) {
QMetaObject::invokeMethod(&m_capture, "stop");
QMetaObject::invokeMethod(&m_capture, "start", Q_ARG(int, camera_index));
}
......@@ -6,14 +6,15 @@
#include <QWidget>
#include <QDialog>
#include <QThread>
#include <QtCore/QBasicTimer>
#include <QtCore/QArgument>
#include <QtCore/QMetaType>
#include <QtCore/QScopedPointer>
#include <QtCore/QTimerEvent>
#include <QtGui/QImage>
#include <QtGui/QPaintEvent>
#include <QtWidgets/QVBoxLayout>
#include <QBasicTimer>
#include <QArgument>
#include <QMetaType>
#include <QScopedPointer>
#include <QTimerEvent>
#include <QImage>
#include <QPaintEvent>
#include <QVBoxLayout>
#include <QComboBox>
Q_DECLARE_METATYPE(cv::Mat);
......@@ -90,23 +91,27 @@ class CameraDisplay : public QDialog {
Q_OBJECT
public:
explicit CameraDisplay(QWidget *parent = nullptr, int camera = 0);
explicit CameraDisplay(QWidget *parent = nullptr, int camera_index = 0);
~CameraDisplay() override;
void setCamera(int camera);
int getCamera();
int getCamera();
protected:
void setVisible(bool visible) override;
void reject() override;
protected Q_SLOTS:
void selectedCameraChanged(int camera_index);
private:
void pauseVideo();
QVBoxLayout *m_layout;
QComboBox *m_camera_list;
ImageViewer *m_image_viewer;
int m_camera;
......
#ifndef MINOTAUR_CPP_MODIFY_H
#define MINOTAUR_CPP_MODIFY_H
#include <opencv2/core/mat.hpp>
class VideoModifier {
public:
virtual void modify(cv::Mat *img) = 0;
};
#endif //MINOTAUR_CPP_MODIFY_H
#include "tracker.h"
void TrackerModifier::modify(cv::Mat *img) {
}
#ifndef MINOTAUR_CPP_TRACKER_H
#define MINOTAUR_CPP_TRACKER_H
#include "modify.h"
#include <opencv2/tracking
class TrackerModifier : public VideoModifier {
public:
void modify(cv::Mat *img) override;
private:
cv::Ptr<cv::Tracker> m_tracker;
};
#endif //MINOTAUR_CPP_TRACKER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment