From cffd06a173d17ab40e847bd7544bcf124118c4dc Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 23 Dec 2024 23:39:15 -0800 Subject: [PATCH 1/9] fix? --- src/ws_server.cu | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ws_server.cu b/src/ws_server.cu index 12cbd4f..f5c08e8 100644 --- a/src/ws_server.cu +++ b/src/ws_server.cu @@ -174,7 +174,12 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { cv::warpAffine(*bgr_img, rotatedImage, matRotation, bgr_img->size()); *bgr_img = rotatedImage.clone(); } - + void flip180(cv::Mat* bgr_img){ + cv::flip(*bgr_img, *bgr_img, 0); + } + void flip90(cv::Mat* bgr_img){ + cv::flip(*bgr_img, *bgr_img, 1); + } void startReadAndSendThread(const int camera_idx, const std::string& cal_file, const bool rotate_img) { read_thread_ = std::thread(&AprilTagHandler::readAndSend, this, camera_idx, From 025952a0ee0d171d8e08061a5f9c7d6af3bb2bbc Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 24 Dec 2024 00:33:07 -0800 Subject: [PATCH 2/9] add readme for build server thingy --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fba650a..ff5dc0f 100644 --- a/README.md +++ b/README.md @@ -145,3 +145,4 @@ Flask App: ![Alt](/res/flaskapp.png "Flask App Screenshot") Information for how data is sent to and from the Orin on NetworkTables is stored on the following Google Doc https://docs.google.com/document/d/1zhl0dlSLXOld302rhOQrhItLp2thuDD308Gv3yvkHMY/edit?usp=sharing +If you are an M-A Student looking for access to the build server, please fill out the form https://docs.google.com/document/d/14MWXYbr9kazaDxuQmgdHVRad1crJv6h6GJaEA4p0HTE/edit?usp=sharing \ No newline at end of file From 0ad4aebac383a3c911254964edddc72a92fc00a2 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 24 Dec 2024 12:58:17 -0800 Subject: [PATCH 3/9] add code for rotation utils --- .vscode/settings.json | 73 ++++++++++++++++++++++++++++++++++++++++ app/templates/index.html | 16 ++++++--- src/ws_server.cu | 43 +++++++++++++++-------- 3 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1de4b86 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,73 @@ +{ + "files.associations": { + "algorithm": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "set": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index 4902600..b8ad20e 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -125,7 +125,6 @@

AprilTag Detection with Controls and Pose Data

-
@@ -143,8 +142,12 @@

AprilTag Detection with Controls and Pose Data

- - + + +
+
+ +
@@ -212,8 +215,11 @@

Pose Data:

}; }); - document.getElementById('rotate-image').onchange = function() { - sendControl('rotate', this.checked); + document.getElementById('rotate-image-vertically').onchange = function() { + sendControl('flipVertical', this.checked); + }; + document.getElementById('rotate-image-horizontally').onchange = function() { + sendControl('flipHorizontal', this.checked); }; // Initial state diff --git a/src/ws_server.cu b/src/ws_server.cu index f5c08e8..0f58656 100644 --- a/src/ws_server.cu +++ b/src/ws_server.cu @@ -42,8 +42,10 @@ using json = nlohmann::json; DEFINE_int32(camera_idx, 0, "Camera index"); DEFINE_string(cal_file, "", "path name to calibration file"); -DEFINE_bool(rotate_img, true, +DEFINE_bool(rotate_vertical, false, "Rotates image by 180 degrees prior to detecting apriltags"); +DEFINE_bool(rotate_horizontal, false, + "Rotates image by 90 degrees prior to detecting apriltags"); enum ExposureMode { AUTO = 0, MANUAL = 1 }; @@ -78,8 +80,12 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { exposure_mode_ = j["value"].get(); settings_changed_ = true; } - if (j["type"] == "rotate") { - gui_rotate_img_ = j["value"].get(); + if (j["type"] == "flipVertical") { + flipVertical_ = j["value"].get(); + settings_changed_ = true; + } + if(j["type"] == "flipHorizontal"){ + flipHorizontal_ = j["value"].get(); settings_changed_ = true; } @@ -166,7 +172,8 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { return true; } - // TODO: Implement a faster version of this method! +/* +Legacy vertical flipping code void rotateImage(cv::Mat* bgr_img, const float angle) { cv::Point2f center((bgr_img->cols - 1) / 2.0, (bgr_img->rows - 1) / 2.0); cv::Mat matRotation = cv::getRotationMatrix2D(center, angle, 1.0); @@ -174,16 +181,17 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { cv::warpAffine(*bgr_img, rotatedImage, matRotation, bgr_img->size()); *bgr_img = rotatedImage.clone(); } - void flip180(cv::Mat* bgr_img){ +*/ + void flipVertical(cv::Mat* bgr_img){ cv::flip(*bgr_img, *bgr_img, 0); } - void flip90(cv::Mat* bgr_img){ + void flipHorizontal(cv::Mat* bgr_img){ cv::flip(*bgr_img, *bgr_img, 1); } void startReadAndSendThread(const int camera_idx, const std::string& cal_file, - const bool rotate_img) { + const bool rotate_vertical, const bool rotate_horizontal) { read_thread_ = std::thread(&AprilTagHandler::readAndSend, this, camera_idx, - cal_file, rotate_img); + cal_file, rotate_vertical, rotate_horizontal); } void joinReadAndSendThread() { @@ -210,7 +218,7 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { } void readAndSend(const int camera_idx, const std::string& cal_file, - const bool rotate_img) { + const bool rotate_vertical, const bool rotate_horizontal) { std::cout << "Enabling video capture" << std::endl; bool camera_started = false; cv::VideoCapture cap; @@ -291,7 +299,8 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { // Set the value of the gui rotate image variable to the value // that is passed in on the command line. The user can change it // later on from the gui. - gui_rotate_img_ = rotate_img; + flipVertical_ = rotate_vertical; + flipHorizontal_ = rotate_horizontal; int frame_counter = 0; cv::Mat bgr_img, yuyv_img; @@ -315,8 +324,13 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { frame_counter++; auto overallstart = std::chrono::high_resolution_clock::now(); - if (gui_rotate_img_) { - rotateImage(&bgr_img, 180.0); + //Let's check the time this takes, can always combine to one call if both are true later. + //Best case scenario is we don't place the camera wrong so we do not need this method at all. + if (flipVertical_) { + flipVertical(&bgr_img); + } + if (flipHorizontal_) { + flipHorizontal(&bgr_img); } cv::cvtColor(bgr_img, yuyv_img, cv::COLOR_BGR2YUV_YUYV); auto gpudetectstart = std::chrono::high_resolution_clock::now(); @@ -427,7 +441,8 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { std::atomic exposure_{50}; std::atomic exposure_mode_{0}; std::atomic settings_changed_{false}; - std::atomic gui_rotate_img_{false}; + std::atomic flipVertical_{false}; + std::atomic flipHorizontal_{false}; std::thread read_thread_; }; @@ -457,7 +472,7 @@ int main(int argc, char* argv[]) { handler ->startReadAndSendThread(FLAGS_camera_idx, FLAGS_cal_file, - FLAGS_rotate_img); + FLAGS_rotate_vertical, FLAGS_rotate_horizontal); server->serve("", 8080); handler->stop(); handler->joinReadAndSendThread(); From 5ea769b2936601d91dd910ff7bdc1b6ece92107f Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 24 Dec 2024 13:02:16 -0800 Subject: [PATCH 4/9] replace accidentally deleted line --- app/templates/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/app/templates/index.html b/app/templates/index.html index b8ad20e..85b1562 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -125,6 +125,7 @@

AprilTag Detection with Controls and Pose Data

+
From 6d6e26de4ffaa7d2258a5c555432776fbe6d7a10 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+maxspier@users.noreply.github.com> Date: Thu, 26 Dec 2024 10:54:03 -0800 Subject: [PATCH 5/9] Delete .vscode/settings.json --- .vscode/settings.json | 73 ------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 1de4b86..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "files.associations": { - "algorithm": "cpp", - "atomic": "cpp", - "bit": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "exception": "cpp", - "filesystem": "cpp", - "format": "cpp", - "forward_list": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "iterator": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "map": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "set": "cpp", - "span": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "string": "cpp", - "system_error": "cpp", - "thread": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "typeinfo": "cpp", - "utility": "cpp", - "vector": "cpp", - "xfacet": "cpp", - "xiosbase": "cpp", - "xlocale": "cpp", - "xlocbuf": "cpp", - "xlocinfo": "cpp", - "xlocmes": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xmemory": "cpp", - "xstddef": "cpp", - "xstring": "cpp", - "xtr1common": "cpp", - "xtree": "cpp", - "xutility": "cpp" - } -} \ No newline at end of file From 4935100c2476585e59883a7b6c537957790f6f87 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+maxspier@users.noreply.github.com> Date: Thu, 26 Dec 2024 10:55:02 -0800 Subject: [PATCH 6/9] Remove legacy flip code --- src/ws_server.cu | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/ws_server.cu b/src/ws_server.cu index 0f58656..33d27e5 100644 --- a/src/ws_server.cu +++ b/src/ws_server.cu @@ -171,17 +171,7 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { return true; } - -/* -Legacy vertical flipping code - void rotateImage(cv::Mat* bgr_img, const float angle) { - cv::Point2f center((bgr_img->cols - 1) / 2.0, (bgr_img->rows - 1) / 2.0); - cv::Mat matRotation = cv::getRotationMatrix2D(center, angle, 1.0); - cv::Mat rotatedImage; - cv::warpAffine(*bgr_img, rotatedImage, matRotation, bgr_img->size()); - *bgr_img = rotatedImage.clone(); - } -*/ +//Flipcode -1 = both directions void flipVertical(cv::Mat* bgr_img){ cv::flip(*bgr_img, *bgr_img, 0); } From b7df4bb2b4d1b8d12953b7dbca72f60d7ee90f77 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:07:27 -0600 Subject: [PATCH 7/9] fix P.R. image error --- src/ws_server.cu | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ws_server.cu b/src/ws_server.cu index 33d27e5..9d55052 100644 --- a/src/ws_server.cu +++ b/src/ws_server.cu @@ -172,11 +172,11 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { return true; } //Flipcode -1 = both directions - void flipVertical(cv::Mat* bgr_img){ - cv::flip(*bgr_img, *bgr_img, 0); + void flipVertical(const cv::Mat& bgr_img, cv::Mat* output_img){ + cv::flip(bgr_img, *output_img, 0); } - void flipHorizontal(cv::Mat* bgr_img){ - cv::flip(*bgr_img, *bgr_img, 1); + void flipHorizontal(const cv::Mat& bgr_img, cv::Mat* output_img){ + cv::flip(bgr_img, *output_img, 1); } void startReadAndSendThread(const int camera_idx, const std::string& cal_file, const bool rotate_vertical, const bool rotate_horizontal) { From 4cc4996e14887de6e414177640d56398720a40ba Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Sat, 28 Dec 2024 15:43:09 -0600 Subject: [PATCH 8/9] fix issue from PR --- src/ws_server.cu | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ws_server.cu b/src/ws_server.cu index 9d55052..e99798f 100644 --- a/src/ws_server.cu +++ b/src/ws_server.cu @@ -177,6 +177,9 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { } void flipHorizontal(const cv::Mat& bgr_img, cv::Mat* output_img){ cv::flip(bgr_img, *output_img, 1); + } + void flipBoth(const cv::Mat& bgr_img, cv::Mat* output_img){ + cv::flip(bgr_img, *output_img, -1); } void startReadAndSendThread(const int camera_idx, const std::string& cal_file, const bool rotate_vertical, const bool rotate_horizontal) { @@ -316,12 +319,18 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { auto overallstart = std::chrono::high_resolution_clock::now(); //Let's check the time this takes, can always combine to one call if both are true later. //Best case scenario is we don't place the camera wrong so we do not need this method at all. - if (flipVertical_) { - flipVertical(&bgr_img); - } - if (flipHorizontal_) { - flipHorizontal(&bgr_img); + if(flipVertical_ && flipHorizontal_){ + flipBoth(bgr_img.clone(), &bgr_img); + } else { + if (flipVertical_) { + flipVertical(bgr_img.clone(), &bgr_img); + } + if (flipHorizontal_) { + flipHorizontal(bgr_img.clone(), &bgr_img); + } } + + cv::cvtColor(bgr_img, yuyv_img, cv::COLOR_BGR2YUV_YUYV); auto gpudetectstart = std::chrono::high_resolution_clock::now(); detector.Detect(yuyv_img.data); From 10c993f4a1e18474a7523c48e2a75bb6c3901687 Mon Sep 17 00:00:00 2001 From: Max Spier <68516760+Mixmix00@users.noreply.github.com> Date: Sat, 28 Dec 2024 23:23:39 -0600 Subject: [PATCH 9/9] fix PR --- app/templates/index.html | 4 ++-- src/ws_server.cu | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/templates/index.html b/app/templates/index.html index 85b1562..cc0e493 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -144,11 +144,11 @@

AprilTag Detection with Controls and Pose Data

- +
- +
diff --git a/src/ws_server.cu b/src/ws_server.cu index e99798f..e03ab5d 100644 --- a/src/ws_server.cu +++ b/src/ws_server.cu @@ -322,12 +322,12 @@ class AprilTagHandler : public seasocks::WebSocket::Handler { if(flipVertical_ && flipHorizontal_){ flipBoth(bgr_img.clone(), &bgr_img); } else { - if (flipVertical_) { - flipVertical(bgr_img.clone(), &bgr_img); - } - if (flipHorizontal_) { - flipHorizontal(bgr_img.clone(), &bgr_img); - } + // if (flipVertical_) { + // flipVertical(bgr_img.clone(), &bgr_img); + // } + // if (flipHorizontal_) { + // flipHorizontal(bgr_img.clone(), &bgr_img); + // } }