diff --git a/Calibration/mainwindow.cpp b/Calibration/mainwindow.cpp index 612b5bd7a3a5b2c6316f743eb5c6ef49f958ee05..30df88f518d77c672cd55204c71ed63fa0429f0e 100644 --- a/Calibration/mainwindow.cpp +++ b/Calibration/mainwindow.cpp @@ -26,6 +26,8 @@ MainWindow::MainWindow(QWidget *parent) pteConsole_cursor = QTextCursor(ui->pteConsole->document()); pteConsole_cursor.movePosition(QTextCursor::End); + ui->btnSave->setEnabled(false); + searchRealSenseDevices(); } @@ -45,6 +47,7 @@ MainWindow::~MainWindow() */ void MainWindow::quitApplication() { + sandbox.stopCamera(); this->close(); } @@ -112,12 +115,22 @@ void MainWindow::saveConfiguration() { pteConsole_cursor.insertText("Serialized\n"); out.close(); + pteConsole_cursor.insertText(sandbox.getA()); + pteConsole_cursor.insertText("\n"); + pteConsole_cursor.insertText(QString::number(sandbox.getB())); + pteConsole_cursor.insertText("\n"); + ifstream in("./device"); pteConsole_cursor.insertText("Deserialize\n"); sandbox.deserialize(in); pteConsole_cursor.insertText("Deserialized\n"); out.close(); + pteConsole_cursor.insertText(sandbox.getA()); + pteConsole_cursor.insertText("\n"); + pteConsole_cursor.insertText(QString::number(sandbox.getB())); + pteConsole_cursor.insertText("\n"); + } /*! @@ -128,6 +141,10 @@ void MainWindow::configure() { switch (stepConfiguration) { case 0: // Edit the border { + indexCapturedPointToToSetDetectedPoint = 0; + indexPointToDetectBeamer = 0; + ui->btnSave->setEnabled(false); + 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"); @@ -144,10 +161,12 @@ void MainWindow::configure() { 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(500); - } while(indexPointToDetectBeamer < 3); + waitKey(100); + } while(indexPointToDetectBeamer < nbPointToDetectBeamer); ui->lblImage->setPixmap(QPixmap()); - stepConfiguration = 3; + stepConfiguration = 0; + ui->btnSave->setEnabled(true); + sandbox.stopCamera(); break; } case 2: @@ -155,8 +174,13 @@ void MainWindow::configure() { if (!crcToDetectBeamer.empty()) { sandbox.capturePointToDetectBeamer(crcToDetectBeamer); - indexPointToDetectBeamer++; + indexCapturedPointToToSetDetectedPoint++; pteConsole_cursor.insertText("add element\n"); + + if (indexCapturedPointToToSetDetectedPoint == nbCapturedPointToToSetDetectedPoint) { + indexCapturedPointToToSetDetectedPoint = 0; + indexPointToDetectBeamer++; + } } } default: diff --git a/Calibration/mainwindow.h b/Calibration/mainwindow.h index 378a6e005a4eb565009751fa58df922bd7a132be..093807614a6c434d242926c0ca6d75d13939cd67 100644 --- a/Calibration/mainwindow.h +++ b/Calibration/mainwindow.h @@ -38,6 +38,9 @@ private: int stepConfiguration = 0; vector<int> crcToDetectBeamer; int indexPointToDetectBeamer = 0; + int indexCapturedPointToToSetDetectedPoint = 0; + const int nbPointToDetectBeamer = 3; + const int nbCapturedPointToToSetDetectedPoint = 3; // Methods void showListRealSenseDevices(); diff --git a/build-Calibration-Desktop-Debug/2020-04-28-16_09_19.log b/build-Calibration-Desktop-Debug/2020-05-05-20_34_14.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-04-28-16_09_19.log rename to build-Calibration-Desktop-Debug/2020-05-05-20_34_14.log diff --git a/build-Calibration-Desktop-Debug/2020-04-28-16_10_49.log b/build-Calibration-Desktop-Debug/2020-05-05-20_34_30.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-04-28-16_10_49.log rename to build-Calibration-Desktop-Debug/2020-05-05-20_34_30.log diff --git a/build-Calibration-Desktop-Debug/2020-04-28-16_13_14.log b/build-Calibration-Desktop-Debug/2020-05-05-20_35_37.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-04-28-16_13_14.log rename to build-Calibration-Desktop-Debug/2020-05-05-20_35_37.log diff --git a/build-Calibration-Desktop-Debug/2020-04-28-17_37_14.log b/build-Calibration-Desktop-Debug/2020-05-05-20_36_52.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-04-28-17_37_14.log rename to build-Calibration-Desktop-Debug/2020-05-05-20_36_52.log diff --git a/build-Calibration-Desktop-Debug/2020-04-28-17_39_58.log b/build-Calibration-Desktop-Debug/2020-05-05-20_36_58.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-04-28-17_39_58.log rename to build-Calibration-Desktop-Debug/2020-05-05-20_36_58.log diff --git a/build-Calibration-Desktop-Debug/Calibration b/build-Calibration-Desktop-Debug/Calibration index a4fafe057ad6dcd1ffef2533400e03f66c695f0f..03e6dfaa5c152f12a5f90a5b1ef6d1efdbc9375c 100755 Binary files a/build-Calibration-Desktop-Debug/Calibration and b/build-Calibration-Desktop-Debug/Calibration differ diff --git a/build-Calibration-Desktop-Debug/device b/build-Calibration-Desktop-Debug/device index d1f2d150cbe022e463d39e98d639cec274e06cc8..24e1410b523618c1045463b038b256950d995014 100644 Binary files a/build-Calibration-Desktop-Debug/device and b/build-Calibration-Desktop-Debug/device differ diff --git a/build-Calibration-Desktop-Debug/mainwindow.o b/build-Calibration-Desktop-Debug/mainwindow.o index ade5df0929bf2d64d55cdda42007697834114a82..b2f6c8733450fd9681b8e0b1b6b2f8df81b7e527 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 9d5cf281077b3fa1dd7650c40573158777baadaf..a5467cb02deb6ced170e990a71d7917f22a1a9ff 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 b8eab859e95e6d8e1740bcde2ae208e420f339ca..ba3a2f0b5078d815564fa951447e0289a2212c5f 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/libsandbox.a b/build-sandbox-Desktop-Debug/libsandbox.a index 459fdda59d720e12d6807bccb8db03b124961b7c..05d03dfd89a36eaee15bb353669b83f0fce8e0f9 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 e72752be32480b5dab14b36d73d42d1d472f38b1..91ed6cadf2632348cb23dbcca5b0d4093878c036 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 49468b5638e512601cbb052a835dcc38423ac1c8..a5d96fc10a197470e00fd8dd68fda977bbc9cdb3 100644 --- a/sandbox/beamer.cpp +++ b/sandbox/beamer.cpp @@ -16,6 +16,19 @@ typedef struct double x, y, z; } XYZ; +/*! + * \brief LineLineIntersect + * \param p1 + * \param p2 + * \param p3 + * \param p4 + * \param pa + * \param pb + * \param mua + * \param mub + * \return + * Use 4 points to calculate the unprecised intersection of two lines + */ int LineLineIntersect( Point3d p1, Point3d p2, Point3d p3, Point3d p4, Point3d *pa, Point3d *pb, double *mua, double *mub) @@ -69,7 +82,7 @@ Beamer::Beamer(){ beamerPosition = Point3f(0.0f, 0.265f, -0.205f); points.push_back(Point(500, 500)); points.push_back(Point(1000, 300)); - points.push_back(Point(300, 800)); + points.push_back(Point(300, 700)); } @@ -77,6 +90,11 @@ Beamer::~Beamer(){ } +/*! + * \brief Beamer::findCercleZ + * \param rgb colored Frame + * \return a vector for the detected circle (can be empty) + */ vector<int> Beamer::findCercleZ(Mat &rgb) { Mat src_gray; @@ -101,10 +119,15 @@ vector<int> Beamer::findCercleZ(Mat &rgb) return result; } +/*! + * \brief Beamer::findPoint + * \param camera Intel RealSense Camera + * \param i index of point to detect + * \return a tuple with the frame and the detected circle + */ tuple<Mat, vector<int>> Beamer::findPoint(Camera camera, int i) { Mat rgb; - Point p = points[i]; camera.captureFramesAlign(); rgb = camera.getRGBFrameAlign(); @@ -121,6 +144,12 @@ tuple<Mat, vector<int>> Beamer::findPoint(Camera camera, int i) { return make_tuple(rgb, crc); } +/*! + * \brief Beamer::capturePoint + * \param camera + * \param crc detected circle + * Store the detect point + */ void Beamer::capturePoint(Camera camera, vector<int> crc) { Mat depth; camera.captureFramesAlign(); @@ -131,6 +160,10 @@ void Beamer::capturePoint(Camera camera, vector<int> crc) { capturedPoints.push_back(p); } +/*! + * \brief Beamer::findBeamerPosition + * Calculate the position of the beamer with the detected points + */ void Beamer::findBeamerPosition() { vector<Point3d> points1; //vectors calculate for each point vector<Point3d> points2; //1 point for each vector (to calculate constante d) diff --git a/sandbox/sandbox.cpp b/sandbox/sandbox.cpp index b4372cd591469567c6ec995184b60afb28c6e779..e516392a45b5b6b5a150aa43d092ee519bf97cd4 100644 --- a/sandbox/sandbox.cpp +++ b/sandbox/sandbox.cpp @@ -62,16 +62,23 @@ void Sandbox::loadListRealSenseDevices() void Sandbox::serialize(ostream& stream) { // Serialize ID for the Intel RealSense Camera - stream << realSenseDevice.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); + const char* serialnumber = realSenseDevice.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); // Serialize calibrate - stream << calibrate.getDistancePlan(); + float distance = calibrate.getDistancePlan(); + Mat matRotation = calibrate.getMatrixRotation(); - stream << matRotation.cols << matRotation.rows << matRotation.type(); + int cols = matRotation.cols; + int rows = matRotation.rows; // Serialize beamer - stream << beamer.getPosition().x << beamer.getPosition().y << beamer.getPosition().z; + int x, y, z; + x = beamer.getPosition().x; + y = beamer.getPosition().y; + z = beamer.getPosition().z; + // Seriliazation + stream << serialnumber << "\t" << distance << "\t" << cols << "\t" << rows << "\t" << x << "\t" << y << "\t" << z << "\t"; } /*! @@ -80,36 +87,40 @@ void Sandbox::serialize(ostream& stream) * \return a text to log the result * Deserialization to load a configuration file */ -string Sandbox::deserialize(istream& stream) +void Sandbox::deserialize(istream& stream) { - // Deserialization the Intel RealSense Camera - stream >> realSenseDeviceSerialNumber; + // Deserialize the Intel RealSense Camera + char* serialnumber; + + // Deserialize calibrate + float distancePlan; + + int cols, rows, type; + Mat matRotation; + + // Deserialize beamer + int x, y, z; + + // Deseriliazation + stream >> serialnumber >> distancePlan >> cols >> rows >> x >> y >> z; + + // Set Camera int nbListRealSenseDevices = listRealSenseDevices.size(); for (int i = 0; i < nbListRealSenseDevices; ++i) { - if (listRealSenseDevices[i].get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) == realSenseDeviceSerialNumber){ + if (listRealSenseDevices[i].get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) == serialnumber){ realSenseDevice = listRealSenseDevices[i]; i = nbListRealSenseDevices; - return "Device Connected\n"; } } - // Serialize calibrate - int cols, rows, type; - stream >> type >> rows >> cols; - Mat matRotation(cols, rows, type); - calibrate.setMatrixRotation(matRotation); - - float distancePlan; - stream >> distancePlan; + //Set calibraton calibrate.setDistancePlan(distancePlan); - // Serialize beamer - int x, y, z; - stream >> z >> y >> x; + calibrate.setMatrixRotation(matRotation); + + // Set beamer Point3f beamPosition(x, y, z); beamer.setPosition(beamPosition); - - return "Problem to load"; } /*! @@ -193,18 +204,38 @@ void Sandbox::applyBorder() { rectSandbox = Rect(p, rectSize); } +/*! + * \brief Sandbox::detectPointToDetectBeamer + * \param indexPoint + * \return a tuple, with the frame and a vector to detect circle + * Detect point with the circle to detect beamer + */ tuple<Mat, vector<int>> Sandbox::detectPointToDetectBeamer(int indexPoint) { return beamer.findPoint(camera, indexPoint); } +/*! + * \brief Sandbox::capturePointToDetectBeamer + * \param crc circle vector + */ void Sandbox::capturePointToDetectBeamer(vector<int> crc) { beamer.capturePoint(camera, crc); } +/*! + * \brief Sandbox::findBeamerPosition + * Find the position with the detected points + */ void Sandbox::findBeamerPosition() { beamer.findBeamerPosition(); } +/*! + * \brief Sandbox::stopCamera + * Stop the pipe + */ void Sandbox::stopCamera() { camera.stop(); } + + diff --git a/sandbox/sandbox.h b/sandbox/sandbox.h index 844d093799fde3b764aae7d787ffefd9e427a3f1..f65bde113a2e6e86e89ed48de55a93ffa4c99fc4 100644 --- a/sandbox/sandbox.h +++ b/sandbox/sandbox.h @@ -43,7 +43,7 @@ public: void loadListRealSenseDevices(); void saveConfiguration(); void serialize(ostream& stream); - string deserialize(istream& stream); + void deserialize(istream& stream); Mat configure(); double toDegrees(double radians); void applyBorder(); @@ -54,6 +54,12 @@ public: void capturePointToDetectBeamer(vector<int> crc); void findBeamerPosition(); void stopCamera(); + const char* getA() { + return realSenseDevice.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER); + } + int getB() { + return calibrate.getDistancePlan(); + } }; #endif // SANDBOX_H diff --git a/sandbox/serializable.h b/sandbox/serializable.h index 4e9410dd04a0e2b5e7a166b7a32f1acb6d6b7402..9af9037d070ee9bc93584983f045a99e7b96c1b6 100644 --- a/sandbox/serializable.h +++ b/sandbox/serializable.h @@ -13,7 +13,7 @@ public: virtual ~Serializable(){} virtual void serialize(ostream& stream) = 0; - virtual string deserialize(istream& stream) = 0; + virtual void deserialize(istream& stream) = 0; }; #endif // SERIALIZABLE_H