diff --git a/Calibration/mainwindow.cpp b/Calibration/mainwindow.cpp index 265d8a094a5246c16cd5083bace6278459fe2cb1..0e097b0a4e55c011ecd4a5933112e741d4430e26 100644 --- a/Calibration/mainwindow.cpp +++ b/Calibration/mainwindow.cpp @@ -73,7 +73,7 @@ void MainWindow::selectRealSenseDevice(QListWidgetItem* item) { void MainWindow::searchRealSenseDevices() { listRealSenseDevices = sandbox.getListRealSenseDevices(); // Get a snapshot of currently connected devices if (listRealSenseDevices.size() == 0){ - pteConsole_cursor.insertText("No device detected. Is it plugged in?"); + pteConsole_cursor.insertText("No device detected. Is it plugged in?\n"); } else { pteConsole_cursor.insertText("Device detected\n"); showListRealSenseDevices(); @@ -87,5 +87,16 @@ void MainWindow::reloadListRealSenseDevices() { } void MainWindow::saveConfiguration() { - sandbox.saveConfiguration(); + std::ofstream out("./device"); + + pteConsole_cursor.insertText("Serialize\n"); + sandbox.serialize(out); + pteConsole_cursor.insertText("Serialized\n"); + out.close(); + std::ifstream in("./device"); + pteConsole_cursor.insertText("Deserialized\n"); + pteConsole_cursor.insertText(sandbox.deserialize(in).c_str()); + pteConsole_cursor.insertText("Deserialized\n"); + in.close(); + reloadListRealSenseDevices(); } diff --git a/Calibration/mainwindow.h b/Calibration/mainwindow.h index 27d61da471d98c59f56467ae536bb07f96d2186e..2634b4bf90fee1e0448b07813d2941fbde4474d7 100644 --- a/Calibration/mainwindow.h +++ b/Calibration/mainwindow.h @@ -8,6 +8,8 @@ #include <QTextCursor> #include <QListWidgetItem> #include "sandbox.h" +#include <string> +#include <iostream> using namespace std; @@ -34,11 +36,11 @@ private: // Methods void showListRealSenseDevices(); void searchRealSenseDevices(); - void saveConfiguration(); private slots: void quitApplication(); void selectRealSenseDevice(QListWidgetItem*); void reloadListRealSenseDevices(); + void saveConfiguration(); }; #endif // MAINWINDOW_H diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Calibration b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Calibration index 62e70126c5c5c05c810d57599141cd44acd5cc67..3933b597bafee1e251a8c92f47e29580b7240e49 100755 Binary files a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Calibration and b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Calibration differ diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile index 58ac5a560b5e0980ab9a42bdbe9fbe1eb12896bf..8e751ef0670acfd5ffd6c8324b34595f881a2f9b 100644 --- a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile +++ b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile @@ -892,6 +892,7 @@ moc_mainwindow.cpp: ../Calibration/mainwindow.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qtabbar.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qrubberband.h \ ../sandbox/sandbox.h \ + ../sandbox/serializable.h \ moc_predefs.h \ ../../../../Qt/5.14.1/gcc_64/bin/moc /home/fabien/Qt/5.14.1/gcc_64/bin/moc $(DEFINES) --include /home/fabien/Desktop/pa/sandboxrefactorconfig/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_predefs.h -I/home/fabien/Qt/5.14.1/gcc_64/mkspecs/linux-g++ -I/home/fabien/Desktop/pa/sandboxrefactorconfig/Calibration -I/home/fabien/Desktop/pa/sandboxrefactorconfig/sandbox -I/home/fabien/Qt/5.14.1/gcc_64/include -I/home/fabien/Qt/5.14.1/gcc_64/include/QtWidgets -I/home/fabien/Qt/5.14.1/gcc_64/include/QtGui -I/home/fabien/Qt/5.14.1/gcc_64/include/QtCore -I. -I/usr/include/c++/5 -I/usr/include/x86_64-linux-gnu/c++/5 -I/usr/include/c++/5/backward -I/usr/lib/gcc/x86_64-linux-gnu/5/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed -I/usr/include/x86_64-linux-gnu -I/usr/include ../Calibration/mainwindow.h -o moc_mainwindow.cpp @@ -1050,6 +1051,7 @@ main.o: ../Calibration/main.cpp ../Calibration/mainwindow.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qtabbar.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qrubberband.h \ ../sandbox/sandbox.h \ + ../sandbox/serializable.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/QApplication \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qapplication.h \ ../../../../Qt/5.14.1/gcc_64/include/QtCore/qcoreapplication.h \ @@ -1192,6 +1194,7 @@ mainwindow.o: ../Calibration/mainwindow.cpp ../Calibration/mainwindow.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qtabbar.h \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/qrubberband.h \ ../sandbox/sandbox.h \ + ../sandbox/serializable.h \ ui_mainwindow.h \ ../../../../Qt/5.14.1/gcc_64/include/QtCore/QVariant \ ../../../../Qt/5.14.1/gcc_64/include/QtWidgets/QApplication \ diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/device b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/device new file mode 100644 index 0000000000000000000000000000000000000000..b8120bf67851c45898ceaef49b0c91f4aa555395 --- /dev/null +++ b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/device @@ -0,0 +1 @@ +840412061564 \ No newline at end of file diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/main.o b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/main.o index 69d82601b10f0cedfb9ceffe7980491335340697..b5b7af03dde0dc09ddad7f5919540707bce00617 100644 Binary files a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/main.o and b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/main.o differ diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/mainwindow.o b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/mainwindow.o index a24b426bf24cb637f45512fdf843f55d19727990..d93fe6141eafc8de054f6b15faead0a16365bdf7 100644 Binary files a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/mainwindow.o and b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/mainwindow.o differ diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.cpp b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.cpp index 54e3d5a8d1ef3719134d3b0847c16c7d50d34d99..a7d617ca6a803500050828daf4dd41d18896bbb5 100644 --- a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.cpp +++ b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.cpp @@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED struct qt_meta_stringdata_MainWindow_t { - QByteArrayData data[6]; - char stringdata0[94]; + QByteArrayData data[7]; + char stringdata0[112]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ @@ -37,12 +37,13 @@ QT_MOC_LITERAL(1, 11, 15), // "quitApplication" QT_MOC_LITERAL(2, 27, 0), // "" QT_MOC_LITERAL(3, 28, 21), // "selectRealSenseDevice" QT_MOC_LITERAL(4, 50, 16), // "QListWidgetItem*" -QT_MOC_LITERAL(5, 67, 26) // "reloadListRealSenseDevices" +QT_MOC_LITERAL(5, 67, 26), // "reloadListRealSenseDevices" +QT_MOC_LITERAL(6, 94, 17) // "saveConfiguration" }, "MainWindow\0quitApplication\0\0" "selectRealSenseDevice\0QListWidgetItem*\0" - "reloadListRealSenseDevices" + "reloadListRealSenseDevices\0saveConfiguration" }; #undef QT_MOC_LITERAL @@ -52,7 +53,7 @@ static const uint qt_meta_data_MainWindow[] = { 8, // revision 0, // classname 0, 0, // classinfo - 3, 14, // methods + 4, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -60,13 +61,15 @@ static const uint qt_meta_data_MainWindow[] = { 0, // signalCount // slots: name, argc, parameters, tag, flags - 1, 0, 29, 2, 0x08 /* Private */, - 3, 1, 30, 2, 0x08 /* Private */, - 5, 0, 33, 2, 0x08 /* Private */, + 1, 0, 34, 2, 0x08 /* Private */, + 3, 1, 35, 2, 0x08 /* Private */, + 5, 0, 38, 2, 0x08 /* Private */, + 6, 0, 39, 2, 0x08 /* Private */, // slots: parameters QMetaType::Void, QMetaType::Void, 0x80000000 | 4, 2, + QMetaType::Void, QMetaType::Void, 0 // eod @@ -81,6 +84,7 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, case 0: _t->quitApplication(); break; case 1: _t->selectRealSenseDevice((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break; case 2: _t->reloadListRealSenseDevices(); break; + case 3: _t->saveConfiguration(); break; default: ; } } @@ -115,13 +119,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 3) + if (_id < 4) qt_static_metacall(this, _c, _id, _a); - _id -= 3; + _id -= 4; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { - if (_id < 3) + if (_id < 4) *reinterpret_cast<int*>(_a[0]) = -1; - _id -= 3; + _id -= 4; } return _id; } diff --git a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.o b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.o index eaf44988a0be101b89b25f4ccf484e3e8652d9ea..67aa54644218b09f9bffc54369473f2cf1647355 100644 Binary files a/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.o and b/build-Calibration-Desktop_Qt_5_14_1_GCC_64bit-Debug/moc_mainwindow.o differ diff --git a/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile b/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile index 0269aa990d94d9c391b0bb88eeb869753b5c1ef2..c84e2e39ed6921bbbca0e404748a296c22c7c00e 100644 --- a/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile +++ b/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/Makefile @@ -49,8 +49,10 @@ OBJECTS_DIR = ./ ####### Files -SOURCES = ../sandbox/sandbox.cpp -OBJECTS = sandbox.o +SOURCES = ../sandbox/camera.cpp \ + ../sandbox/sandbox.cpp +OBJECTS = camera.o \ + sandbox.o DIST = ../../../../Qt/5.14.1/gcc_64/mkspecs/features/spec_pre.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/common/unix.conf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/common/linux.conf \ @@ -241,6 +243,7 @@ DIST = ../../../../Qt/5.14.1/gcc_64/mkspecs/features/spec_pre.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/qt_config.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/linux-g++/qmake.conf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/spec_post.prf \ + ../sandbox/.qmake.stash \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/exclusive_builds.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/toolchain.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/default_pre.prf \ @@ -259,7 +262,10 @@ DIST = ../../../../Qt/5.14.1/gcc_64/mkspecs/features/spec_pre.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/exceptions.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/yacc.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/lex.prf \ - ../sandbox/sandbox.pro ../sandbox/sandbox.h ../sandbox/sandbox.cpp + ../sandbox/sandbox.pro ../sandbox/camera.h \ + ../sandbox/sandbox.h \ + ../sandbox/serializable.h ../sandbox/camera.cpp \ + ../sandbox/sandbox.cpp QMAKE_TARGET = sandbox DESTDIR = TARGET = libsandbox.a @@ -465,6 +471,7 @@ Makefile: ../sandbox/sandbox.pro ../../../../Qt/5.14.1/gcc_64/mkspecs/linux-g++/ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/qt_config.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/linux-g++/qmake.conf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/spec_post.prf \ + .qmake.stash \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/exclusive_builds.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/toolchain.prf \ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/default_pre.prf \ @@ -675,6 +682,7 @@ Makefile: ../sandbox/sandbox.pro ../../../../Qt/5.14.1/gcc_64/mkspecs/linux-g++/ ../../../../Qt/5.14.1/gcc_64/mkspecs/features/qt_config.prf: ../../../../Qt/5.14.1/gcc_64/mkspecs/linux-g++/qmake.conf: ../../../../Qt/5.14.1/gcc_64/mkspecs/features/spec_post.prf: +.qmake.stash: ../../../../Qt/5.14.1/gcc_64/mkspecs/features/exclusive_builds.prf: ../../../../Qt/5.14.1/gcc_64/mkspecs/features/toolchain.prf: ../../../../Qt/5.14.1/gcc_64/mkspecs/features/default_pre.prf: @@ -709,8 +717,8 @@ distdir: FORCE @test -d $(DISTDIR) || mkdir -p $(DISTDIR) $(COPY_FILE) --parents $(DIST) $(DISTDIR)/ $(COPY_FILE) --parents ../../../../Qt/5.14.1/gcc_64/mkspecs/features/data/dummy.cpp $(DISTDIR)/ - $(COPY_FILE) --parents ../sandbox/sandbox.h $(DISTDIR)/ - $(COPY_FILE) --parents ../sandbox/sandbox.cpp $(DISTDIR)/ + $(COPY_FILE) --parents ../sandbox/camera.h ../sandbox/sandbox.h ../sandbox/serializable.h $(DISTDIR)/ + $(COPY_FILE) --parents ../sandbox/camera.cpp ../sandbox/sandbox.cpp $(DISTDIR)/ clean: compiler_clean @@ -758,7 +766,11 @@ compiler_clean: compiler_moc_predefs_clean ####### Compile -sandbox.o: ../sandbox/sandbox.cpp ../sandbox/sandbox.h +camera.o: ../sandbox/camera.cpp ../sandbox/camera.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o camera.o ../sandbox/camera.cpp + +sandbox.o: ../sandbox/sandbox.cpp ../sandbox/sandbox.h \ + ../sandbox/serializable.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o sandbox.o ../sandbox/sandbox.cpp ####### Install diff --git a/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/libsandbox.a b/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/libsandbox.a index 7b07dfcedd59402b8909fd014bfcdb1d5b88481a..c37ce1422fb28d1f2251f8f62c3653e3a7eb1b6e 100644 Binary files a/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/libsandbox.a and b/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/libsandbox.a differ diff --git a/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/sandbox.o b/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/sandbox.o index aa229a4e36ebac4a75c6a12e81bac1b34323e06f..6ccc367f6439f084f8e1000821d5afde1d101b66 100644 Binary files a/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/sandbox.o and b/build-sandbox-Desktop_Qt_5_14_1_GCC_64bit-Debug/sandbox.o differ diff --git a/sandbox/camera.cpp b/sandbox/camera.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42f19910a20a2c12c2d9f86b3740d693cabd4c2a --- /dev/null +++ b/sandbox/camera.cpp @@ -0,0 +1,150 @@ +#include "camera.h" + +Camera::Camera() {} + +// Capture 30 frames to give autoexposure, etc. a chance to settle +void Camera::warmingUp() +{ + for (int i = 0; i < 30; ++i) + { + rs2::frameset data = pipe.wait_for_frames(); + auto frameDepth = data.get_depth_frame(); + //frameDepth = decFilter.process(frameDepth); + frameDepth = spatFilter.process(frameDepth); + frameDepth = tempFilter.process(frameDepth); + } +} + +Mat Camera::coloredFrame(Mat frameDepth) +{ + Mat depthFrameColored(frameDepth.size(), CV_8U); + int width = frameDepth.cols, height = frameDepth.rows; + static uint32_t histogram[0x10000]; + memset(histogram, 0, sizeof(histogram)); + + for (int i = 0; i < height; ++i) + { + for (int j = 0; j < width; ++j) + { + ++histogram[frameDepth.at<ushort>(i, j)]; + } + } + + for (int i = 2; i < 0x10000; ++i) + histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] + + for (int i = 0; i < height; ++i) + { + for (int j = 0; j < width; ++j) + { + if (uint16_t d = frameDepth.at<ushort>(i, j)) + { + int f = histogram[d] * 255 / histogram[0xFFFF]; // 0-255 based on histogram location + depthFrameColored.at<uchar>(i, j) = static_cast<uchar>(f); + } + else + { + depthFrameColored.at<uchar>(i, j) = 0; + } + } + } + bitwise_not(depthFrameColored, depthFrameColored); //reverse colormap + applyColorMap(depthFrameColored, depthFrameColored, cv::COLORMAP_JET); + depthFrameColored.setTo(cv::Scalar(0, 0, 0), (frameDepth == 0)); + return depthFrameColored; +} + +Mat Camera::captureFrame() +{ + auto frame = pipe.wait_for_frames(); + auto frameDepth = frame.get_depth_frame(); + filterDepthFrame(frameDepth); + Mat matFrame(Size(frameDepth.get_width(), frameDepth.get_height()), CV_16UC1, (void *)frameDepth.get_data(), Mat::AUTO_STEP); + return matFrame; +} +void Camera::captureFramesAlign() +{ + rs2::align align(RS2_STREAM_DEPTH); + auto frameset = pipe.wait_for_frames(); + //Get processed aligned frame + frameset = align.process(frameset); + // Trying to get color and aligned depth frames + rs2::video_frame color_frame = frameset.get_color_frame(); + rs2::depth_frame depth_frame = frameset.get_depth_frame(); + filterDepthFrame(depth_frame); + matDepth = Mat(Size(depth_frame.get_width(), depth_frame.get_height()), CV_16UC1, (void *)depth_frame.get_data(), Mat::AUTO_STEP); + Mat(Size(color_frame.get_width(), color_frame.get_height()), CV_8UC3, (void *)color_frame.get_data(), Mat::AUTO_STEP).copyTo(matRGB); +} + +void Camera::filterDepthFrame(rs2::depth_frame &frameDepth) +{ + // frameDepth = decFilter.process(frameDepth); + frameDepth = spatFilter.process(frameDepth); + frameDepth = tempFilter.process(frameDepth); + intrinsics = frameDepth.get_profile().as<rs2::video_stream_profile>().get_intrinsics(); +} +Mat Camera::getAverageFrame(int numberFrame) +{ + Mat averageFrame; + Camera::captureFrame().copyTo(averageFrame); + for (int i = 1; i <= numberFrame; i++) + { + averageFrame *= i; + add(averageFrame, Camera::captureFrame(), averageFrame); + averageFrame /= i + 1; + } + return averageFrame; +} + +Point3f Camera::deprojectPixelToPoint(float coord[], float z1) +{ + float p[3]; + rs2_deproject_pixel_to_point(p, &intrinsics, coord, z1); + return Point3f(p[0], p[1], p[2]); +} + +Point2i Camera::projectPointToPixel(Point3f point3D) +{ + float point[3] = {point3D.x, point3D.y, point3D.z}; + float pixel[2]; + rs2_project_point_to_pixel(pixel, &intrinsics, point); + return Point2i(pixel[0], pixel[1]); +} + +void Camera::start() +{ + rs2::log_to_console(RS2_LOG_SEVERITY_ERROR); + //spatFilter.set_option(RS2_OPTION_HOLES_FILL, 5); + profile = pipe.start(cfg); + auto sensor = profile.get_device().first<rs2::depth_sensor>(); + // TODO: At the moment the SDK does not offer a closed enum for D400 visual presets + // We do this to reduce the number of black pixels + // The hardware can perform hole-filling much better and much more power efficient then our software + auto range = sensor.get_option_range(RS2_OPTION_VISUAL_PRESET); + for (auto i = range.min; i < range.max; i += range.step) + if (std::string(sensor.get_option_value_description(RS2_OPTION_VISUAL_PRESET, i)) == "High Density") + sensor.set_option(RS2_OPTION_VISUAL_PRESET, i); + warmingUp(); +} + +void Camera::startAlign() +{ + rs2::log_to_console(RS2_LOG_SEVERITY_ERROR); + spatFilter.set_option(RS2_OPTION_HOLES_FILL, 5); + //cfg.enable_device_from_file("../input/flux/flux5.bag"); + profile = pipe.start(cfg); + auto sensor = profile.get_device().first<rs2::depth_sensor>(); + // TODO: At the moment the SDK does not offer a closed enum for D400 visual presets + // We do this to reduce the number of black pixels + // The hardware can perform hole-filling much better and much more power efficient then our software + auto range = sensor.get_option_range(RS2_OPTION_VISUAL_PRESET); + for (auto i = range.min; i < range.max; i += range.step) + if (std::string(sensor.get_option_value_description(RS2_OPTION_VISUAL_PRESET, i)) == "High Density") + sensor.set_option(RS2_OPTION_VISUAL_PRESET, i); + warmingUp(); +} + +void Camera::stop() +{ + pipe.stop(); +} diff --git a/sandbox/camera.h b/sandbox/camera.h new file mode 100644 index 0000000000000000000000000000000000000000..e4bf962cc0af29272b38024c7cd5061a896fe797 --- /dev/null +++ b/sandbox/camera.h @@ -0,0 +1,54 @@ +#ifndef CAMERA_H +#define CAMERA_H + +#include <librealsense2/rs.hpp> +#include <librealsense2/rsutil.h> +#include <opencv4/opencv2/opencv.hpp> + + +class Camera +{ +private: + //constants in mm + //const float scale = rs2_get_depth_scale(sensor, NULL); + const int maxHeightSand = 400; + const int maxZ = 1120; + const int minZ = maxZ - maxHeightSand; + + rs2::spatial_filter spatFilter; + rs2::temporal_filter tempFilter; + rs2::decimation_filter decFilter; + rs2::config cfg; + rs2::pipeline pipe; + rs2::pipeline_profile profile; + rs2_intrinsics intrinsics; + void flipMat(cv::Mat &m); + void filterDepthFrame(rs2::depth_frame &frameDepth); + + cv::Mat matDepth; + cv::Mat matRGB; + +public: + Camera(); + void start(); + void stop(); + // Capture 30 frames to give autoexposure, etc. a chance to settle + void warmingUp(); + cv::Mat captureFrame(); + cv::Mat getAverageFrame(int numberFrame); + static cv::Mat coloredFrame(cv::Mat frameDepth); + cv::Point3f deprojectPixelToPoint(float coord[], float z1); + cv::Point2i projectPointToPixel(cv::Point3f point3D); + + void captureFramesAlign(); + void startAlign(); + cv::Mat getDepthFrameAlign() + { + return matDepth; + } + cv::Mat getRGBFrameAlign() + { + return matRGB.clone(); + } +}; +#endif diff --git a/sandbox/sandbox.cpp b/sandbox/sandbox.cpp index 78bdb3d62857633030ac3c88a5247f5eb51b0be7..ce9fd1b5c899f062771e7bc90c4ef09c98559778 100644 --- a/sandbox/sandbox.cpp +++ b/sandbox/sandbox.cpp @@ -59,8 +59,18 @@ void Sandbox::serialize(std::ostream& stream) stream << realSenseDevice.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); } -void Sandbox::deserialize(std::istream& stream) +string Sandbox::deserialize(std::istream& stream) { // Deserialization code stream >> realSenseDeviceSerialNumber; + int nbListRealSenseDevices = listRealSenseDevices.size(); + for (int i = 0; i < nbListRealSenseDevices; ++i) { + if (listRealSenseDevices[i].get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) == realSenseDeviceSerialNumber){ + realSenseDevice = listRealSenseDevices[i]; + i = nbListRealSenseDevices; + return "Device Connected\n"; + } + } + + return ""; } diff --git a/sandbox/sandbox.h b/sandbox/sandbox.h index cfcf5f5fc816271923b5840d354b13ec32c08d45..f68ba5dd3c93f296f315198e261f3567c88fc766 100644 --- a/sandbox/sandbox.h +++ b/sandbox/sandbox.h @@ -9,6 +9,8 @@ #include <iostream> #include "serializable.h" +using namespace std; + class Sandbox : Serializable { public: @@ -26,7 +28,7 @@ public: void loadListRealSenseDevices(); bool saveConfiguration(); void serialize(std::ostream& stream); - void deserialize(std::istream& stream); + string deserialize(std::istream& stream); }; #endif // SANDBOX_H diff --git a/sandbox/sandbox.pro b/sandbox/sandbox.pro index 0902da10c7270b86dbdb1cbd0d1a89bb65830f51..8242d41033df3506429ddc02994052923058642c 100644 --- a/sandbox/sandbox.pro +++ b/sandbox/sandbox.pro @@ -17,9 +17,11 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + camera.cpp \ sandbox.cpp HEADERS += \ + camera.h \ sandbox.h \ serializable.h @@ -29,4 +31,8 @@ unix { } !isEmpty(target.path): INSTALLS += target -LIBS += \ -lboost_system \ +INCLUDE += /usr/local/include + +LIBS += \ + -lboost_system \ + -L/usr/local/lib -lopencv_world \ diff --git a/sandbox/serializable.h b/sandbox/serializable.h index daedfd37ad1f80584e38460d2a37b00649af2f44..4a55fc12cdaac3a75e92c190d341722773ca2ac1 100644 --- a/sandbox/serializable.h +++ b/sandbox/serializable.h @@ -2,6 +2,9 @@ #define SERIALIZABLE_H #include <bits/stdc++.h> +#include <iostream> + +using namespace std; class Serializable { @@ -10,7 +13,7 @@ public: virtual ~Serializable(){} virtual void serialize(std::ostream& stream) = 0; - virtual void deserialize(std::istream& stream) = 0; + virtual string deserialize(std::istream& stream) = 0; }; #endif // SERIALIZABLE_H