Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TagDetector Cleanup and Update RoveComm_CPP Submodule #344

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/handlers/TagDetectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class TagDetectionHandler
TagDetector* m_pTagDetectorMainCam;
TagDetector* m_pTagDetectorLeftCam;
TagDetector* m_pTagDetectorRightCam;
TagDetector* m_pTagDetectorGroundCam;
RecordingHandler* m_pRecordingHandler;

public:
Expand Down
16 changes: 12 additions & 4 deletions src/vision/aruco/ArucoDetection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
* to not alter the original in case it's used after the call to this function
* completes.
*
* @param cvInputFrame - cv::Mat of the image to pre-process.
* @param cvInputFrame - cv::Mat of the image to pre-process. This image should be in BGR format.
* @param cvOutputFrame - cv::Mat to write the pre-processed image to.
*
* @todo Determine optimal order for speed
Expand All @@ -95,9 +95,17 @@
******************************************************************************/
inline void PreprocessFrame(const cv::Mat& cvInputFrame, cv::Mat& cvOutputFrame)
{
// Check if the input frame is in BGR format.
if (cvInputFrame.channels() != 3)

Check warning on line 99 in src/vision/aruco/ArucoDetection.hpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/ArucoDetection.hpp#L99

Added line #L99 was not covered by tests
{
// Submit logger message.
LOG_ERROR(logging::g_qSharedLogger, "PreprocessFrame() requires a BGR image.");
return;

Check warning on line 103 in src/vision/aruco/ArucoDetection.hpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/ArucoDetection.hpp#L102-L103

Added lines #L102 - L103 were not covered by tests
}

// Grayscale.
cv::cvtColor(cvInputFrame, cvOutputFrame, cv::COLOR_BGRA2GRAY);
cv::filter2D(cvOutputFrame, cvInputFrame, -1, constants::ARUCO_SHARPEN_KERNEL_EXTRA);
cv::cvtColor(cvInputFrame, cvOutputFrame, cv::COLOR_BGR2GRAY);
cv::filter2D(cvOutputFrame, cvOutputFrame, -1, constants::ARUCO_SHARPEN_KERNEL_EXTRA);

Check warning on line 108 in src/vision/aruco/ArucoDetection.hpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/ArucoDetection.hpp#L107-L108

Added lines #L107 - L108 were not covered by tests
// Reduce number of colors/gradients in the image.
// imgops::ColorReduce(cvOutputFrame);
// Denoise (Looks like bilateral filter is req. for ArUco, check speed since docs say it's slow)
Expand All @@ -120,7 +128,7 @@
/******************************************************************************
* @brief Detect ArUco tags in the provided image.
*
* @param cvFrame - The camera frame to run ArUco detection on. Should be BGR format.
* @param cvFrame - The camera frame to run ArUco detection on. Should be BGR format or grayscale.
* @param cvArucoDetector - The configured aruco detector to use for detection.
* @return std::vector<ArucoTag> - The resultant vector containing the detected tags in the frame.
*
Expand Down
32 changes: 25 additions & 7 deletions src/vision/aruco/TagDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@
// Download mat from GPU memory.
m_cvGPUPointCloud.download(m_cvPointCloud);
m_cvGPUFrame.download(m_cvFrame);
// Drop the Alpha channel from the image copy to preproc frame.
cv::cvtColor(m_cvFrame, m_cvFrame, cv::COLOR_BGRA2RGB);

Check warning on line 239 in src/vision/aruco/TagDetector.cpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TagDetector.cpp#L239

Added line #L239 was not covered by tests
}
else
{
Expand All @@ -259,6 +261,11 @@
// Submit logger message.
LOG_WARNING(logging::g_qSharedLogger, "TagDetector unable to get regular frame from ZEDCam!");
}
else
{
// Drop the Alpha channel from the image copy to preproc frame.
cv::cvtColor(m_cvFrame, m_cvFrame, cv::COLOR_BGRA2RGB);

Check warning on line 267 in src/vision/aruco/TagDetector.cpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TagDetector.cpp#L267

Added line #L267 was not covered by tests
}
}
}
else
Expand All @@ -272,23 +279,34 @@
// Submit logger message.
LOG_WARNING(logging::g_qSharedLogger, "TagDetector unable to get point cloud from BasicCam!");
}
else
{
// Check if the camera image is a >3 channel image.
if (m_cvFrame.channels() > 3)
{
// Drop the Alpha channel from the image copy to preproc frame.
cv::cvtColor(m_cvFrame, m_cvFrame, cv::COLOR_BGRA2RGB);

Check warning on line 288 in src/vision/aruco/TagDetector.cpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TagDetector.cpp#L288

Added line #L288 was not covered by tests
}
}
}

/////////////////////////////////////////
// Actual detection logic goes here.
/////////////////////////////////////////
// Drop the Alpha channel from the image copy to preproc frame.
cv::cvtColor(m_cvFrame, m_cvArucoProcFrame, cv::COLOR_BGRA2BGR);
// Run image through some pre-processing step to improve detection.
arucotag::PreprocessFrame(m_cvArucoProcFrame, m_cvArucoProcFrame);
arucotag::PreprocessFrame(m_cvFrame, m_cvArucoProcFrame);

Check warning on line 297 in src/vision/aruco/TagDetector.cpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TagDetector.cpp#L297

Added line #L297 was not covered by tests
// Detect tags in the image
std::vector<arucotag::ArucoTag> vNewlyDetectedTags = arucotag::Detect(m_cvArucoProcFrame, m_cvArucoDetector);

// Estimate the positions of the tags using the point cloud
for (arucotag::ArucoTag& stTag : vNewlyDetectedTags)
// Only estimate the pose of the tags if the point cloud is available and we are using a ZED camera.
if (m_bUsingZedCamera && !m_cvPointCloud.empty())
{
// Use the point cloud to get the location of the tag.
arucotag::EstimatePoseFromPointCloud(m_cvPointCloud, stTag);
// Estimate the positions of the tags using the point cloud
for (arucotag::ArucoTag& stTag : vNewlyDetectedTags)
{
// Use the point cloud to get the location of the tag.
arucotag::EstimatePoseFromPointCloud(m_cvPointCloud, stTag);

Check warning on line 308 in src/vision/aruco/TagDetector.cpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TagDetector.cpp#L308

Added line #L308 was not covered by tests
}
}
// Merge the newly detected tags with the pre-existing detected tags
this->UpdateDetectedTags(vNewlyDetectedTags);
Expand Down
8 changes: 8 additions & 0 deletions src/vision/aruco/TensorflowTagDetection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
const float fMinObjectConfidence = 0.40f,
const float fNMSThreshold = 0.60f)
{
// Check if the input frame is in RGB format.
if (cvFrame.channels() != 3)

Check warning on line 102 in src/vision/aruco/TensorflowTagDetection.hpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TensorflowTagDetection.hpp#L102

Added line #L102 was not covered by tests
{
// Submit logger message.
LOG_ERROR(logging::g_qSharedLogger, "Detect() requires a RGB image.");
return {};

Check warning on line 106 in src/vision/aruco/TensorflowTagDetection.hpp

View check run for this annotation

Codecov / codecov/patch

src/vision/aruco/TensorflowTagDetection.hpp#L105-L106

Added lines #L105 - L106 were not covered by tests
}

// Declare instance variables.
std::vector<TensorflowTag> vDetectedTags;

Expand Down