add camera configuration dialog, non functional yet
This commit is contained in:
parent
4ae2945002
commit
bb500f465c
90
camconfig.cpp
Normal file
90
camconfig.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "camconfig.h"
|
||||
|
||||
CamConfigurator::CamConfigurator(Pylon::DeviceInfoList_t &deviceList, QWidget *parent) :
|
||||
deviceList(deviceList), QDialog(parent) {
|
||||
mode_combo = new QComboBox(this);
|
||||
mode_combo->addItem("single camera");
|
||||
if (deviceList.size() > 1){
|
||||
mode_combo->addItem("stereo camera");
|
||||
}
|
||||
connect(mode_combo, SIGNAL(currentIndexChanged(int)), SLOT(modeChanged(int)));
|
||||
|
||||
device_combo = new QComboBox(this);
|
||||
for (auto d : deviceList) {
|
||||
device_combo->addItem(QString(d.GetFullName().c_str()));
|
||||
}
|
||||
connect(device_combo, SIGNAL(currentIndexChanged(int)), SLOT(primaryDeviceChanged(int)));
|
||||
|
||||
orientation_combo = new QComboBox(this);
|
||||
orientation_combo->addItem("Vertical");
|
||||
orientation_combo->addItem("Horizontal");
|
||||
orientation_combo->setEnabled(false);
|
||||
|
||||
QWidget *header = new QWidget(this);
|
||||
QGridLayout *grid = new QGridLayout(header);
|
||||
grid->addWidget(new QLabel("Recording mode:", this), 0, 0);
|
||||
grid->addWidget(mode_combo, 0, 1);
|
||||
grid->addWidget(new QLabel("Primary device:", this), 1, 0);
|
||||
grid->addWidget(device_combo, 1, 1);
|
||||
grid->addWidget(new QLabel("Orientation:", this), 2, 0);
|
||||
grid->addWidget(orientation_combo, 2, 1);
|
||||
header->setLayout(grid);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout(this);
|
||||
vbox->addWidget(header);
|
||||
|
||||
stack = new QStackedWidget(this);
|
||||
stack->addWidget(singleCameraView());
|
||||
stack->addWidget(new QLabel("Stereo View"));
|
||||
stack->setCurrentIndex(0);
|
||||
vbox->addWidget(stack);
|
||||
|
||||
buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok
|
||||
| QDialogButtonBox::Cancel);
|
||||
connect(buttonbox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonbox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
vbox->addWidget(buttonbox);
|
||||
//this->setLayout(vbox);
|
||||
}
|
||||
|
||||
QWidget* CamConfigurator::singleCameraView() {
|
||||
QWidget *w = new QWidget(this);
|
||||
QVBoxLayout *l = new QVBoxLayout(w);
|
||||
l->setParent(w);
|
||||
w->setLayout(l);
|
||||
|
||||
QString cam_name = device_combo->currentText();
|
||||
singleCamPreview = new CameraPreview(cam_name, this);
|
||||
l->addWidget(singleCamPreview);
|
||||
return w;
|
||||
}
|
||||
|
||||
// void CamConfigurator::stereoCameraView() {
|
||||
// QWidget *w = new QWidget(this);
|
||||
// QVBoxLayout *l = new QVBoxLayout();
|
||||
// w->setLayout(l);
|
||||
// l->addWidget(orientation_combo);
|
||||
// }
|
||||
|
||||
|
||||
void CamConfigurator::modeChanged(int idx) {
|
||||
stack->setCurrentIndex(idx);
|
||||
orientation_combo->setEnabled(idx == 1);
|
||||
}
|
||||
|
||||
void CamConfigurator::primaryDeviceChanged(int idx) {
|
||||
std::cerr << idx << std::endl;
|
||||
if (stack->currentIndex() == 0) { // single camera setting
|
||||
QString devicename = device_combo->currentText();
|
||||
singleCamPreview->updateCamera(devicename);
|
||||
}
|
||||
}
|
||||
|
||||
CamConfigurator::~CamConfigurator()
|
||||
{
|
||||
delete singleCamPreview;
|
||||
}
|
||||
// void OptionsDialog::file_opened(QString filename)
|
||||
// {
|
||||
// QObject::connect(this, SLOT(file_opened(QString)), ui->widget, SLOT(file_opened(QString)));
|
||||
// }
|
46
camconfig.h
Normal file
46
camconfig.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef CAMCONFIG_H
|
||||
#define CAMCONFIG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QComboBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QStackedWidget>
|
||||
#include <QGridLayout>
|
||||
#include <pylon/PylonIncludes.h>
|
||||
|
||||
#include "camerapreview.h"
|
||||
|
||||
namespace Ui {
|
||||
class CamConfigurator;
|
||||
}
|
||||
|
||||
class CamConfigurator : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CamConfigurator(Pylon::DeviceInfoList_t &deviceList, QWidget *parent = 0);
|
||||
~CamConfigurator();
|
||||
|
||||
public slots:
|
||||
void modeChanged(int idx);
|
||||
void primaryDeviceChanged(int idx);
|
||||
|
||||
// signals:
|
||||
// void column_visibility_changed(QString who, QString column, bool state);
|
||||
// void recent_file_changed(QStringList);
|
||||
|
||||
private:
|
||||
Pylon::DeviceInfoList_t deviceList;
|
||||
QComboBox *mode_combo, *device_combo, *orientation_combo;
|
||||
QStackedWidget *stack;
|
||||
QDialogButtonBox *buttonbox;
|
||||
|
||||
CameraPreview *singleCamPreview;
|
||||
|
||||
QWidget* singleCameraView();
|
||||
//void stereoCameraView();
|
||||
};
|
||||
|
||||
#endif // CAMCONFIG_H
|
140
camerapreview.cpp
Normal file
140
camerapreview.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
#include "camerapreview.h"
|
||||
#include <QMessageBox>
|
||||
#include <math.h>
|
||||
|
||||
CameraPreview::CameraPreview(QString &devicename, QWidget *parent):cameraname(devicename), QWidget(parent), camera(nullptr) {
|
||||
QLabel *label = new QLabel(cameraname);
|
||||
this->setLayout(new QVBoxLayout(this));
|
||||
this->layout()->addWidget(label);
|
||||
imgLabel = new QLabel(this);
|
||||
imgLabel->setMinimumSize(QSize(1024, 768));
|
||||
this->layout()->addWidget(imgLabel);
|
||||
QWidget *controls = new QWidget(this);
|
||||
|
||||
width = new QSpinBox(controls);
|
||||
width->setMinimum(1);
|
||||
width->setMaximum(2048);
|
||||
width->setValue(width->maximum());
|
||||
connect(width, SIGNAL(textChanged(QString)), SLOT(updateROI(QString)));
|
||||
|
||||
height = new QSpinBox(controls);
|
||||
height->setMinimum(1);
|
||||
height->setMaximum(1536);
|
||||
height->setValue(height->maximum());
|
||||
connect(height, SIGNAL(textChanged(QString)), SLOT(updateROI(QString)));
|
||||
|
||||
xoffs = new QSpinBox(controls);
|
||||
xoffs->setMinimum(0);
|
||||
xoffs->setMaximum(2047);
|
||||
xoffs->setValue(0);
|
||||
connect(xoffs, SIGNAL(textChanged(QString)), SLOT(updateROI(QString)));
|
||||
|
||||
yoffs = new QSpinBox(controls);
|
||||
yoffs->setMinimum(0);
|
||||
yoffs->setMaximum(1535);
|
||||
yoffs->setValue(0);
|
||||
connect(yoffs, SIGNAL(textChanged(QString)), SLOT(updateROI(QString)));
|
||||
|
||||
QGridLayout *grid = new QGridLayout(controls);
|
||||
grid->addWidget(new QLabel("width", controls), 0, 0);
|
||||
grid->addWidget(width, 0, 1);
|
||||
|
||||
grid->addWidget(new QLabel("height", controls), 1, 0);
|
||||
grid->addWidget(height, 1, 1);
|
||||
|
||||
grid->addWidget(new QLabel("x-offset", controls), 0, 2);
|
||||
grid->addWidget(xoffs, 0, 3);
|
||||
|
||||
grid->addWidget(new QLabel("y-offset", controls), 1, 2);
|
||||
grid->addWidget(yoffs, 1, 3);
|
||||
controls->setLayout(grid);
|
||||
this->layout()->addWidget(controls);
|
||||
updateCamera(devicename);
|
||||
takeStill();
|
||||
}
|
||||
|
||||
void CameraPreview::updateCamera(QString &device){
|
||||
std::cerr << "update camera! " << device.toStdString() << std::endl;
|
||||
cameraname = device;
|
||||
|
||||
if (camera != NULL) {
|
||||
std::cerr << "camera is not nullptr! " << std::endl;
|
||||
delete camera;
|
||||
}
|
||||
camera = new PylonWrapper(cameraname.toStdString());
|
||||
std::string message;
|
||||
bool success = camera->openCamera(message);
|
||||
if (!success) {
|
||||
QMessageBox msgBox;
|
||||
QString msg = "<p><b>Could not open camera device!</b><p><p>" + QString::fromStdString(message) + "</p>";
|
||||
msgBox.setText(msg);
|
||||
msgBox.exec();
|
||||
}
|
||||
takeStill();
|
||||
}
|
||||
|
||||
|
||||
void CameraPreview::takeStill() {
|
||||
if (camera->isOpen()) {
|
||||
MyImage mimg;
|
||||
bool valid = camera->grabFrame(mimg);
|
||||
if (!valid) {
|
||||
std::cerr << "Grabbing from camera failed!" << std::endl;
|
||||
return;
|
||||
}
|
||||
QImage img(static_cast<uchar *>(mimg.data()), mimg.width(), mimg.height(),
|
||||
QImage::Format::Format_Grayscale8);
|
||||
|
||||
// QPixmap img("/home/grewe/projects/programming/pylon-recorder/test.png");
|
||||
QPixmap mpm = QPixmap::fromImage(img);
|
||||
this->pm = mpm;
|
||||
mpm = mpm.scaledToWidth(1024);
|
||||
setImage(mpm);
|
||||
updateROI("");
|
||||
} else {
|
||||
std::cerr << "Camera is not open! Connect to camera first!" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CameraPreview::setImage(const QPixmap &img) {
|
||||
imgLabel->setPixmap(img);
|
||||
}
|
||||
|
||||
void CameraPreview::updateROI(QString v){
|
||||
QImage img = pm.toImage();
|
||||
double scaling = 1024.0 / img.width();
|
||||
img = img.scaledToWidth(1024);
|
||||
QPainter qPainter(&img);
|
||||
qPainter.setBrush(Qt::NoBrush);
|
||||
qPainter.setPen(Qt::red);
|
||||
QPen p = qPainter.pen();
|
||||
p.setWidthF(1.5);
|
||||
qPainter.setPen(p);
|
||||
int x = xoffs->value();
|
||||
int rxoffs = round(xoffs->value() * scaling);
|
||||
int ryoffs = round(yoffs->value() * scaling);
|
||||
int rwidth = round(width->value() * scaling);
|
||||
int rheight = round(height->value() * scaling);
|
||||
qPainter.drawRect(rxoffs, ryoffs, rwidth, rheight);
|
||||
bool bEnd = qPainter.end();
|
||||
|
||||
QPixmap npm = QPixmap::fromImage(img);
|
||||
setImage(npm);
|
||||
}
|
||||
// FIXME at some point i need to check that xoffset + width must not exceed image width
|
||||
// FIXME same for y offset and height
|
||||
// FIXME initialize the cameras
|
||||
|
||||
CameraPreview::~CameraPreview(){
|
||||
std::cerr << "cameraPreview destructor" << std::endl;
|
||||
if (camera != nullptr){
|
||||
std::cerr << "close camera" << std::endl;
|
||||
// camera->closeCamera();
|
||||
std::cerr << "call terminate" << std::endl;
|
||||
// camera->terminate();
|
||||
}
|
||||
delete camera;
|
||||
std::cerr << "preview: deleted camera" << std::endl;
|
||||
|
||||
}
|
50
camerapreview.h
Normal file
50
camerapreview.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef CAMPREVIEW_H
|
||||
#define CAMPREVIEW_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QStackedWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QSpinBox>
|
||||
#include <QPainter>
|
||||
#include <pylon/PylonIncludes.h>
|
||||
|
||||
#include "pylonwrapper.h"
|
||||
|
||||
namespace Ui {
|
||||
class CameraPreview;
|
||||
}
|
||||
|
||||
class CameraPreview : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CameraPreview(QString &devicename, QWidget *parent = 0);
|
||||
~CameraPreview();
|
||||
|
||||
public slots:
|
||||
void updateCamera(QString &device);
|
||||
void updateROI(QString v);
|
||||
|
||||
// signals:
|
||||
// void column_visibility_changed(QString who, QString column, bool state);
|
||||
// void recent_file_changed(QStringList);
|
||||
|
||||
private:
|
||||
QString cameraname;
|
||||
QSpinBox *width, *height, *xoffs, *yoffs;
|
||||
QLabel *imgLabel;
|
||||
QPixmap pm;
|
||||
|
||||
void takeStill();
|
||||
void setImage(const QPixmap &img);
|
||||
// void setImage(const QImage &img);
|
||||
PylonWrapper *camera;
|
||||
|
||||
};
|
||||
|
||||
#endif // CAMPREVIEW_H
|
Loading…
Reference in New Issue
Block a user