diff --git a/Calibration/mainwindow.cpp b/Calibration/mainwindow.cpp index c7c0149994ee96487cb60947b2a0cea95e872368..a37ab8a8f7b0fc715a0921608319b147dcd8c5ae 100644 --- a/Calibration/mainwindow.cpp +++ b/Calibration/mainwindow.cpp @@ -26,6 +26,7 @@ MainWindow::MainWindow(QWidget *parent) pteConsole_cursor = QTextCursor(ui->pteConsole->document()); pteConsole_cursor.movePosition(QTextCursor::End); + // block backup without information ui->btnSave->setEnabled(false); searchRealSenseDevices(); @@ -112,17 +113,17 @@ void MainWindow::saveConfiguration() { ofstream out; out.open("./device"); - pteConsole_cursor.insertText("Serialize\n"); + pteConsole_cursor.insertText("Start serialization\n"); sandbox.serialize(out); - pteConsole_cursor.insertText("Serialized\n"); + pteConsole_cursor.insertText("Serialization completed\n"); out.close(); ifstream in; in.open("./device"); - pteConsole_cursor.insertText("Deserialize\n"); + pteConsole_cursor.insertText("Start deserialization\n"); sandbox.deserialize(in); - pteConsole_cursor.insertText("Deserialized\n"); + pteConsole_cursor.insertText("Deserialization completed\n"); out.close(); } @@ -135,46 +136,77 @@ void MainWindow::configure() { switch (stepConfiguration) { case 0: // Edit the border { - indexCapturedPointToToSetDetectedPoint = 0; - indexPointToDetectBeamer = 0; + // Reinit the states of the application + nbCurrentCapturedPoint = 0; + nbCurrentRegressionLine = 0; ui->btnSave->setEnabled(false); + // Draw border Mat coloredFrame = sandbox.generateBorder(); ui->lblImage->setPixmap(QPixmap::fromImage(QImage(coloredFrame.data, coloredFrame.cols, coloredFrame.rows, coloredFrame.step, QImage::Format_RGB888))); - pteConsole_cursor.insertText("Ready to init\n"); + + pteConsole_cursor.insertText("Ready to define the deformation matrix \n"); + pteConsole_cursor.insertText("Adapt the border with the projection of the beamer \n \n"); ui->btnConfig->setText("Generate matrix"); - stepConfiguration = 1; + + stepConfiguration = 1; // Change function of the button for the next step of calibration break; } - case 1: // Valid the border for the matrix deformation and start beamer detection + case 1: // Valid the border for the deformation matrix and start beamer detection { - sandbox.applyBorder(); - ui->btnConfig->setText("Capture Point"); - Mat frameDetection; - stepConfiguration = 2; + + sandbox.applyBorder(); // Generate the deformation matrix + + bool intersectionFound = false; do { - tie(frameDetection, crcToDetectBeamer) = sandbox.detectPointToDetectBeamer(indexPointToDetectBeamer); - ui->lblImage->setPixmap(QPixmap::fromImage(QImage(frameDetection.data, frameDetection.cols, frameDetection.rows, frameDetection.step, QImage::Format_RGB888))); - waitKey(100); - } while(indexPointToDetectBeamer < nbPointToDetectBeamer); + ui->btnConfig->setText("Capture point"); + pteConsole_cursor.insertText("Ready to capture points to find the position of the beamer \n"); + pteConsole_cursor.insertText("0 on 3 regression lines \n"); + pteConsole_cursor.insertText("0 on 3 points captured \n"); + + Mat frameDetection; + stepConfiguration = 2; // Change function to capture points + + do { // Reload the frame until all points are captured + // Get the frame and the list of circle detected used to capture points + tie(frameDetection, validDetection, listCircleDetected) = sandbox.detectPointToDetectBeamer(nbCurrentRegressionLine); + ui->lblImage->setPixmap(QPixmap::fromImage(QImage(frameDetection.data, frameDetection.cols, frameDetection.rows, frameDetection.step, QImage::Format_RGB888))); + waitKey(100); + } while(nbCurrentRegressionLine < nbTotalRegressionLine); + + // Find the position of the beamer with the intersections + intersectionFound = sandbox.findIntersections(); + + if (!intersectionFound) + pteConsole_cursor.insertText("Position not found. \n \n"); + + } while(!intersectionFound); + + // Complete the process + pteConsole_cursor.insertText("Calibration completed. You can save it now. \n \n"); ui->lblImage->setPixmap(QPixmap()); stepConfiguration = 0; ui->btnSave->setEnabled(true); sandbox.stopCamera(); break; } - case 2: + case 2: // Capture a point to find the beamer { - if (!crcToDetectBeamer.empty() && crcToDetectBeamer.size() == 1) + if (validDetection) // Capture the point only if there is exactly one circle { - sandbox.capturePointToDetectBeamer(crcToDetectBeamer); - indexCapturedPointToToSetDetectedPoint++; - pteConsole_cursor.insertText("add element\n"); + sandbox.capturePointToDetectBeamer(listCircleDetected); + nbCurrentCapturedPoint++; - if (indexCapturedPointToToSetDetectedPoint == nbCapturedPointToToSetDetectedPoint) { - indexCapturedPointToToSetDetectedPoint = 0; - indexPointToDetectBeamer++; + if (nbCurrentCapturedPoint == nbTotalCapturedPoint) { + sandbox.makeRegression(); + nbCurrentCapturedPoint = 0; + nbCurrentRegressionLine++; + + pteConsole_cursor.insertText("\n"); } + + pteConsole_cursor.insertText(QString::number(nbCurrentRegressionLine) + " on 3 regression lines \n"); + pteConsole_cursor.insertText(QString::number(nbCurrentCapturedPoint) + " on 3 points captured \n"); } } default: @@ -188,12 +220,11 @@ void MainWindow::configure() { * selected the edge of border the nearest of the mouse */ void MainWindow::moveEdgeBorder() { - - if (stepConfiguration == 1) { - if (selectedPoint == -1) { - selectedPoint = sandbox.findEdgeBorder(ui->lblImage->x, ui->lblImage->y); + if (stepConfiguration == 1) { // Method activated only on the step for the deformation matrix + if (selectedEdge == -1) { // Select the edge + selectedEdge = sandbox.findEdgeBorder(ui->lblImage->x, ui->lblImage->y); // Select rectangle's edge } else { - Mat coloredFrame = sandbox.editEdgeBorder(selectedPoint,ui->lblImage->x, ui->lblImage->y); + Mat coloredFrame = sandbox.editEdgeBorder(selectedEdge,ui->lblImage->x, ui->lblImage->y); // Move rectangle's edge ui->lblImage->setPixmap(QPixmap::fromImage(QImage(coloredFrame.data, coloredFrame.cols, coloredFrame.rows, coloredFrame.step, QImage::Format_RGB888))); } } @@ -205,6 +236,6 @@ void MainWindow::moveEdgeBorder() { */ void MainWindow::deselectEdgeBorder() { if (stepConfiguration == 1) { - selectedPoint = -1; + selectedEdge = -1; // Deselect rectangle's edge } } diff --git a/Calibration/mainwindow.h b/Calibration/mainwindow.h index 919d89fea62d1ce198eef1720b46cb50e2104d09..72229180a461dc1ba9cb650624fc9280ab158ef4 100644 --- a/Calibration/mainwindow.h +++ b/Calibration/mainwindow.h @@ -30,17 +30,17 @@ public: private: // Properties Ui::MainWindow *ui; - QTextCursor pteConsole_cursor; - context ctx; + QTextCursor pteConsole_cursor; // Cursor to write on the application's console device_list listRealSenseDevices; - Sandbox sandbox; - int selectedPoint = -1; + Sandbox sandbox; // Interface of the library + int selectedEdge = -1; // Index of the selected edge border for the deformation matrix step int stepConfiguration = 0; - vector<Vec3f> crcToDetectBeamer; - int indexPointToDetectBeamer = 0; - int indexCapturedPointToToSetDetectedPoint = 0; - const int nbPointToDetectBeamer = 3; - const int nbCapturedPointToToSetDetectedPoint = 3; + vector<Vec3f> listCircleDetected; // List of detected circle to find the tool to calculate the distance of the captured point + int nbCurrentRegressionLine = 0; + int nbCurrentCapturedPoint = 0; + const int nbTotalRegressionLine = 3; + const int nbTotalCapturedPoint = 3; + bool validDetection = false; // Methods void showListRealSenseDevices(); diff --git a/Calibration/reactivelabel.cpp b/Calibration/reactivelabel.cpp index f38abca3d199a086b8c7f0ec89d7336a98f0ef0f..f4b24c31b269eeec1e923c4e88c450be55cd00b0 100644 --- a/Calibration/reactivelabel.cpp +++ b/Calibration/reactivelabel.cpp @@ -5,6 +5,12 @@ ReactiveLabel::ReactiveLabel(QWidget *parent) : QLabel(parent) } +/*! + * \brief ReactiveLabel::mouseMoveEvent + * \param ev mouse vent + * Get the position of the mouse when the mouse move + * with the left-button pressed + */ void ReactiveLabel::mouseMoveEvent(QMouseEvent *ev){ this->x = ev->x(); this->y = ev->y(); @@ -12,10 +18,18 @@ void ReactiveLabel::mouseMoveEvent(QMouseEvent *ev){ emit mousePos(); } +/*! + * \brief ReactiveLabel::mousePressEvent + * Left-buton pressed + */ void ReactiveLabel::mousePressEvent(QMouseEvent *){ emit mousePressed(); } +/*! + * \brief ReactiveLabel::mouseReleaseEvent + * Left-buton released + */ void ReactiveLabel::mouseReleaseEvent(QMouseEvent *){ emit mouseLeft(); } diff --git a/Calibration/reactivelabel.h b/Calibration/reactivelabel.h index 68f64d09a4b6da2800bb7f1354cd13f526370af3..79bdf85606658e1b42eb9d9ac011a26793d43c64 100644 --- a/Calibration/reactivelabel.h +++ b/Calibration/reactivelabel.h @@ -4,17 +4,23 @@ #include <QLabel> #include <QMouseEvent> +/*! + * \brief The ReactiveLabel class + * Custom QLabel to add method for events mouse + */ class ReactiveLabel : public QLabel { Q_OBJECT public: explicit ReactiveLabel(QWidget *parent = 0); + // Properties + int x, y = 0; + + // Methods void mouseMoveEvent(QMouseEvent *ev); void mousePressEvent(QMouseEvent *ev); - void mouseReleaseEvent(QMouseEvent *ev); - - int x, y = 0; + void mouseReleaseEvent(QMouseEvent *ev); signals: void mousePressed(); diff --git a/build-Calibration-Desktop-Debug/Calibration b/build-Calibration-Desktop-Debug/Calibration index b214a6a59ea2ac94d770218c36684ba5dd4a95ab..9603d559268a54e91143c0f17c6a441da1496c44 100755 Binary files a/build-Calibration-Desktop-Debug/Calibration and b/build-Calibration-Desktop-Debug/Calibration differ diff --git a/build-Calibration-Desktop-Debug/main.o b/build-Calibration-Desktop-Debug/main.o index e6b494c465ee9af638f93c92ba0aec86808fa129..9b1cfabb39aa6438dbaf96495ddc275f3aa25a00 100644 Binary files a/build-Calibration-Desktop-Debug/main.o and b/build-Calibration-Desktop-Debug/main.o differ diff --git a/build-Calibration-Desktop-Debug/mainwindow.o b/build-Calibration-Desktop-Debug/mainwindow.o index f0527a137fae1900136a6ae128900b65c3062c76..5988192e6dc6d841c1594cd68c9014454455d02b 100644 Binary files a/build-Calibration-Desktop-Debug/mainwindow.o and b/build-Calibration-Desktop-Debug/mainwindow.o differ diff --git a/build-Calibration-Desktop-Debug/moc_mainwindow.o b/build-Calibration-Desktop-Debug/moc_mainwindow.o index 6193a3ff80565100081be63f7c7df4c0b3874457..05edb540bfebfb5f6de3f878eb004f3adb0fe1e8 100644 Binary files a/build-Calibration-Desktop-Debug/moc_mainwindow.o and b/build-Calibration-Desktop-Debug/moc_mainwindow.o differ diff --git a/build-sandbox-Desktop-Debug/beamer.o b/build-sandbox-Desktop-Debug/beamer.o index 84a2be5a2f151feee9064fb5d0a20c6a016b6090..9b099dd7a3d34020b5d9646a406e36543971c659 100644 Binary files a/build-sandbox-Desktop-Debug/beamer.o and b/build-sandbox-Desktop-Debug/beamer.o differ diff --git a/build-sandbox-Desktop-Debug/calibrate.o b/build-sandbox-Desktop-Debug/calibrate.o index 8e683ae507b0caa4cea9e4902cfb48f3c9b568fd..88f664ba594e7fdf05a4a80187bc4237be8a3bae 100644 Binary files a/build-sandbox-Desktop-Debug/calibrate.o and b/build-sandbox-Desktop-Debug/calibrate.o differ diff --git a/build-sandbox-Desktop-Debug/libsandbox.a b/build-sandbox-Desktop-Debug/libsandbox.a index 5eecca2b7844ba27050daf17ee1b98ff3315ecb8..a9b0bf6fe08d731d41ded7da745d0d6379aecf84 100644 Binary files a/build-sandbox-Desktop-Debug/libsandbox.a and b/build-sandbox-Desktop-Debug/libsandbox.a differ diff --git a/build-sandbox-Desktop-Debug/sandbox.o b/build-sandbox-Desktop-Debug/sandbox.o index 5ba1e4ac154cee31f387a9c796614480755b023f..47b8601fabaa13e528b555f2a8138d0edf59da65 100644 Binary files a/build-sandbox-Desktop-Debug/sandbox.o and b/build-sandbox-Desktop-Debug/sandbox.o differ diff --git a/sandbox/beamer.cpp b/sandbox/beamer.cpp index f91b96db9ab51c12f379910f94ac1c6400bf033b..4200e3b4acce4c592c43d35215bdb101f61e001b 100644 --- a/sandbox/beamer.cpp +++ b/sandbox/beamer.cpp @@ -29,7 +29,20 @@ typedef struct * \return * Use 4 points to calculate the unprecised intersection of two lines */ -int LineLineIntersect( +/*! + * \brief Beamer::intersectTwoLines + * \param p1 + * \param p2 + * \param p3 + * \param p4 + * \param pa + * \param pb + * \param mua + * \param mub + * \return validation of the founded intersection + * Use 4 points to calculate the unprecised intersection of two lines + */ +bool Beamer::intersectTwoLines( Point3d p1, Point3d p2, Point3d p3, Point3d p4, Point3d *pa, Point3d *pb, double *mua, double *mub) { @@ -78,12 +91,13 @@ int LineLineIntersect( } Beamer::Beamer(){ - //position par défaut + // Default position beamerPosition = Point3f(0.0f, 0.265f, -0.205f); + + // Set position points to capture to find position points.push_back(Point(500, 500)); points.push_back(Point(1000, 300)); points.push_back(Point(300, 700)); - } Beamer::~Beamer(){ @@ -91,62 +105,63 @@ Beamer::~Beamer(){ } /*! - * \brief Beamer::findCercleZ - * \param rgb colored Frame - * \return a vector for the detected circle (can be empty) + * \brief Beamer::findListCircles + * \param rgb colored frane + * \return list circles + * Find all circles in a frame */ -vector<Vec3f> Beamer::findCercleZ(Mat &rgb) +vector<Vec3f> Beamer::findListCircles(Mat &rgb) { Mat src_gray; cvtColor(rgb, src_gray, CV_BGR2GRAY); - /// Reduce the noise so we avoid false circle detection + // Reduce the noise so we avoid false circle detection GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2); vector<Vec3f> circles; circles.clear(); - /// Apply the Hough Transform to find the circles + // Apply the Hough Transform to find the circles //source, output, method, inverse ratio of resolution, Minimum distance between detected centers, threeshold canny, threeshold center, min radius, max radius HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows / 4, 75, 50, 0, 0); - //doit tester si le cercle est bon (rayon); - return circles; - /*vector<int> result; - if (!circles.empty()) - { - for (int i = 0; i < 3; i++) - { - result.push_back(round(circles[0][i])); - } - } - return result;*/ } + /*! - * \brief Beamer::findPoint + * \brief Beamer::detectPoint * \param camera Intel RealSense Camera * \param i index of point to detect - * \return a tuple with the frame and the detected circle + * \return a tuple with the frame, the validation of the detection and the list of detected circles + * Detect a point when the center of a unique circle on the frame + * is near the position define by the cross */ -tuple<Mat, vector<Vec3f>> Beamer::findPoint(Camera camera, int i) { +tuple<Mat, bool, vector<Vec3f>> Beamer::detectPoint(Camera camera, int i) { Mat rgb; Point p = points[i]; camera.captureFramesAlign(); rgb = camera.getRGBFrameAlign(); - Scalar color; - vector<Vec3f> crc = findCercleZ(rgb); + Scalar color = Scalar(255, 0, 0); + vector<Vec3f> crc = findListCircles(rgb); + bool valid = false; - for (int i = 0; i < crc.size(); ++i) { + for (uint i = 0; i < crc.size(); ++i) { circle(rgb, Point(round(crc[i][0]), round(crc[i][1])),round(crc[i][2]), Scalar(0,0,255), 4); } - if (!crc.empty() && crc.size() == 1) - color = Scalar(0, 255, 0); - else - color = Scalar(0, 0, 255); + + // Check unique circle + if (!crc.empty() && crc.size() == 1) { + + // Check the position of the circle + float distanceCenterPoint = (crc[1][0] - p.x) * (crc[1][0] - p.x) + (crc[1][0] - p.y) * (crc[1][0] - p.y); + if (distanceCenterPoint < errorDistanceCenterPoint) { + color = Scalar(0, 255, 0); + valid = true; + } + } line(rgb, Point(p.x, 0), Point(p.x, rgb.rows - 1), color, 4); line(rgb, Point(0, p.y), Point(rgb.cols - 1, p.y), color, 4); - return make_tuple(rgb, crc); + return make_tuple(rgb, valid, crc); } /*! @@ -166,40 +181,74 @@ void Beamer::capturePoint(Camera camera, vector<Vec3f> crc) { } /*! - * \brief Beamer::findBeamerPosition - * Calculate the position of the beamer with the detected points + * \brief Beamer::makeRegression + * make a regression with the captured points for a same position */ -void Beamer::findBeamerPosition() { - vector<Point3d> points1; //vectors calculate for each point - vector<Point3d> points2; //1 point for each vector (to calculate constante d) - double fact = -20.0; - Vec6f line; - fitLine(capturedPoints, line, CV_DIST_L2, 0, 0.01, 0.01); - points1.push_back(Point3d(line[3] * fact, line[4] * fact, line[5] * fact)); - points2.push_back(Point3d(line[0], line[1], line[2])); +void Beamer::makeRegression() { + fitLine(capturedPoints, regressedLines, CV_DIST_L2, 0, 0.01, 0.01); + points1.push_back(Point3d(regressedLines[3] * fact, regressedLines[4] * fact, regressedLines[5] * fact)); + points2.push_back(Point3d(regressedLines[0], regressedLines[1], regressedLines[2])); + capturedPoints.clear(); +} +/*! + * \brief Beamer::findIntersections + * \return the validation of the intersection of the lines + */ +bool Beamer::findIntersections() { Point3d pa, pb; double mua; double mub; - vector<Point3d> beamerPoints; - LineLineIntersect(points1[0], points2[0], points1[1], points2[1], &pa, &pb, &mua, &mub); + beamerPoints.clear(); + validIntersection = true; + + validIntersection = intersectTwoLines(points1[0], points2[0], points1[1], points2[1], &pa, &pb, &mua, &mub) ? validIntersection : false; beamerPoints.push_back(pa); beamerPoints.push_back(pb); - LineLineIntersect(points1[0], points2[0], points1[2], points2[2], &pa, &pb, &mua, &mub); + validIntersection = intersectTwoLines(points1[0], points2[0], points1[2], points2[2], &pa, &pb, &mua, &mub) ? validIntersection : false; beamerPoints.push_back(pa); beamerPoints.push_back(pb); - LineLineIntersect(points1[1], points2[1], points1[2], points2[2], &pa, &pb, &mua, &mub); + validIntersection = intersectTwoLines(points1[1], points2[1], points1[2], points2[2], &pa, &pb, &mua, &mub) ? validIntersection : false; beamerPoints.push_back(pa); beamerPoints.push_back(pb); - Point3d beamerPoint(0.0, 0.0, 0.0); - for (unsigned int i = 0; i < beamerPoints.size(); i++) - { - beamerPoint += beamerPoints[i]; + return validIntersection; + +} + +/*! + * \brief Beamer::findBeamerPosition + * Calculate the position with the intersections + */ +void Beamer::findBeamerPosition() { + if(validIntersection) { + Point3d beamerPoint(0.0, 0.0, 0.0); + for (unsigned int i = 0; i < beamerPoints.size(); i++) + { + beamerPoint += beamerPoints[i]; + } + beamerPoint /= 6.0; + + //set beamer position + beamerPosition.x = (float)beamerPoint.x; + beamerPosition.y = (float)beamerPoint.y; + beamerPosition.z = (float)beamerPoint.z; } - beamerPoint /= 6.0; - //set beamer position - beamerPosition.x = (float)beamerPoint.x; - beamerPosition.y = (float)beamerPoint.y; - beamerPosition.z = (float)beamerPoint.z; +} + +/*! + * \brief Beamer::getPosition + * \return position of the beamer + */ +Point3f Beamer::getPosition() +{ + return beamerPosition; +} + +/*! + * \brief setPosition + * \param position of the beamer + */ +void Beamer::setPosition(Point3f position) { + beamerPosition = position; } diff --git a/sandbox/beamer.h b/sandbox/beamer.h index a04ff25325453fb211bf49b65f37bafd2ef2f07b..2ecba19f7da4273ee455eafe635a4ce8064082b1 100644 --- a/sandbox/beamer.h +++ b/sandbox/beamer.h @@ -7,31 +7,45 @@ using namespace cv; using namespace std; +/*! + * \brief The Beamer class + * Toolbox to get the position of the beamer + */ class Beamer { private: - float solveD(Vec3f v, Point3f p); - Point3f intersection(Vec3f v1, Point3f p1, Vec3f v2, Point3f p2, Vec3f v3, Point3f p3, bool &isFound); - vector<Vec3f> findCercleZ(Mat &rgb); + // Properties Point3f beamerPosition; vector<Point> points; vector<Point3f> capturedPoints; + vector<Point3d> points1; //vectors calculate for each point + vector<Point3d> points2; //1 point for each vector (to calculate constante d) + double const fact = -20.0; + Vec6f regressedLines; + vector<Point3d> beamerPoints; + bool validIntersection; + + // Methods + bool intersectTwoLines( + Point3d p1, Point3d p2, Point3d p3, Point3d p4, Point3d *pa, Point3d *pb, + double *mua, double *mub); + vector<Vec3f> findListCircles(Mat &rgb); public: - Beamer(); - ~Beamer(); + //Properties static const int width = 1400; static const int height = 1050; - Point3f getPosition() - { - return beamerPosition; - } - void setPosition(Point3f position) { - beamerPosition = position; - } - void findBeamer(Camera camera); - tuple<Mat, vector<Vec3f>> findPoint(Camera camera, int i); + float errorDistanceCenterPoint = 0.1; + + // Methods + Beamer(); + ~Beamer(); + void makeRegression(); + Point3f getPosition(); + void setPosition(Point3f position); + tuple<Mat, bool, vector<Vec3f>> detectPoint(Camera camera, int i); void capturePoint(Camera camera, vector<Vec3f> crc); + bool findIntersections(); void findBeamerPosition(); }; #endif diff --git a/sandbox/borderedit.cpp b/sandbox/borderedit.cpp index 80244685f6158bb03bbb6b43667e8bf9491e0c2c..bb670f9f01134ca700a72925c329b245ce81c59f 100644 --- a/sandbox/borderedit.cpp +++ b/sandbox/borderedit.cpp @@ -1,12 +1,5 @@ -#include <algorithm> #include "borderedit.h" -/*! - * \brief BorderEdit::frameImage - * The original frame without border - */ -Mat BorderEdit::frameImage; - /*! * \brief BorderEdit::drawBorder * \param p first point of the border diff --git a/sandbox/borderedit.h b/sandbox/borderedit.h index 1d2120e08f343f74b2dd9ceef00f1f93236a1b30..8d3513a3a12b0d93dbf8e52b174a410f68b8c3f7 100644 --- a/sandbox/borderedit.h +++ b/sandbox/borderedit.h @@ -3,24 +3,28 @@ #include <opencv2/opencv.hpp> #include <QLabel> +#include <algorithm> using namespace cv; using namespace std; /*! * \brief The BorderEdit class - * Use the colored frame of the Intel RealSense - * Apply a border inside and move to correspond - * of the projected image of the beamer + * Static toolbox to draw and manipulate + * the border on a coloredFrame */ class BorderEdit { private: + // Properties static const int margeClick = 10; - static Mat frameImage; + static Mat frameImage; // The original frame without border + + // Methods static Mat drawBorder(cv::Point *p, int n); public: + // Methods static Mat initBorder(Mat frame, vector<Point> *posSandbox); static Mat edit(int selectedPoint, int x, int y, vector<Point> *posSandbox); static int findPoints(int x, int y, vector<Point> *posSandbox); diff --git a/sandbox/camera.cpp b/sandbox/camera.cpp index b755a264b710431c536ee9df7a23e460216aa5b3..574444c1b16021cece367e05475eeabdbed3e415 100644 --- a/sandbox/camera.cpp +++ b/sandbox/camera.cpp @@ -6,7 +6,10 @@ Camera::~Camera() { } -// Capture 30 frames to give autoexposure, etc. a chance to settle +/*! + * \brief Camera::warmingUp + * Capture 30 frames to give autoexposure, etc. a chance to settle + */ void Camera::warmingUp() { for (int i = 0; i < 30; ++i) @@ -19,45 +22,6 @@ void Camera::warmingUp() } } -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, COLORMAP_JET); - depthFrameColored.setTo(Scalar(0, 0, 0), (frameDepth == 0)); - return depthFrameColored; -} - Mat Camera::captureFrame() { auto frame = pipe.wait_for_frames(); diff --git a/sandbox/camera.h b/sandbox/camera.h index 9c871f9178bedf94ae0fcd2fcb370c5b0295d7b2..32d17bce9634a7be55fd9c3bcbf28695437bf7a8 100644 --- a/sandbox/camera.h +++ b/sandbox/camera.h @@ -12,12 +12,13 @@ using namespace std; class Camera { private: + //Properties + //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; - spatial_filter spatFilter; temporal_filter tempFilter; decimation_filter decFilter; @@ -25,13 +26,16 @@ private: pipeline pipe; pipeline_profile profile; rs2_intrinsics intrinsics; + Mat matDepth; + Mat matRGB; + + // Methods void flipMat(Mat &m); void filterDepthFrame(depth_frame &frameDepth); - Mat matDepth; - Mat matRGB; public: + // Methods Camera(); ~Camera(); void start(); @@ -40,7 +44,6 @@ public: void warmingUp(); Mat captureFrame(); Mat getAverageFrame(int numberFrame); - static Mat coloredFrame(Mat frameDepth); Point3f deprojectPixelToPoint(float coord[], float z1); Point2i projectPointToPixel(Point3f point3D); diff --git a/sandbox/sandbox.cpp b/sandbox/sandbox.cpp index 5d77ce9c6295d0ebe5587641d2b760edfe59ac39..b39ccff8448044f93cfec56e0cc1d6be175f3970 100644 --- a/sandbox/sandbox.cpp +++ b/sandbox/sandbox.cpp @@ -139,7 +139,7 @@ void Sandbox::deserialize(istream& stream) { uint16_t value; stream >> value; - data[b][a]; + data[b][a] = value; std::cout << a << " | " << b << " : " << value << endl; } } @@ -253,8 +253,8 @@ void Sandbox::applyBorder() { * \return a tuple, with the frame and a vector to detect circle * Detect point with the circle to detect beamer */ -tuple<Mat, vector<Vec3f>> Sandbox::detectPointToDetectBeamer(int indexPoint) { - return beamer.findPoint(camera, indexPoint); +tuple<Mat, bool, vector<Vec3f>> Sandbox::detectPointToDetectBeamer(int indexPoint) { + return beamer.detectPoint(camera, indexPoint); } /*! @@ -273,6 +273,14 @@ void Sandbox::findBeamerPosition() { beamer.findBeamerPosition(); } +/*! + * \brief Sandbox::findIntersections + * \return the validation of the intersection of the lines + */ +bool Sandbox::findIntersections() { + return beamer.findIntersections(); +} + /*! * \brief Sandbox::stopCamera * Stop the pipe @@ -281,4 +289,7 @@ void Sandbox::stopCamera() { camera.stop(); } +void Sandbox::makeRegression() { + beamer.makeRegression(); +} diff --git a/sandbox/sandbox.h b/sandbox/sandbox.h index 9204534466c8e30fd1967e43d8c0dac6e10ed366..8818b40a223991a4e16e1770a885f479dbdd2995 100644 --- a/sandbox/sandbox.h +++ b/sandbox/sandbox.h @@ -51,10 +51,12 @@ public: Mat generateBorder(); int findEdgeBorder(int x, int y); Mat editEdgeBorder(int selectedPoint, int x, int y); - tuple<Mat, vector<Vec3f>> detectPointToDetectBeamer(int indexPoint); + tuple<Mat, bool, vector<Vec3f>> detectPointToDetectBeamer(int indexPoint); void capturePointToDetectBeamer(vector<Vec3f> crc); void findBeamerPosition(); void stopCamera(); + void makeRegression(); + bool findIntersections(); }; diff --git a/sandbox/sandbox.pro b/sandbox/sandbox.pro index 2e4f76fdd6499365589d9853d2ea8053b01e768a..912ec56162351e8873e3175d17737d2c047ec0bc 100644 --- a/sandbox/sandbox.pro +++ b/sandbox/sandbox.pro @@ -18,18 +18,18 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ beamer.cpp \ - calibrate.cpp \ camera.cpp \ sandbox.cpp \ - borderedit.cpp + borderedit.cpp \ + transformframe.cpp HEADERS += \ beamer.h \ - calibrate.h \ camera.h \ sandbox.h \ serializable.h \ - borderedit.h + borderedit.h \ + transformframe.h # Default rules for deployment. unix { diff --git a/sandbox/calibrate.cpp b/sandbox/transformframe.cpp similarity index 55% rename from sandbox/calibrate.cpp rename to sandbox/transformframe.cpp index 0ab99714a675c590791e2e492fadf6f9c700a10d..87a8ff5b88d7fc3d8937b9950efa4c846b798cb9 100644 --- a/sandbox/calibrate.cpp +++ b/sandbox/transformframe.cpp @@ -1,20 +1,35 @@ -#include "calibrate.h" -#include "camera.h" +#include "transformframe.h" -Calibrate::Calibrate() +TransformFrame::TransformFrame() { } -Point2i Calibrate::rotatePixel(Point2i pixel) +/*! + * \brief Calibrate::rotatePixel + * \param pixel + * \return deformed pixel + * Apply the rotation matrix on a single pixel + */ +Point2i TransformFrame::rotatePixel(Point2i pixel) { Mat tmp = (Mat_<Vec2f>(1, 1) << Vec2f(pixel.x, pixel.y)); transform(tmp, tmp, matRotation); return Point2i(tmp.at<Vec2f>(0, 0)); } -Point2i Calibrate::transformationPixel(int i, int j, float z, Camera camera, Point3f beamer) +/*! + * \brief Calibrate::transformationPixel + * \param i first index for the pixel + * \param j second index for the pixel + * \param z depth distance + * \param camera + * \param beamer + * \return transformed 2D point + * Apply the transformation on a single pixel + */ +Point2i TransformFrame::transformationPixel(int i, int j, float z, Camera camera, Point3f beamer) { //pixel to point 3d float coord[2] = {static_cast<float>(j), static_cast<float>(i)}; @@ -29,7 +44,15 @@ Point2i Calibrate::transformationPixel(int i, int j, float z, Camera camera, Poi return camera.projectPointToPixel(p); } -void Calibrate::transformationFrame(Mat &src, Mat &dst, Camera camera, Point3f beamer) +/*! + * \brief Calibrate::transformationFrame + * \param src + * \param dst + * \param camera + * \param beamer + * Apply the transformation on a frame + */ +void TransformFrame::transformationFrame(Mat &src, Mat &dst, Camera camera, Point3f beamer) { int64_t t1 = getTickCount(); //transformation on all pixel @@ -49,7 +72,16 @@ void Calibrate::transformationFrame(Mat &src, Mat &dst, Camera camera, Point3f b // medianBlur(dst, dst, 3); } -void Calibrate::transformationFrame(Mat &depth, Mat &src, Mat &dst, Camera camera, Point3f beamer) +/*! + * \brief Calibrate::transformationFrame + * \param depth + * \param src + * \param dst + * \param camera + * \param beamer + * Apply the transformation on a frame + */ +void TransformFrame::transformationFrame(Mat &depth, Mat &src, Mat &dst, Camera camera, Point3f beamer) { int nbChannel = src.channels(); //transformation on all pixel @@ -74,3 +106,39 @@ void Calibrate::transformationFrame(Mat &depth, Mat &src, Mat &dst, Camera camer dilate(dst, dst, Mat(), Point(-1, -1), 2, 1, 1); erode(dst, dst, Mat(), Point(-1, -1), 2, 1, 1); } + +/*! + * \brief Calibrate::getMatrixRotation + * \return the rotation matrix + */ +Mat TransformFrame::getMatrixRotation() +{ + return matRotation; +} + +/*! + * \brief Calibrate::setMatrixRotation + * \param matrix of rotation + */ +void TransformFrame::setMatrixRotation(Mat matrix) +{ + matRotation = matrix.clone(); +} + +/*! + * \brief Calibrate::getDistancePlan + * \return distance of the sandbox + */ +float TransformFrame::getDistancePlan() +{ + return distancePlan; +} + +/*! + * \brief Calibrate::setDistancePlan + * \param distance of the sandbox + */ +void TransformFrame::setDistancePlan(float distance) +{ + distancePlan = distance; +} diff --git a/sandbox/calibrate.h b/sandbox/transformframe.h similarity index 58% rename from sandbox/calibrate.h rename to sandbox/transformframe.h index 2581b5b8b339afbbdd52907d788c8bf40eff7de0..678664ac504bed9637b90cf2d9de31380e3177de 100644 --- a/sandbox/calibrate.h +++ b/sandbox/transformframe.h @@ -6,33 +6,28 @@ using namespace cv; -class Calibrate +/*! + * \brief The TransformFrame class + * Class to adapt the detection of the Intel RealSense Camera + * to the projection of the beamer + */ +class TransformFrame { private: + // Properties Mat matRotation; float distancePlan; public: - Calibrate(); + // Methods + TransformFrame(); Point2i transformationPixel(int i, int j, float z, Camera camera, Point3f beamer); Point2i rotatePixel(Point2i pixel); void transformationFrame(Mat &src, Mat &dst, Camera camera, Point3f beamer); void transformationFrame(Mat &depth, Mat &src, Mat &dst, Camera camera, Point3f beamer); - Mat getMatrixRotation() - { - return matRotation; - } - void setMatrixRotation(Mat matrix) - { - matRotation = matrix.clone(); - } - float getDistancePlan() - { - return distancePlan; - } - void setDistancePlan(float distance) - { - distancePlan = distance; - } + Mat getMatrixRotation(); + void setMatrixRotation(Mat matrix); + float getDistancePlan(); + void setDistancePlan(float distance); }; #endif