You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.3 KiB
C

/*!
* \file CrossMarkDetector.h
* \date 2020/07/20
*
* \author Lin, Chi
* Contact: lin.chi@hzleaper.com
*
*
* \note
*/
#ifndef __CrossMarkDetector_h_
#define __CrossMarkDetector_h_
#include "CVUtils.h"
#include "StdUtils.h"
#include "CyclopsEnums.h"
#include "CyclopsModules.h"
#include "DetectRoi.h"
class CrossMarkDetector : public ICyclopsModuleInstance
{
public:
/*! \fn setUseAutoThreshold
* Define whether to user auto-thresholding for binarize image, default to true, see also getUseAutoThreshold()
* \fn getUseAutoThreshold
* Get whether to user auto-thresholding for binarize image, see also setUseAutoThreshold()
*/
DECLARE_PARAMETER(bool, UseAutoThreshold)
/*! \fn setCMColor
* Define color range of cross mark, works if it's not using auto-thresholding, default to [128, 150], see also getCMColor()
* \fn getCMColor
* Get color range of cross mark, works if it's not using auto-thresholding, see also setCMColor()
*/
DECLARE_PARAMETER(Range, CMColor)
/*! \fn setPolarity
* Define polarity of cross mark, either black cross mark on white background(Polarity::Black2White, default),
* or white cross mark on black background(Polarity::White2Black), see also getPolarity()
* \fn getPolarity
* Get value of polarity of circle edge, see also setPolarity()
*/
DECLARE_PARAMETER2(Polarity, Polarity, Polarity::Black2White, Polarity::White2Black)
/*! \fn setDetectMethod
* Define detection method, default to CMDetectMethod::GradientBased, see also getDetectMethod()
* \fn getDetectMethod
* Get detection method, see also setDetectMethod()
*/
enum CMDetectMethod
{
GradientBased = 0,
GrayValueBased,
};
DECLARE_PARAMETER2(CMDetectMethod, Method, CMDetectMethod::GradientBased, CMDetectMethod::GrayValueBased)
/*! \fn setUseSoftThreshold
* Define whether to use soft thresholding, default to false, see also getUseSoftThreshold()
* \fn getUseSoftThreshold
* Get value of whether to use soft thresholding, see also setUseSoftThreshold()
*/
DECLARE_PARAMETER(bool, UseSoftThreshold)
/*! \fn setSoftThresholdRange
* Define the weighted range of soft thresholding, default to 5, same as BlobDetector::setSoftThresholdRange()
* \fn getSoftThresholdRange
* Get value of the weighted range of soft thresholding, see also setSoftThresholdRange()
*/
DECLARE_PARAMETER(int, SoftThresholdRange)
/*! \fn setSizeRange
* Define optinal size range of cross mark, default to [0, 0] means no specification, see also getRange()
* \fn getSize
* Get optinal size range of cross mark, see also setRange()
*/
DECLARE_PARAMETER(Range, SizeRange)
public:
CrossMarkDetector() :
mUseAutoThreshold(true), mCMColor(128, 150), mPolarity(Polarity::Black2White), mMethod(CMDetectMethod::GradientBased),
mUseSoftThreshold(false), mSoftThresholdRange(5), mSizeRange(0, 0)
{}
virtual ~CrossMarkDetector() {}
/*! \fn serializeToMemory
* Serialize the cross mark detector into a in-memory string, see also deserializeFromMemory()
* @param str used to take the output serialization result
* @return true for succeed, false for fail
* \fn serializeToFile
* Serialize the cross mark detector into a text file, see also deserializeFromFile()
* @param filename file name (full path) where we will write the data
* @return true for succeed, false for fail
* \fn deserializeFromMemory
* Deserialize the cross mark detector from in-memory string, see also serializeToMemory()
* @param str in-memory string
* @return true for succeed, false for fail
* \fn deserializeFromFile
* Deserialize the cross mark detector from a text file, see also serializeToFile()
* @param filename file name (full path) where we will read the data
* @return true for succeed, false for fail
*/
DECL_SERIALIZE_FUNCS
virtual bool detectBest(const Mat& img,
Point2f& bestCM, float& hAngle, float& vAngle,
Mat* mask = nullptr);
/** @overload */
virtual bool detectBest(const Mat& img, const vector<Point2f>& roi,
Point2f& bestCM, float& hAngle, float& vAngle);
/** @overload */
virtual bool detectBest(const Mat& img, DetectRoi& droi,
Point2f& bestCM, float& hAngle, float& vAngle);
//! Smart pointer to hold an instance of CrossMarkDetector
typedef std::shared_ptr<CrossMarkDetector> Ptr;
DECL_GET_INSTANCE(CrossMarkDetector::Ptr)
private:
virtual bool serialize(FileStorage& fs);
virtual bool deserialize(const FileNode& fs);
};
#endif // CrossMarkDetector_h_