diff --git a/Calibration/mainwindow.cpp b/Calibration/mainwindow.cpp index 30df88f518d77c672cd55204c71ed63fa0429f0e..c7c0149994ee96487cb60947b2a0cea95e872368 100644 --- a/Calibration/mainwindow.cpp +++ b/Calibration/mainwindow.cpp @@ -108,28 +108,22 @@ void MainWindow::reloadListRealSenseDevices() { * Use the serialization of the API to save the configuration */ void MainWindow::saveConfiguration() { - ofstream out("./device"); + remove("./device"); + ofstream out; + out.open("./device"); pteConsole_cursor.insertText("Serialize\n"); sandbox.serialize(out); 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"); + ifstream in; + in.open("./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"); + out.close(); } @@ -171,7 +165,7 @@ void MainWindow::configure() { } case 2: { - if (!crcToDetectBeamer.empty()) + if (!crcToDetectBeamer.empty() && crcToDetectBeamer.size() == 1) { sandbox.capturePointToDetectBeamer(crcToDetectBeamer); indexCapturedPointToToSetDetectedPoint++; diff --git a/Calibration/mainwindow.h b/Calibration/mainwindow.h index 093807614a6c434d242926c0ca6d75d13939cd67..919d89fea62d1ce198eef1720b46cb50e2104d09 100644 --- a/Calibration/mainwindow.h +++ b/Calibration/mainwindow.h @@ -36,7 +36,7 @@ private: Sandbox sandbox; int selectedPoint = -1; int stepConfiguration = 0; - vector<int> crcToDetectBeamer; + vector<Vec3f> crcToDetectBeamer; int indexPointToDetectBeamer = 0; int indexCapturedPointToToSetDetectedPoint = 0; const int nbPointToDetectBeamer = 3; diff --git a/build-Calibration-Desktop-Debug/2020-05-05-20_34_14.log b/build-Calibration-Desktop-Debug/2020-05-12-17_40_49.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-05-05-20_34_14.log rename to build-Calibration-Desktop-Debug/2020-05-12-17_40_49.log diff --git a/build-Calibration-Desktop-Debug/2020-05-05-20_34_30.log b/build-Calibration-Desktop-Debug/2020-05-12-17_44_28.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-05-05-20_34_30.log rename to build-Calibration-Desktop-Debug/2020-05-12-17_44_28.log diff --git a/build-Calibration-Desktop-Debug/2020-05-05-20_35_37.log b/build-Calibration-Desktop-Debug/2020-05-12-17_58_20.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-05-05-20_35_37.log rename to build-Calibration-Desktop-Debug/2020-05-12-17_58_20.log diff --git a/build-Calibration-Desktop-Debug/2020-05-05-20_36_52.log b/build-Calibration-Desktop-Debug/2020-05-12-18_02_55.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-05-05-20_36_52.log rename to build-Calibration-Desktop-Debug/2020-05-12-18_02_55.log diff --git a/build-Calibration-Desktop-Debug/2020-05-05-20_36_58.log b/build-Calibration-Desktop-Debug/2020-05-12-18_10_23.log similarity index 100% rename from build-Calibration-Desktop-Debug/2020-05-05-20_36_58.log rename to build-Calibration-Desktop-Debug/2020-05-12-18_10_23.log diff --git a/build-Calibration-Desktop-Debug/2020-05-12-18_11_53.log b/build-Calibration-Desktop-Debug/2020-05-12-18_11_53.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/build-Calibration-Desktop-Debug/2020-05-12-18_19_29.log b/build-Calibration-Desktop-Debug/2020-05-12-18_19_29.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/build-Calibration-Desktop-Debug/2020-05-12-18_20_13.log b/build-Calibration-Desktop-Debug/2020-05-12-18_20_13.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/build-Calibration-Desktop-Debug/Calibration b/build-Calibration-Desktop-Debug/Calibration index 03e6dfaa5c152f12a5f90a5b1ef6d1efdbc9375c..b214a6a59ea2ac94d770218c36684ba5dd4a95ab 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 24e1410b523618c1045463b038b256950d995014..ad3bec151ec3cf369a2885166e4989391d981fb5 100644 Binary files a/build-Calibration-Desktop-Debug/device and b/build-Calibration-Desktop-Debug/device differ diff --git a/build-Calibration-Desktop-Debug/main.o b/build-Calibration-Desktop-Debug/main.o index 9b1cfabb39aa6438dbaf96495ddc275f3aa25a00..e6b494c465ee9af638f93c92ba0aec86808fa129 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 b2f6c8733450fd9681b8e0b1b6b2f8df81b7e527..f0527a137fae1900136a6ae128900b65c3062c76 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 a5467cb02deb6ced170e990a71d7917f22a1a9ff..6193a3ff80565100081be63f7c7df4c0b3874457 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/Makefile b/build-sandbox-Desktop-Debug/Makefile index 7ba8be361b43c2ef12b15649fd82aa2c5e3864f1..9951d4c307e6d508c5b8cba05c6cbd9cbe57a73b 100644 --- a/build-sandbox-Desktop-Debug/Makefile +++ b/build-sandbox-Desktop-Debug/Makefile @@ -111,6 +111,7 @@ DIST = /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_pre.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/qt_config.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_post.prf \ + ../sandbox/.qmake.stash \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/exclusive_builds.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/toolchain.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/default_pre.prf \ @@ -209,6 +210,7 @@ Makefile: ../sandbox/sandbox.pro /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/qt_config.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_post.prf \ + .qmake.stash \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/exclusive_builds.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/toolchain.prf \ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/default_pre.prf \ @@ -287,6 +289,7 @@ Makefile: ../sandbox/sandbox.pro /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/qt_config.prf: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++/qmake.conf: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/spec_post.prf: +.qmake.stash: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/exclusive_builds.prf: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/toolchain.prf: /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/default_pre.prf: diff --git a/build-sandbox-Desktop-Debug/beamer.o b/build-sandbox-Desktop-Debug/beamer.o index ba3a2f0b5078d815564fa951447e0289a2212c5f..84a2be5a2f151feee9064fb5d0a20c6a016b6090 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/camera.o b/build-sandbox-Desktop-Debug/camera.o index 53f583f1e29d4ffc8c75d5f04403adc5f4983a2d..d95cbab19f8bd491c37aaa72f0237b4f41810389 100644 Binary files a/build-sandbox-Desktop-Debug/camera.o and b/build-sandbox-Desktop-Debug/camera.o differ diff --git a/build-sandbox-Desktop-Debug/libsandbox.a b/build-sandbox-Desktop-Debug/libsandbox.a index 05d03dfd89a36eaee15bb353669b83f0fce8e0f9..5eecca2b7844ba27050daf17ee1b98ff3315ecb8 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 91ed6cadf2632348cb23dbcca5b0d4093878c036..5ba1e4ac154cee31f387a9c796614480755b023f 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 a5d96fc10a197470e00fd8dd68fda977bbc9cdb3..f91b96db9ab51c12f379910f94ac1c6400bf033b 100644 --- a/sandbox/beamer.cpp +++ b/sandbox/beamer.cpp @@ -95,7 +95,7 @@ Beamer::~Beamer(){ * \param rgb colored Frame * \return a vector for the detected circle (can be empty) */ -vector<int> Beamer::findCercleZ(Mat &rgb) +vector<Vec3f> Beamer::findCercleZ(Mat &rgb) { Mat src_gray; cvtColor(rgb, src_gray, CV_BGR2GRAY); @@ -108,7 +108,8 @@ vector<int> Beamer::findCercleZ(Mat &rgb) HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows / 4, 75, 50, 0, 0); //doit tester si le cercle est bon (rayon); - vector<int> result; + return circles; + /*vector<int> result; if (!circles.empty()) { for (int i = 0; i < 3; i++) @@ -116,7 +117,7 @@ vector<int> Beamer::findCercleZ(Mat &rgb) result.push_back(round(circles[0][i])); } } - return result; + return result;*/ } /*! @@ -125,15 +126,19 @@ vector<int> Beamer::findCercleZ(Mat &rgb) * \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) { +tuple<Mat, vector<Vec3f>> Beamer::findPoint(Camera camera, int i) { Mat rgb; Point p = points[i]; camera.captureFramesAlign(); rgb = camera.getRGBFrameAlign(); Scalar color; - vector<int> crc = findCercleZ(rgb); - if (!crc.empty()) + vector<Vec3f> crc = findCercleZ(rgb); + + for (int 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); @@ -150,12 +155,12 @@ tuple<Mat, vector<int>> Beamer::findPoint(Camera camera, int i) { * \param crc detected circle * Store the detect point */ -void Beamer::capturePoint(Camera camera, vector<int> crc) { +void Beamer::capturePoint(Camera camera, vector<Vec3f> crc) { Mat depth; camera.captureFramesAlign(); depth = camera.getDepthFrameAlign(); - float coord[2] = {(float)crc[0], (float)crc[1]}; - float z = static_cast<float>(depth.at<uint16_t>(crc[1], crc[0])); + float coord[2] = {(float)crc[0][0], (float)crc[0][1]}; + float z = static_cast<float>(depth.at<uint16_t>(crc[0][1], crc[0][0])); Point3f p = camera.deprojectPixelToPoint(coord, z / 1000.0); capturedPoints.push_back(p); } diff --git a/sandbox/beamer.h b/sandbox/beamer.h index adabf109992fc1068fc02a8fc836efbf95fc4d87..a04ff25325453fb211bf49b65f37bafd2ef2f07b 100644 --- a/sandbox/beamer.h +++ b/sandbox/beamer.h @@ -12,7 +12,7 @@ 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<int> findCercleZ(Mat &rgb); + vector<Vec3f> findCercleZ(Mat &rgb); Point3f beamerPosition; vector<Point> points; vector<Point3f> capturedPoints; @@ -30,8 +30,8 @@ public: beamerPosition = position; } void findBeamer(Camera camera); - tuple<Mat, vector<int>> findPoint(Camera camera, int i); - void capturePoint(Camera camera, vector<int> crc); + tuple<Mat, vector<Vec3f>> findPoint(Camera camera, int i); + void capturePoint(Camera camera, vector<Vec3f> crc); void findBeamerPosition(); }; #endif diff --git a/sandbox/camera.cpp b/sandbox/camera.cpp index a4e241eecdf67b99a3b2eadf35a245d766592df2..b755a264b710431c536ee9df7a23e460216aa5b3 100644 --- a/sandbox/camera.cpp +++ b/sandbox/camera.cpp @@ -68,7 +68,7 @@ Mat Camera::captureFrame() } void Camera::captureFramesAlign() { - rs2::align align(RS2_STREAM_DEPTH); + rs2::align align(RS2_STREAM_COLOR); auto frameset = pipe.wait_for_frames(); //Get processed aligned frame frameset = align.process(frameset); diff --git a/sandbox/sandbox.cpp b/sandbox/sandbox.cpp index e516392a45b5b6b5a150aa43d092ee519bf97cd4..5d77ce9c6295d0ebe5587641d2b760edfe59ac39 100644 --- a/sandbox/sandbox.cpp +++ b/sandbox/sandbox.cpp @@ -70,15 +70,25 @@ void Sandbox::serialize(ostream& stream) Mat matRotation = calibrate.getMatrixRotation(); int cols = matRotation.cols; int rows = matRotation.rows; + int type = matRotation.type(); // Serialize beamer - int x, y, z; + float 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"; + stream << serialnumber << CHAR_DELIM << distance << CHAR_DELIM << x << CHAR_DELIM << y << CHAR_DELIM << z << CHAR_DELIM << cols << CHAR_DELIM << rows << CHAR_DELIM << type << CHAR_DELIM; + std::cout << rows << " | " << cols << endl; + for (int a = 0; a < matRotation.rows; a++) + { + for (int b = 0; b < matRotation.cols; b++) + { + std::cout << a << " | " << b << " : " << matRotation.at<uint16_t>(a, b) << endl; + stream << matRotation.at<uint16_t>(a, b) << CHAR_DELIM; + } + } } /*! @@ -90,19 +100,51 @@ void Sandbox::serialize(ostream& stream) void Sandbox::deserialize(istream& stream) { // Deserialize the Intel RealSense Camera - char* serialnumber; + string serialnumber; // Deserialize calibrate float distancePlan; int cols, rows, type; - Mat matRotation; + // Deserialize beamer - int x, y, z; + float x, y, z; + + std::cout << "serialnumber" << endl; // Deseriliazation - stream >> serialnumber >> distancePlan >> cols >> rows >> x >> y >> z; + + stream >> serialnumber; + std::cout << "distancePlan" << endl; + stream >> distancePlan; + std::cout << "x" << endl; + stream >> x; + std::cout << "y" << endl; + stream >> y; + std::cout << "z" << endl; + stream >> z; + std::cout << "cols" << endl; + stream >> cols; + std::cout << "rows" << endl; + stream >> rows; + std::cout << "type" << endl; + stream >> type; + std::cout << "toto" << endl; + + uint16_t* data[rows][cols]; + for (int a = 0; a < rows; a++) + { + for (int b = 0; b < cols; b++) + { + uint16_t value; + stream >> value; + data[b][a]; + std::cout << a << " | " << b << " : " << value << endl; + } + } + + //Mat matRotation(rows, cols, type, data); // Set Camera int nbListRealSenseDevices = listRealSenseDevices.size(); @@ -116,13 +158,14 @@ void Sandbox::deserialize(istream& stream) //Set calibraton calibrate.setDistancePlan(distancePlan); - calibrate.setMatrixRotation(matRotation); + //calibrate.setMatrixRotation(matRotation); // Set beamer - Point3f beamPosition(x, y, z); - beamer.setPosition(beamPosition); + Point3f beamerPosition = Point3f(x, y, z); + beamer.setPosition(beamerPosition); } + /*! * \brief Sandbox::generateBorder * \return the colored frame with a rectangle to place the border @@ -210,7 +253,7 @@ 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<int>> Sandbox::detectPointToDetectBeamer(int indexPoint) { +tuple<Mat, vector<Vec3f>> Sandbox::detectPointToDetectBeamer(int indexPoint) { return beamer.findPoint(camera, indexPoint); } @@ -218,7 +261,7 @@ tuple<Mat, vector<int>> Sandbox::detectPointToDetectBeamer(int indexPoint) { * \brief Sandbox::capturePointToDetectBeamer * \param crc circle vector */ -void Sandbox::capturePointToDetectBeamer(vector<int> crc) { +void Sandbox::capturePointToDetectBeamer(vector<Vec3f> crc) { beamer.capturePoint(camera, crc); } diff --git a/sandbox/sandbox.h b/sandbox/sandbox.h index f65bde113a2e6e86e89ed48de55a93ffa4c99fc4..9204534466c8e30fd1967e43d8c0dac6e10ed366 100644 --- a/sandbox/sandbox.h +++ b/sandbox/sandbox.h @@ -33,6 +33,7 @@ private: vector<Point> border; Point center; Beamer beamer; + const char* CHAR_DELIM = "\t"; public: Sandbox(); @@ -50,16 +51,12 @@ public: Mat generateBorder(); int findEdgeBorder(int x, int y); Mat editEdgeBorder(int selectedPoint, int x, int y); - tuple<Mat, vector<int>> detectPointToDetectBeamer(int indexPoint); - void capturePointToDetectBeamer(vector<int> crc); + tuple<Mat, vector<Vec3f>> detectPointToDetectBeamer(int indexPoint); + void capturePointToDetectBeamer(vector<Vec3f> 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