mirror of
https://github.com/zebrajr/opencv.git
synced 2025-12-06 12:19:50 +01:00
Make sure serialization with single dict preserves old behavior
This commit is contained in:
parent
3c88a001a2
commit
6c3b195a57
|
|
@ -1407,6 +1407,10 @@ void ArucoDetector::refineDetectedMarkers(InputArray _image, const Board& _board
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArucoDetector::write(FileStorage &fs) const {
|
void ArucoDetector::write(FileStorage &fs) const {
|
||||||
|
// preserve old format for single dictionary case
|
||||||
|
if (1 == arucoDetectorImpl->dictionaries.size()) {
|
||||||
|
arucoDetectorImpl->dictionaries[0].writeDictionary(fs);
|
||||||
|
} else {
|
||||||
fs << "dictionaries" << "[";
|
fs << "dictionaries" << "[";
|
||||||
for (auto& dictionary : arucoDetectorImpl->dictionaries) {
|
for (auto& dictionary : arucoDetectorImpl->dictionaries) {
|
||||||
fs << "{";
|
fs << "{";
|
||||||
|
|
@ -1414,6 +1418,7 @@ void ArucoDetector::write(FileStorage &fs) const {
|
||||||
fs << "}";
|
fs << "}";
|
||||||
}
|
}
|
||||||
fs << "]";
|
fs << "]";
|
||||||
|
}
|
||||||
arucoDetectorImpl->detectorParams.writeDetectorParameters(fs);
|
arucoDetectorImpl->detectorParams.writeDetectorParameters(fs);
|
||||||
arucoDetectorImpl->refineParams.writeRefineParameters(fs);
|
arucoDetectorImpl->refineParams.writeRefineParameters(fs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,15 @@
|
||||||
#include "opencv2/objdetect/aruco_detector.hpp"
|
#include "opencv2/objdetect/aruco_detector.hpp"
|
||||||
#include "opencv2/calib3d.hpp"
|
#include "opencv2/calib3d.hpp"
|
||||||
|
|
||||||
|
namespace cv::aruco {
|
||||||
|
bool operator==(const Dictionary& d1, const Dictionary& d2);
|
||||||
|
bool operator==(const Dictionary& d1, const Dictionary& d2) {
|
||||||
|
return d1.markerSize == d2.markerSize
|
||||||
|
&& std::equal(d1.bytesList.begin<uchar>(), d1.bytesList.end<uchar>(), d2.bytesList.begin<uchar>())
|
||||||
|
&& d1.maxCorrectionBits == d2.maxCorrectionBits;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace opencv_test { namespace {
|
namespace opencv_test { namespace {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -675,6 +684,9 @@ TEST(CV_ArucoMultiDict, noDict)
|
||||||
EXPECT_THROW({
|
EXPECT_THROW({
|
||||||
detector.removeDictionary(0);
|
detector.removeDictionary(0);
|
||||||
}, Exception);
|
}, Exception);
|
||||||
|
EXPECT_THROW({
|
||||||
|
detector.setDictionaries({});
|
||||||
|
}, Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -717,6 +729,36 @@ TEST(CV_ArucoMultiDict, multiMarkerDetection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(CV_ArucoMultiDict, serialization)
|
||||||
|
{
|
||||||
|
const std::string fileName("test_aruco_serialization.json");
|
||||||
|
aruco::ArucoDetector detector;
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::Mode::WRITE);
|
||||||
|
detector.write(fs);
|
||||||
|
fs.release();
|
||||||
|
FileStorage test_fs(fileName, FileStorage::Mode::READ);
|
||||||
|
aruco::ArucoDetector test_detector;
|
||||||
|
test_detector.read(test_fs.root());
|
||||||
|
// compare default constructor result
|
||||||
|
EXPECT_EQ(aruco::getPredefinedDictionary(aruco::DICT_4X4_50), test_detector.getDictionary());
|
||||||
|
}
|
||||||
|
detector.addDictionary(aruco::getPredefinedDictionary(aruco::DICT_5X5_100));
|
||||||
|
{
|
||||||
|
FileStorage fs(fileName, FileStorage::Mode::WRITE);
|
||||||
|
detector.write(fs);
|
||||||
|
fs.release();
|
||||||
|
FileStorage test_fs(fileName, FileStorage::Mode::READ);
|
||||||
|
aruco::ArucoDetector test_detector;
|
||||||
|
test_detector.read(test_fs.root());
|
||||||
|
// check for one additional dictionary
|
||||||
|
ASSERT_EQ(2ul, test_detector.getDictionaries().size());
|
||||||
|
EXPECT_EQ(aruco::getPredefinedDictionary(aruco::DICT_4X4_50), test_detector.getDictionary());
|
||||||
|
EXPECT_EQ(aruco::getPredefinedDictionary(aruco::DICT_5X5_100), test_detector.getDictionary(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ArucoThreading: public testing::TestWithParam<aruco::CornerRefineMethod>
|
struct ArucoThreading: public testing::TestWithParam<aruco::CornerRefineMethod>
|
||||||
{
|
{
|
||||||
struct NumThreadsSetter {
|
struct NumThreadsSetter {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user