Skip to content

Commit

Permalink
SE-1773 (#37)
Browse files Browse the repository at this point in the history
* SE-1773 added filemaneger
  • Loading branch information
guy-martin authored Jul 18, 2024
1 parent 89ec71d commit 2b2d050
Show file tree
Hide file tree
Showing 18 changed files with 1,142 additions and 194 deletions.
6 changes: 6 additions & 0 deletions stereo_viewer/bundle.bat
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ FOR %%M IN (
Gui
Widgets
OpenGL
Network
Concurrent
) DO (
COPY /Y %QTHOME%\bin\QT5%%M.dll %~dp0\install\bin
IF %ERRORLEVEL% NEQ 0 goto :exit_with_error
Expand Down Expand Up @@ -83,6 +85,10 @@ FOR %%M IN (
echo "Past %OPENCVHOME%\bin\%%M*.dll"
)

:: COPY YamlCPP
copy /Y %~dp0\install\lib\yaml_cpp.dll %~dp0\install\bin
ECHO "YamlCPP copied"

:: COPY Pleora SDK Files
copy /Y "C:\Program Files\Common Files\Pleora\eBUS SDK\GenICam\bin\Win64_x64\*.dll" ^
%~dp0\install\bin
Expand Down
2 changes: 1 addition & 1 deletion stereo_viewer/env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CALL "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\B

:: QT5
IF NOT DEFINED QTHOME (
SET QTHOME=C:\qt5
SET QTHOME=C:\Qt\5.15.2\msvc2015_64
)
IF NOT EXIST %QTHOME% (
ECHO QT5 not properly installed ... exiting
Expand Down
30 changes: 17 additions & 13 deletions stereo_viewer/inc/gev/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,32 @@
#include "inc/bottlenose_chunk_parser.hpp"
namespace labforge::gev {

struct BNImageData{
cv::Mat* left;
cv::Mat* right;
uint64_t timestamp;
int32_t min_disparity;
pointcloud_t pc;
};

class Pipeline : public QThread {
Q_OBJECT

public:
Pipeline(PvStreamGEV *stream_gev, PvDeviceGEV*device_gev, QObject*parent = nullptr);

virtual ~Pipeline();
bool Start(bool calibrate);
bool Start(bool calibrate, bool stereo);
void Stop();
bool IsStarted() { return m_start_flag; }
size_t GetPairs(std::list<std::tuple<cv::Mat*, cv::Mat*, uint64_t, int32_t, pointcloud_t>> &out);
size_t GetPairs(std::list<BNImageData> &out);
void run() override;

Q_SIGNALS:
void pairReceived(bool is_disparity);
void monoReceived(bool is_disparity);
void pairReceived();
void monoReceived();
void terminated(bool fatal = false);
void onError(QString msg);
void onError(const QString &msg);
void timeout();

private:
Expand All @@ -62,19 +70,15 @@ namespace labforge::gev {
PvGenCommand *m_stop;
PvGenFloat *m_fps;
PvGenFloat *m_bandwidth;
PvGenEnum* m_pixformat;
PvGenBoolean *m_rectify;
PvGenBoolean *m_undistort;
PvGenInteger *m_mindisparity;

bool m_rectify_init;
bool m_undistort_init;
PvString m_pixfmt_init;

std::list<PvBuffer*> m_buffers;
QQueue<std::tuple<cv::Mat*, cv::Mat*, uint64_t , int32_t, pointcloud_t>> m_images;
QQueue<BNImageData> m_images;
volatile bool m_start_flag;
QMutex m_image_lock;

void enterCalibrationMode(bool enable, bool stereo);

};
}

Expand Down
5 changes: 5 additions & 0 deletions stereo_viewer/inc/io/calib.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <QString>
#include <map>

bool loadCalibration(const QString &filePath,
std::map<QString, double> &kp);
20 changes: 17 additions & 3 deletions stereo_viewer/inc/io/data_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QWaitCondition>
#include <cstdint>
#include <QVector>
#include <QPair>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include "inc/bottlenose_chunk_parser.hpp"
Expand All @@ -33,6 +34,15 @@
#define __IO_DATA_THREAD_HPP__

namespace labforge::io {
enum ImageDataType {
IMTYPE_IO, ///< single image
IMTYPE_DO, ///< disparity alone
IMTYPE_LR, ///< left+right images
IMTYPE_LD, ///< left+disparity images
IMTYPE_DR, ///< disparity+right images
IMTYPE_DC, ///< disparity+confidence images
};

struct ImageData
{
uint64_t timestamp;
Expand All @@ -42,8 +52,10 @@ struct ImageData
cv::Mat disparity;
int32_t min_disparity;
pointcloud_t pc;
ImageDataType imtype;
};


class DataThread : public QThread
{
Q_OBJECT
Expand All @@ -55,7 +67,8 @@ class DataThread : public QThread
void process(uint64_t timestamp, const QImage &left,
const QImage &right, QString format,
const uint16_t *raw, int32_t,
pointcloud_t &pc);
const pointcloud_t &pc);
void setImageDataType(ImageDataType imtype);
bool setFolder(QString new_folder);
void setStereoDisparity(bool is_stereo, bool is_disparity);
void stop();
Expand All @@ -82,10 +95,11 @@ class DataThread : public QThread
QString m_left_fname;
QString m_right_fname;
QString m_disparity_fname;
QString m_conf_fname;
QString m_pc_fname;
bool m_stereo;

bool m_abort;
bool m_disparity;
ImageDataType m_imtype;
cv::Mat m_matQ;
};
}
Expand Down
73 changes: 73 additions & 0 deletions stereo_viewer/inc/io/file_uploader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/******************************************************************************
* Copyright 2024 Labforge Inc. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this project except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************
@file file_uploader.hpp File Uploader Header
@author Martin Tchamgoue <[email protected]>
*/
#include <QString>
#include <PvDeviceGEV.h>
#include <cstdint>
#include <QObject>
#include <QNetworkAccessManager>
#include <memory>
#include <QFile>

#ifndef _IO_FILE_UPLOADER_HPP_
#define _IO_FILE_UPLOADER_HPP_

namespace labforge::io {
class FileUploader : public QObject
{
Q_OBJECT
public:
FileUploader(PvDeviceGEV *device_gev,
QObject *parent = nullptr);
~FileUploader();
void process(const QString &fid, const QString &ftype, const QString &fname);

signals:
void error(const QString &);
void finished(bool);
void progress(int);
void workingOn(const QString&);

private slots:
void onRequestFinished(QNetworkReply *reply);
void onUploadProgress(qint64 bytesSent, qint64 bytesTotal);

private:
QString m_ftype;
PvGenString *m_status;
PvGenBoolean *m_flag;
bool m_reset_flag;
PvDeviceGEV *m_device;
std::unique_ptr<QNetworkAccessManager> m_network;
QFile m_file;

bool setRegister(QString regname, double regvalue);
uint32_t getNumCameras();
void uploadCalibration(uint32_t expected_cam, const QString &fname);

void emitError(QString err);

bool attemptConnect(uint32_t, QString&);
void transferFile(const QString &fname);
void monitorTransfer();

};
}

#endif // _IO_FILE_UPLOADER_HPP_
22 changes: 17 additions & 5 deletions stereo_viewer/inc/ui/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
#include <PvDevice.h>
#include <PvStreamGEV.h>
#include <chrono>
#include <QProgressDialog>
#include <QPair>
#include <QtWidgets>

#include "ui_stereo_viewer.h"
#include "gev/pipeline.hpp"
#include "io/data_thread.hpp"
#include "gev/calib_params.hpp"
#include "io/file_uploader.hpp"
#include <cstdint>

class PvGenBrowserWnd;
Expand All @@ -51,21 +55,26 @@ public Q_SLOTS:
void handleConnect();
void handleDisconnect();
void handleRecording();
void handleStereoData(bool is_disparity);
void handleMonoData(bool is_disparity);
void handleError(QString msg);
void newData(uint64_t timestamp, QImage &left, QImage &right, bool stereo,
bool disparity, uint16_t *raw_disparity, int32_t min_disparity, pointcloud_t &pc);
void handleStereoData();
void handleMonoData();
void handleError(const QString &msg);
void newData(uint64_t timestamp, QImage &left, QImage &right, QPair<QString, QString> &label,
bool disparity, uint16_t *raw_disparity, int32_t min_disparity, const pointcloud_t &pc);
void onFolderSelect();
void handleSave();
void handleFocus();
void handleDeviceControl();
void setRuler(int value);
void handleTimeOut();
void handleUpload();
void onFileTransferSelect();
void handleFileUploadError(QString msg);
void handleFileUploadFinished(bool);

protected:
void ShowGenWindow( PvGenBrowserWnd *aWnd, PvGenParameterArray *aArray, const QString &aTitle );
void CloseGenWindow( PvGenBrowserWnd *aWnd );
bool eventFilter(QObject *obj, QEvent *event) override;

private:
bool connectGEV(const PvDeviceInfo *info);
Expand Down Expand Up @@ -93,6 +102,9 @@ public Q_SLOTS:
void resetStatusCounters();

labforge::gev::CalibParams m_calib;

std::unique_ptr<labforge::io::FileUploader> m_uploader;
QProgressDialog *m_upbar;
};

}
Expand Down
26 changes: 25 additions & 1 deletion stereo_viewer/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ app_inc = include_directories(
cpp = meson.get_compiler('cpp')
# set PATH=C:\qt5\bin;%PATH%
qt5 = import('qt5')
qt5_deps = dependency('qt5', modules: ['Core', 'Gui', 'Widgets', 'Test', 'Network'], main: true)
qt5_deps = dependency('qt5', modules: ['Core', 'Gui', 'Widgets', 'Test', 'Network', 'Concurrent'], main: true)

opencv_dep = dependency('opencv4', required: false)
if not opencv_dep.found()
cv_dir = get_option('cv_dir')
Expand Down Expand Up @@ -104,11 +105,34 @@ pleora_dep = declare_dependency(compile_args: pleora_inc,
compile_args: pleora_args
)

# json
nlohmann_json_dep = dependency('nlohmann_json', fallback : ['nlohmann_json', 'nlohmann_json_dep'])

# yaml-cppnau
yamlcpp_dep = dependency('yaml-cpp', version: '>= 0.6.1', required: false)
if not yamlcpp_dep.found()
yamlcmake = import('cmake')
shared = 'OFF'
if host_machine.system() == 'windows'
shared = 'ON'
endif
yamlcpp_dep = yamlcmake.subproject('yaml-cpp', cmake_options: [
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
'-DYAML_CPP_BUILD_TOOLS=OFF',
'-DYAML_CPP_BUILD_TESTS=OFF',
'-DYAML_CPP_BUILD_CONTRIB=OFF',
'-DBUILD_SHARED_LIBS=' + shared
]).dependency('yaml-cpp')
endif

# Lump together all monolithic dependencies from above
app_deps = [
qt5_deps,
opencv_dep,
pleora_dep,
nlohmann_json_dep,
yamlcpp_dep
]

subdir('src')
Loading

0 comments on commit 2b2d050

Please sign in to comment.