Skip to content
Snippets Groups Projects
Commit 2abf26d1 authored by simon.fanetti's avatar simon.fanetti
Browse files

add GUI to setup the resolution of projection

parent e0079671
No related branches found
No related tags found
No related merge requests found
include src/common.mk
include dep.mk
OBJSALL=$(shell find src -name '*.o')
LIBNAME=libsandbox
LIB_MINOR_VERS=0.0
LIB_MAJOR_VERS=1
LIB_VERS=$(LIB_MAJOR_VERS).$(LIB_MINOR_VERS)
LIB_FULL_NAME=$(LIBNAME).so.$(LIB_VERS)
all:
$(MAKE) -C src
$(MAKE) pack -C .
$(MAKE) link -C .
$(MAKE) -C build
$(MAKE) -C app
pack:
gcc -shared -Wl,-soname,$(LIB_FULL_NAME) -o $(LIB_FULL_NAME) $(OBJSALL)
link:
-ln -s $(LIB_FULL_NAME) $(LIBNAME).so.$(LIB_MAJOR_VERS)
-ln -s $(LIB_FULL_NAME) $(LIBNAME).so
clean:
-rm -f *.o *.so*
-rm $(SETUPAPP)
$(MAKE) clean -C src
$(MAKE) clean -C app
$(MAKE) clean -C build
......@@ -4,6 +4,6 @@
- LD_LIBRARY_PATH must contain dir's path to libsandbox.so
- Enter this command in the terminal where you are using your application
```
REALTIVE_PATH_TO_SO=../ar_sandbox_lib && \
REALTIVE_PATH_TO_SO=../ar_sandbox_lib/build && \
export LD_LIBRARY_PATH=$(pwd)/$REALTIVE_PATH_TO_SO
```
include ../src/common.mk
include ../dep.mk
SETUPAPP=SandboxSetupApp
LIB_PATH=..
app: $(SETUPAPP).o
g++ $< -o $(SETUPAPP) -L$(LIB_PATH) -lsandbox $(DEP_SANDBOX)
$(SETUPAPP).o: $(SETUPAPP).cpp
$(CCP) $(CFLAGS) -I$(LIB_PATH)/inc -c $< -o $@
all:
$(shell cd SandboxSetup && qmake *.pro)
$(MAKE) -C SandboxSetup
clean:
-rm -f *.o
-rm $(SETUPAPP)
$(MAKE) distclean -C SandboxSetup
#-------------------------------------------------
#
# Project created by QtCreator 2020-05-13T17:30:24
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SandboxSetup
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
INCLUDEPATH += ../../inc
LIBS += -L"../../build" -lsandbox -lrealsense2 -lyaml-cpp
LIBS += $(shell pkg-config --libs --cflags opencv)
#include "../inc/sandboxSetup.h"
#include "mainwindow.h"
#include <QApplication>
#include <sandboxSetup.h>
int main(int argc, char *argv[])
{
int main(){
SandboxSetup setup;
if(setup.setupBeamerResolution()){
std::cout << "Invalide resolution" << std::endl;
QApplication a(argc, argv);
MainWindow w;
w.show();
a.exec();
setup.setBeamerResolution(cv::Size(w.getWidth(), w.getHeight()));
if(w.getWidth()==0 || w.getHeight()==0){
std::cout << "Cancel Resolution" << std::endl;
return 1;
}
if(setup.setupProjection()){
std::cout << "Cancel calibration" << std::endl;
return 1;
}
if(setup.setupBeamerLocation()){
std::cout << "Cancel calibration" << std::endl;
return 1;
......@@ -23,6 +32,7 @@ int main(){
std::cout << "Failed to save configuration" << std::endl;
return 1;
}
return 0;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
std::string path = ".monitors.tmp";
monitors = std::map<std::string, std::vector<std::string>>();
// Save in file the monitors and their resolutions
system( ("xrandr -d :0 | sed -n '1!p' > " + path).c_str() );
loadResolutionsFromFile(path);
QList<QScreen*> screens = QApplication::screens();
for(int i=0; i<screens.size(); i++){
QScreen* sc = screens[i];
ui->cbxOutputs->addItem( sc->name() );
}
if(screens.size() > 0){
loadResolutionsOf(screens[0]);
}
std::remove(path.c_str());
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_cbxOutputs_currentIndexChanged(int index){
QList<QScreen*> screens = QApplication::screens();
loadResolutionsOf(screens[index]);
}
// load resolutions into GUI
void MainWindow::loadResolutionsOf(QScreen* sc){
ui->cbxResolutions->clear();
const char *key = sc->name().toStdString().c_str();
std::vector<std::string> resolutions = monitors[key];
for(int i=0; i<resolutions.size(); i++){
std::vector<std::string> res = splitResolution(resolutions[i]);
ui->cbxResolutions->addItem( QString::fromStdString(res[0] + "x" + res[1]) );
}
}
// Get height and width from the string "_width_x_height_"
// http://www.martinbroadhurst.com/how-to-split-a-string-in-c.html
std::vector<std::string> MainWindow::splitResolution(std::string s){
char delim = 'x';
std::vector<std::string> res;
std::stringstream ss(s);
std::string token;
while (std::getline(ss, token, delim)) {
res.push_back(token);
}
return res;
}
bool MainWindow::isResolution(std::string s){
return splitResolution(s).size() == 2;
}
void MainWindow::loadResolutionsFromFile(std::string path){
// Get monitors and their resolutions into a Map
std::ifstream infile(path);
std::string line;
std::string key;
while (std::getline(infile, line)){
std::istringstream iss(line);
std::string l;
iss >> l;
if(!isResolution(l)){
key = l;
monitors[key] = std::vector<std::string>();
}else{
monitors[key].push_back(l);
}
}
}
void MainWindow::on_btnOutputs_clicked()
{
QString selectedRes = ui->cbxResolutions->currentText();
std::vector<std::string> res = splitResolution(selectedRes.toStdString());
width = std::stoi(res[0]);
height = std::stoi(res[1]);
this->close();
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets>
#include <string>
#include <sstream>
#include <vector>
#include <fstream>
#include <map>
#include <iostream>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
int getHeight(){ return height; }
int getWidth(){ return width; }
private slots:
void on_cbxOutputs_currentIndexChanged(int index);
void on_btnOutputs_clicked();
private:
Ui::MainWindow *ui;
int height = 0;
int width = 0;
std::map<std::string, std::vector<std::string>> monitors;
void loadResolutionsOf(QScreen* screen);
std::vector<std::string> splitResolution(std::string s);
bool isResolution(std::string s);
void loadResolutionsFromFile(std::string path);
};
#endif // MAINWINDOW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QComboBox" name="cbxOutputs">
<property name="geometry">
<rect>
<x>50</x>
<y>40</y>
<width>141</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QComboBox" name="cbxResolutions">
<property name="geometry">
<rect>
<x>50</x>
<y>130</y>
<width>181</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="btnOutputs">
<property name="geometry">
<rect>
<x>270</x>
<y>180</y>
<width>89</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Valide</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>101</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Choose output</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>131</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Choose resolution</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
OBJSALL=$(shell find ../src -name '*.o')
LIBNAME=libsandbox
LIB_MINOR_VERS=0.0
LIB_MAJOR_VERS=1
LIB_VERS=$(LIB_MAJOR_VERS).$(LIB_MINOR_VERS)
LIB_FULL_NAME=$(LIBNAME).so.$(LIB_VERS)
all:
$(MAKE) pack
$(MAKE) link
pack:
gcc -shared -Wl,-soname,$(LIB_FULL_NAME) -o $(LIB_FULL_NAME) $(OBJSALL)
link:
-ln -s $(LIB_FULL_NAME) $(LIBNAME).so.$(LIB_MAJOR_VERS)
-ln -s $(LIB_FULL_NAME) $(LIBNAME).so
clean:
-rm -f *.so*
......@@ -5,7 +5,6 @@
#include "camera.h"
#include "beamerProjection.h"
#include "beamer.h"
#include "borderedit.h"
#include "sandboxConfig.h"
class Sandbox{
......
......@@ -2,7 +2,6 @@
#define SANDBOXSETUP_H
#include <opencv2/opencv.hpp>
#include <cstdlib>
#include "beamer.h"
#include "beamerProjection.h"
#include "camera.h"
......@@ -22,11 +21,20 @@ class SandboxSetup{
public:
SandboxSetup();
// save config in file => persistant
int saveConfigFrom(char *path);
int saveConfig();
// edit variables of config => not persistant
int setupProjection();
int setupBeamerResolution();
int setupBeamerLocation();
void setBeamerResolution(cv::Size resolution);
void setBeamerPosition(cv::Point3f pos);
void setCroppingMask(cv::Rect mask);
void setAdjustingMatrix(cv::Mat matrix);
};
#endif
#ifndef SANDBOX_H
#define SANDBOX_H
#include <opencv2/opencv.hpp>
#include "camera.h"
#include "beamerProjection.h"
#include "beamer.h"
#include "borderedit.h"
#include "sandboxConfig.h"
class Sandbox{
private:
char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml";
char *defaultWindowsName = (char*) "ShowApp";
BeamerProjection projection;
Camera camera;
Beamer beamer;
void initWindowsFullScreen(char *windowName);
void showImage(cv::Mat* image, char *windowName);
public:
Sandbox();
cv::Mat getRGBFrame();
cv::Mat getDepthFrame();
cv::Mat* adjustProjection(cv::Mat* frame);
void showImage(cv::Mat* image);
int loadConfig();
int loadConfigFrom(char *path);
void initWindowsFullScreen();
};
#endif
......@@ -5,6 +5,23 @@ SandboxSetup::SandboxSetup(){
}
void SandboxSetup::setBeamerResolution(cv::Size resolution){
beamer.setHeight(resolution.height);
beamer.setWidth(resolution.width);
}
void SandboxSetup::setBeamerPosition(cv::Point3f pos){
beamer.setPosition(pos);
}
void SandboxSetup::setCroppingMask(cv::Rect mask){
camera.setCroppingMask(mask);
}
void SandboxSetup::setAdjustingMatrix(cv::Mat matrix){
projection.setAdjustingMatrix(matrix);
}
// return 1 when config can't be saved in file
int SandboxSetup::saveConfigFrom(char *path){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment