Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Commit

Permalink
Added Support for (new) Besteker camera
Browse files Browse the repository at this point in the history
added camera reset button

Added default resetCamera
  • Loading branch information
ExSidius committed Nov 10, 2018
1 parent 7d3d86d commit e65cc7b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 12 deletions.
93 changes: 83 additions & 10 deletions Camera.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "Camera.h"
#include "QRegularExpression"
#include "QDebug"
#include <QProcess>

Camera::Camera(Arena& arena) : QObject(), mArena(arena) {
connect(&mCaptureTimer, SIGNAL(timeout()), SLOT(capture()));
mMarkerDetector.setDetectionMode(aruco::DM_VIDEO_FAST, 0.0001);
isBestekerCamera = false;
}

void Camera::capture() {
Expand All @@ -26,6 +30,19 @@ void Camera::capture() {

void Camera::applySettings(uint cameraDevice, QSize resolution, uint frameRate, float markerSize) {
mCameraDevice = cameraDevice;
QString bestekerCamera = QString("USB Live Camera");//name of the Besteker camera
QString command = QString("v4l2-ctl --list-devices");

QProcess process;
process.start(command);
process.waitForFinished(-1);

if (process.readAllStandardOutput().indexOf(bestekerCamera) != -1) {
//check for whether a live camera is plugged in (Besteker)
//Besteker has different brightness, sharpness settings and doesn't have a focus option
isBestekerCamera = true;
}

mVideoCapture.open(cameraDevice);

mVideoCapture.set(cv::CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G'));
Expand All @@ -37,16 +54,6 @@ void Camera::applySettings(uint cameraDevice, QSize resolution, uint frameRate,
mMarkerSize = markerSize;
}

void Camera::onBrightnessChanged(int brightness) {
QString command;
command = command + QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c brightness=");
command = command + QString::number(brightness);

system(command.toStdString().c_str());
}

void Camera::onCustomXChanged(double x) {
mCustomCoordinate.x = static_cast<float>(x);
}
Expand All @@ -69,6 +76,9 @@ void Camera::onDrawObstaclesChanged(bool draw) {

void Camera::onFocusChanged(int focus) {
QString command;

if (isBestekerCamera) return;

command = command + QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c focus_absolute=");
Expand All @@ -79,12 +89,75 @@ void Camera::onFocusChanged(int focus) {

void Camera::onSharpnessChanged(int sharpness) {
QString command;

if (isBestekerCamera) {
sharpness = sharpness * 6.0 / 255.0;
}
command = command + QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c sharpness=");
command = command + QString::number(sharpness);

system(command.toStdString().c_str());
}

void Camera::onBrightnessChanged(int brightness) {
QString command;
if (isBestekerCamera) {
brightness = brightness * 128.0 / 255.0 - 64;
}
command = command + QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c brightness=");
command = command + QString::number(brightness);

system(command.toStdString().c_str());
}

void Camera::resetCamera() {
//'v4l2-ctl -d /dev/video2 --all' lists default values for the camera
int sharpness, brightness, contrast;
QString command;
if (isBestekerCamera) {
sharpness = 6;
contrast = 64;
brightness = -64;
} else {
sharpness = 128;
contrast = 128;
brightness = 128;
}

//set sharpness
command = command + QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c sharpness=");
command = command + QString::number(sharpness);
system(command.toStdString().c_str());

//set brightness
command = QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c brightness=");
command = command + QString::number(brightness);
system(command.toStdString().c_str());

//set contrast
command = QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c contrast=");
command = command + QString::number(contrast);
system(command.toStdString().c_str());

//set focus
if (!isBestekerCamera) {
command = QString("v4l2-ctl -d /dev/video");
command = command + QString::number(mCameraDevice);
command = command + QString(" -c focus_absolute=");
command = command + QString::number(0);
system(command.toStdString().c_str());
}

}

inline QImage Camera::cvMatToQImage(const cv::Mat& inMat)
Expand Down
2 changes: 2 additions & 0 deletions Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Camera : public QObject {

public:
explicit Camera(Arena& arena);
void resetCamera();
bool isBestekerCamera;

public slots:
void applySettings(uint cameraDevice, QSize resolution, uint frameRate, float markerSize);
Expand Down
15 changes: 15 additions & 0 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void MainWindow::onApplySettingsClicked()
float markerSize = ui->markerSizeLineEdit->text().toFloat();

mCamera.applySettings(cameraDevice, resolution, frameRate, markerSize);
this->on_resetCamera_clicked();

// Arena size
float width = ui->arenaWidthLineEdit->text().toFloat();
Expand Down Expand Up @@ -92,3 +93,17 @@ void MainWindow::fillDefaultSettings()
onApplySettingsClicked();
}


void MainWindow::on_resetCamera_clicked()
{
mCamera.resetCamera();
if (mCamera.isBestekerCamera) {
ui->cameraFocusSlider->setValue(0);
ui->cameraBrightnessSlider->setValue(0);
ui->cameraSharpnessSlider->setValue(255);
} else {
ui->cameraFocusSlider->setValue(128);
ui->cameraBrightnessSlider->setValue(128);
ui->cameraSharpnessSlider->setValue(128);
}
}
1 change: 1 addition & 0 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private slots:
void onNewFrame(QImage image);
void onApplySettingsClicked();
void onRandomizeButtonClicked();
void on_resetCamera_clicked();

private:
Ui::MainWindow *ui;
Expand Down
11 changes: 9 additions & 2 deletions MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
Expand Down Expand Up @@ -345,6 +345,13 @@
</item>
</layout>
</item>
<item row="11" column="1">
<widget class="QPushButton" name="resetCamera">
<property name="text">
<string>Reset Camera</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -413,7 +420,7 @@
<x>0</x>
<y>0</y>
<width>1056</width>
<height>19</height>
<height>22</height>
</rect>
</property>
</widget>
Expand Down

0 comments on commit e65cc7b

Please sign in to comment.