mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-03 01:50:24 +08:00
Fixing ChArUco board support on opencv >= 4.7.0 (#1331)
Fixed https://github.com/introlab/rtabmap_ros/issues/1200
This commit is contained in:
@@ -231,7 +231,7 @@ ENDIF()
|
|||||||
set(RTABMAP_QT_VERSION AUTO CACHE STRING "Force a specific Qt version.")
|
set(RTABMAP_QT_VERSION AUTO CACHE STRING "Force a specific Qt version.")
|
||||||
set_property(CACHE RTABMAP_QT_VERSION PROPERTY STRINGS AUTO 4 5 6)
|
set_property(CACHE RTABMAP_QT_VERSION PROPERTY STRINGS AUTO 4 5 6)
|
||||||
|
|
||||||
FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS core calib3d imgproc highgui stitching photo video videoio OPTIONAL_COMPONENTS aruco xfeatures2d nonfree gpu cudafeatures2d)
|
FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS core calib3d imgproc highgui stitching photo video videoio OPTIONAL_COMPONENTS aruco objdetect xfeatures2d nonfree gpu cudafeatures2d)
|
||||||
|
|
||||||
IF(WITH_QT)
|
IF(WITH_QT)
|
||||||
FIND_PACKAGE(PCL 1.7 REQUIRED QUIET COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization)
|
FIND_PACKAGE(PCL 1.7 REQUIRED QUIET COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
include(CMakeFindDependencyMacro)
|
include(CMakeFindDependencyMacro)
|
||||||
|
|
||||||
# Mandatory dependencies
|
# Mandatory dependencies
|
||||||
find_dependency(OpenCV COMPONENTS core calib3d imgproc highgui stitching photo video OPTIONAL_COMPONENTS aruco xfeatures2d nonfree gpu cudafeatures2d)
|
find_dependency(OpenCV COMPONENTS core calib3d imgproc highgui stitching photo video OPTIONAL_COMPONENTS aruco objdetect xfeatures2d nonfree gpu cudafeatures2d)
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/RTABMap_guiTargets.cmake")
|
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/RTABMap_guiTargets.cmake")
|
||||||
find_dependency(PCL 1.7 COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization)
|
find_dependency(PCL 1.7 COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization)
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <rtabmap/utilite/UEventsHandler.h>
|
#include <rtabmap/utilite/UEventsHandler.h>
|
||||||
|
|
||||||
#if defined(HAVE_OPENCV_ARUCO) || CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
|
#if defined(HAVE_OPENCV_OBJDETECT) && (CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7))
|
||||||
|
#include <opencv2/objdetect/charuco_detector.hpp>
|
||||||
|
#define HAVE_CHARUCO
|
||||||
|
#elif defined(HAVE_OPENCV_ARUCO)
|
||||||
#include <opencv2/aruco/charuco.hpp>
|
#include <opencv2/aruco/charuco.hpp>
|
||||||
#define HAVE_CHARUCO
|
#define HAVE_CHARUCO
|
||||||
#endif
|
#endif
|
||||||
@@ -141,6 +144,10 @@ private:
|
|||||||
cv::Ptr<cv::aruco::Dictionary> markerDictionary_;
|
cv::Ptr<cv::aruco::Dictionary> markerDictionary_;
|
||||||
cv::Ptr<cv::aruco::DetectorParameters> arucoDetectorParams_;
|
cv::Ptr<cv::aruco::DetectorParameters> arucoDetectorParams_;
|
||||||
cv::Ptr<cv::aruco::CharucoBoard> charucoBoard_;
|
cv::Ptr<cv::aruco::CharucoBoard> charucoBoard_;
|
||||||
|
#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
|
||||||
|
cv::Ptr<cv::aruco::ArucoDetector> arucoDetector_;
|
||||||
|
cv::Ptr<cv::aruco::CharucoDetector> charucoDetector_;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -597,7 +597,8 @@ void matchCharucoImagePoints(
|
|||||||
objectPoints.push_back(board.chessboardCorners[pointId]);
|
objectPoints.push_back(board.chessboardCorners[pointId]);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
board.matchImagePoints(detectedCorners, detectedIds, objectPoints, cv::noArray());
|
cv::Mat imgPts;
|
||||||
|
board.matchImagePoints(detectedCorners, detectedIds, objectPoints, imgPts);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -753,16 +754,32 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat &
|
|||||||
UASSERT(charucoBoard_.get());
|
UASSERT(charucoBoard_.get());
|
||||||
|
|
||||||
// detect markers
|
// detect markers
|
||||||
|
UDEBUG("Detecting aruco markers...");
|
||||||
|
#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
|
||||||
|
UASSERT(arucoDetector_.get());
|
||||||
|
arucoDetector_->detectMarkers(timg, markerCorners, markerIds, rejected);
|
||||||
|
#else
|
||||||
cv::aruco::detectMarkers(timg, markerDictionary_, markerCorners, markerIds, arucoDetectorParams_, rejected);
|
cv::aruco::detectMarkers(timg, markerDictionary_, markerCorners, markerIds, arucoDetectorParams_, rejected);
|
||||||
|
#endif
|
||||||
// refine strategy to detect more markers
|
// refine strategy to detect more markers
|
||||||
|
UDEBUG("Refining aruco markers...");
|
||||||
|
#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
|
||||||
|
arucoDetector_->refineDetectedMarkers(timg, *charucoBoard_, markerCorners, markerIds, rejected);
|
||||||
|
#else
|
||||||
cv::aruco::refineDetectedMarkers(timg, charucoBoard_, markerCorners, markerIds, rejected);
|
cv::aruco::refineDetectedMarkers(timg, charucoBoard_, markerCorners, markerIds, rejected);
|
||||||
|
#endif
|
||||||
// interpolate charuco corners
|
// interpolate charuco corners
|
||||||
|
UDEBUG("Finding charuco corners (markers=%ld)...", markerCorners.size());
|
||||||
if(markerIds.size() > 0)
|
if(markerIds.size() > 0)
|
||||||
{
|
{
|
||||||
UASSERT(markerIds.size() == markerCorners.size());
|
UASSERT(markerIds.size() == markerCorners.size());
|
||||||
|
#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
|
||||||
|
UASSERT(charucoDetector_.get());
|
||||||
|
charucoDetector_->detectBoard(timg, pointBuf[id], pointIds[id], markerCorners, markerIds);
|
||||||
|
#else
|
||||||
cv::aruco::interpolateCornersCharuco(markerCorners, markerIds, timg, charucoBoard_, pointBuf[id], pointIds[id], cv::noArray(), cv::noArray(), 1);
|
cv::aruco::interpolateCornersCharuco(markerCorners, markerIds, timg, charucoBoard_, pointBuf[id], pointIds[id], cv::noArray(), cv::noArray(), 1);
|
||||||
|
#endif
|
||||||
|
UDEBUG("Found %ld charuco corners (requires 12)", pointBuf[id].size());
|
||||||
if(pointBuf[id].size() >= 12) {
|
if(pointBuf[id].size() >= 12) {
|
||||||
// Match image points
|
// Match image points
|
||||||
matchCharucoImagePoints(*charucoBoard_, pointBuf[id], pointIds[id], objectBuf[id]);
|
matchCharucoImagePoints(*charucoBoard_, pointBuf[id], pointIds[id], objectBuf[id]);
|
||||||
@@ -1273,6 +1290,8 @@ void CalibrationDialog::restart()
|
|||||||
ui_->doubleSpinBox_markerLength->value(),
|
ui_->doubleSpinBox_markerLength->value(),
|
||||||
*markerDictionary_));
|
*markerDictionary_));
|
||||||
charucoBoard_->setLegacyPattern(ui_->comboBox_board_type->currentIndex()==1);
|
charucoBoard_->setLegacyPattern(ui_->comboBox_board_type->currentIndex()==1);
|
||||||
|
arucoDetector_.reset(new cv::aruco::ArucoDetector(*markerDictionary_, *arucoDetectorParams_));
|
||||||
|
charucoDetector_.reset(new cv::aruco::CharucoDetector(*charucoBoard_, cv::aruco::CharucoParameters(), *arucoDetectorParams_));
|
||||||
#else
|
#else
|
||||||
charucoBoard_ = cv::aruco::CharucoBoard::create(
|
charucoBoard_ = cv::aruco::CharucoBoard::create(
|
||||||
ui_->spinBox_boardWidth->value(),
|
ui_->spinBox_boardWidth->value(),
|
||||||
|
|||||||
Reference in New Issue
Block a user