aruco(cleanup): don't use Ptr<FileStorage>

pull/23005/head
Alexander Alekhin 2 years ago
parent 91ac790249
commit c6a15e1835
  1. 14
      modules/objdetect/include/opencv2/objdetect/aruco_detector.hpp
  2. 6
      modules/objdetect/include/opencv2/objdetect/aruco_dictionary.hpp
  3. 132
      modules/objdetect/src/aruco/aruco_detector.cpp
  4. 17
      modules/objdetect/src/aruco/aruco_dictionary.cpp
  5. 10
      modules/objdetect/src/aruco/aruco_utils.hpp

@ -85,11 +85,7 @@ struct CV_EXPORTS_W_SIMPLE DetectorParameters {
/** @brief Write a set of DetectorParameters to FileStorage
*/
bool writeDetectorParameters(FileStorage& fs);
/** @brief simplified API for language bindings
*/
CV_WRAP bool writeDetectorParameters(const Ptr<FileStorage>& fs, const String& name = String());
CV_WRAP bool writeDetectorParameters(FileStorage& fs, const String& name = String());
/// minimum window size for adaptive thresholding before finding contours (default 3).
CV_PROP_RW int adaptiveThreshWinSizeMin;
@ -237,11 +233,7 @@ struct CV_EXPORTS_W_SIMPLE RefineParameters {
/** @brief Write a set of RefineParameters to FileStorage
*/
bool writeRefineParameters(FileStorage& fs);
/** @brief simplified API for language bindings
*/
CV_WRAP bool writeRefineParameters(const Ptr<FileStorage>& fs, const String& name = String());
CV_WRAP bool writeRefineParameters(FileStorage& fs, const String& name = String());
/** @brief minRepDistance minimum distance between the corners of the rejected candidate and the reprojected marker
in order to consider it as a correspondence.
@ -347,7 +339,7 @@ public:
/** @brief simplified API for language bindings
*/
CV_WRAP inline void write(const Ptr<FileStorage>& fs, const String& name = String()) { Algorithm::write(fs, name); }
CV_WRAP inline void write(FileStorage& fs, const String& name) { Algorithm::write(fs, name); }
/** @brief Reads algorithm parameters from a file storage
*/

@ -50,11 +50,7 @@ class CV_EXPORTS_W_SIMPLE Dictionary {
/** @brief Write a dictionary to FileStorage, format is the same as in readDictionary().
*/
void writeDictionary(FileStorage& fs);
/** @brief simplified API for language bindings
*/
CV_WRAP void writeDictionary(Ptr<FileStorage>& fs, const String& name = String());
CV_WRAP void writeDictionary(FileStorage& fs, const String& name = String());
/** @brief Given a matrix of bits. Returns whether if marker is identified or not.
*

@ -16,77 +16,73 @@ namespace aruco {
using namespace std;
static inline bool readWrite(DetectorParameters &params, const Ptr<FileNode>& readNode,
const Ptr<FileStorage>& writeStorage = nullptr) {
CV_Assert(!readNode.empty() || !writeStorage.empty());
static inline bool readWrite(DetectorParameters &params, const FileNode* readNode,
FileStorage* writeStorage = nullptr)
{
CV_Assert(readNode || writeStorage);
bool check = false;
check |= readWriteParameter("adaptiveThreshWinSizeMin", params.adaptiveThreshWinSizeMin, *readNode, *writeStorage);
check |= readWriteParameter("adaptiveThreshWinSizeMax", params.adaptiveThreshWinSizeMax, *readNode, *writeStorage);
check |= readWriteParameter("adaptiveThreshWinSizeStep", params.adaptiveThreshWinSizeStep, *readNode, *writeStorage);
check |= readWriteParameter("adaptiveThreshConstant", params.adaptiveThreshConstant, *readNode, *writeStorage);
check |= readWriteParameter("minMarkerPerimeterRate", params.minMarkerPerimeterRate, *readNode, *writeStorage);
check |= readWriteParameter("maxMarkerPerimeterRate", params.maxMarkerPerimeterRate, *readNode, *writeStorage);
check |= readWriteParameter("adaptiveThreshWinSizeMin", params.adaptiveThreshWinSizeMin, readNode, writeStorage);
check |= readWriteParameter("adaptiveThreshWinSizeMax", params.adaptiveThreshWinSizeMax, readNode, writeStorage);
check |= readWriteParameter("adaptiveThreshWinSizeStep", params.adaptiveThreshWinSizeStep, readNode, writeStorage);
check |= readWriteParameter("adaptiveThreshConstant", params.adaptiveThreshConstant, readNode, writeStorage);
check |= readWriteParameter("minMarkerPerimeterRate", params.minMarkerPerimeterRate, readNode, writeStorage);
check |= readWriteParameter("maxMarkerPerimeterRate", params.maxMarkerPerimeterRate, readNode, writeStorage);
check |= readWriteParameter("polygonalApproxAccuracyRate", params.polygonalApproxAccuracyRate,
*readNode, *writeStorage);
check |= readWriteParameter("minCornerDistanceRate", params.minCornerDistanceRate, *readNode, *writeStorage);
check |= readWriteParameter("minDistanceToBorder", params.minDistanceToBorder, *readNode, *writeStorage);
check |= readWriteParameter("minMarkerDistanceRate", params.minMarkerDistanceRate, *readNode, *writeStorage);
check |= readWriteParameter("cornerRefinementMethod", params.cornerRefinementMethod, *readNode, *writeStorage);
check |= readWriteParameter("cornerRefinementWinSize", params.cornerRefinementWinSize, *readNode, *writeStorage);
readNode, writeStorage);
check |= readWriteParameter("minCornerDistanceRate", params.minCornerDistanceRate, readNode, writeStorage);
check |= readWriteParameter("minDistanceToBorder", params.minDistanceToBorder, readNode, writeStorage);
check |= readWriteParameter("minMarkerDistanceRate", params.minMarkerDistanceRate, readNode, writeStorage);
check |= readWriteParameter("cornerRefinementMethod", params.cornerRefinementMethod, readNode, writeStorage);
check |= readWriteParameter("cornerRefinementWinSize", params.cornerRefinementWinSize, readNode, writeStorage);
check |= readWriteParameter("cornerRefinementMaxIterations", params.cornerRefinementMaxIterations,
*readNode, *writeStorage);
readNode, writeStorage);
check |= readWriteParameter("cornerRefinementMinAccuracy", params.cornerRefinementMinAccuracy,
*readNode, *writeStorage);
check |= readWriteParameter("markerBorderBits", params.markerBorderBits, *readNode, *writeStorage);
readNode, writeStorage);
check |= readWriteParameter("markerBorderBits", params.markerBorderBits, readNode, writeStorage);
check |= readWriteParameter("perspectiveRemovePixelPerCell", params.perspectiveRemovePixelPerCell,
*readNode, *writeStorage);
readNode, writeStorage);
check |= readWriteParameter("perspectiveRemoveIgnoredMarginPerCell", params.perspectiveRemoveIgnoredMarginPerCell,
*readNode, *writeStorage);
readNode, writeStorage);
check |= readWriteParameter("maxErroneousBitsInBorderRate", params.maxErroneousBitsInBorderRate,
*readNode, *writeStorage);
check |= readWriteParameter("minOtsuStdDev", params.minOtsuStdDev, *readNode, *writeStorage);
check |= readWriteParameter("errorCorrectionRate", params.errorCorrectionRate, *readNode, *writeStorage);
readNode, writeStorage);
check |= readWriteParameter("minOtsuStdDev", params.minOtsuStdDev, readNode, writeStorage);
check |= readWriteParameter("errorCorrectionRate", params.errorCorrectionRate, readNode, writeStorage);
// new aruco 3 functionality
check |= readWriteParameter("useAruco3Detection", params.useAruco3Detection, *readNode, *writeStorage);
check |= readWriteParameter("minSideLengthCanonicalImg", params.minSideLengthCanonicalImg, *readNode, *writeStorage);
check |= readWriteParameter("useAruco3Detection", params.useAruco3Detection, readNode, writeStorage);
check |= readWriteParameter("minSideLengthCanonicalImg", params.minSideLengthCanonicalImg, readNode, writeStorage);
check |= readWriteParameter("minMarkerLengthRatioOriginalImg", params.minMarkerLengthRatioOriginalImg,
*readNode, *writeStorage);
readNode, writeStorage);
return check;
}
bool DetectorParameters::readDetectorParameters(const FileNode& fn) {
if(fn.empty())
bool DetectorParameters::readDetectorParameters(const FileNode& fn)
{
if (fn.empty())
return false;
Ptr<FileNode> pfn = makePtr<FileNode>(fn);
return readWrite(*this, pfn);
return readWrite(*this, &fn);
}
bool DetectorParameters::writeDetectorParameters(const Ptr<FileStorage>& fs, const String& name) {
if (fs.empty())
return false;
if(name.empty())
return writeDetectorParameters(*fs);
*fs << name << "{";
bool res = writeDetectorParameters(*fs);
*fs << "}";
bool DetectorParameters::writeDetectorParameters(FileStorage& fs, const String& name)
{
CV_Assert(fs.isOpened());
if (!name.empty())
fs << name << "{";
bool res = readWrite(*this, nullptr, &fs);
if (!name.empty())
fs << "}";
return res;
}
bool DetectorParameters::writeDetectorParameters(FileStorage &fs) {
if (!fs.isOpened())
return false;
return readWrite(*this, nullptr, makePtr<FileStorage>(fs));
}
static inline bool readWrite(RefineParameters& refineParameters, const Ptr<FileNode>& readNode,
const Ptr<FileStorage>& writeStorage = nullptr) {
CV_Assert(!readNode.empty() || !writeStorage.empty());
static inline bool readWrite(RefineParameters& refineParameters, const FileNode* readNode,
FileStorage* writeStorage = nullptr)
{
CV_Assert(readNode || writeStorage);
bool check = false;
check |= readWriteParameter("minRepDistance", refineParameters.minRepDistance, *readNode, *writeStorage);
check |= readWriteParameter("errorCorrectionRate", refineParameters.errorCorrectionRate, *readNode, *writeStorage);
check |= readWriteParameter("checkAllOrders", refineParameters.checkAllOrders, *readNode, *writeStorage);
check |= readWriteParameter("minRepDistance", refineParameters.minRepDistance, readNode, writeStorage);
check |= readWriteParameter("errorCorrectionRate", refineParameters.errorCorrectionRate, readNode, writeStorage);
check |= readWriteParameter("checkAllOrders", refineParameters.checkAllOrders, readNode, writeStorage);
return check;
}
@ -94,27 +90,21 @@ RefineParameters::RefineParameters(float _minRepDistance, float _errorCorrection
minRepDistance(_minRepDistance), errorCorrectionRate(_errorCorrectionRate),
checkAllOrders(_checkAllOrders){}
bool RefineParameters::readRefineParameters(const FileNode &fn) {
if(fn.empty())
bool RefineParameters::readRefineParameters(const FileNode &fn)
{
if (fn.empty())
return false;
Ptr<FileNode> pfn = makePtr<FileNode>(fn);
return readWrite(*this, pfn);
return readWrite(*this, &fn);
}
bool RefineParameters::writeRefineParameters(FileStorage &fs) {
if(!fs.isOpened())
return false;
return readWrite(*this, nullptr, makePtr<FileStorage>(fs));
}
bool RefineParameters::writeRefineParameters(const Ptr<FileStorage>& fs, const String& name) {
if(fs.empty())
return false;
if(name.empty())
return writeRefineParameters(*fs);
*fs << name << "{";
bool res = writeRefineParameters(*fs);
*fs << "}";
bool RefineParameters::writeRefineParameters(FileStorage& fs, const String& name)
{
CV_Assert(fs.isOpened());
if (!name.empty())
fs << name << "{";
bool res = readWrite(*this, nullptr, &fs);
if (!name.empty())
fs << "}";
return res;
}
@ -1279,9 +1269,9 @@ void ArucoDetector::refineDetectedMarkers(InputArray _image, const Ptr<Board> &_
}
}
void ArucoDetector::write(FileStorage &fs) const {
Ptr<FileStorage> pfs = makePtr<FileStorage>(fs);
arucoDetectorImpl->dictionary.writeDictionary(pfs);
void ArucoDetector::write(FileStorage &fs) const
{
arucoDetectorImpl->dictionary.writeDictionary(fs);
arucoDetectorImpl->detectorParams.writeDetectorParameters(fs);
arucoDetectorImpl->refineParams.writeRefineParameters(fs);
}

@ -46,7 +46,13 @@ bool Dictionary::readDictionary(const cv::FileNode& fn) {
return true;
}
void Dictionary::writeDictionary(FileStorage &fs) {
void Dictionary::writeDictionary(FileStorage& fs, const String &name)
{
CV_Assert(fs.isOpened());
if (!name.empty())
fs << name << "{";
fs << "nmarkers" << bytesList.rows;
fs << "markersize" << markerSize;
fs << "maxCorrectionBits" << maxCorrectionBits;
@ -61,14 +67,9 @@ void Dictionary::writeDictionary(FileStorage &fs) {
marker.push_back(bitMarker.at<uint8_t>(j) + '0');
fs << markerName << marker;
}
}
void Dictionary::writeDictionary(Ptr<FileStorage>& fs, const String &name) {
if(name.empty())
return writeDictionary(*fs);
*fs << name << "{";
writeDictionary(*fs);
*fs << "}";
if (!name.empty())
fs << "}";
}

@ -31,10 +31,12 @@ inline bool readParameter(const std::string& name, T& parameter, const FileNode&
}
template<typename T>
inline bool readWriteParameter(const std::string& name, T& parameter, const FileNode& readNode, FileStorage& writeStorage) {
if (!readNode.empty())
return readParameter(name, parameter, readNode);
writeStorage << name << parameter;
inline bool readWriteParameter(const std::string& name, T& parameter, const FileNode* readNode, FileStorage* writeStorage)
{
if (readNode)
return readParameter(name, parameter, *readNode);
CV_Assert(writeStorage);
*writeStorage << name << parameter;
return true;
}

Loading…
Cancel
Save