在角点检测开始前先定义了一个MorphoFeatures类:
class MorphoFeatures {
private:
//用于生成二值图像的阈值
int thresholded;
//角点检测中用到的结构元素
Mat cross;
Mat diamond;
Mat square;
Mat x;
public:
MorphoFeatures() {
int thresholded = -1;
Mat cross(5, 5, CV_8U, Scalar(0));
Mat diamond(5, 5, CV_8U, Scalar(255));
Mat square(5, 5, CV_8U, Scalar(255));
Mat x(5, 5, CV_8U, Scalar(0));
//创建十字形元素
for (int i = 0; i < 5; i++) {
cross.at<uchar>(2, i) = 255;
cross.at<uchar>(i, 2) = 255;
}
//创建菱形元素
diamond.at<uchar>(0, 0) = 0;
diamond.at<uchar>(0, 1) = 0;
diamond.at<uchar>(1, 0) = 0;
diamond.at<uchar>(4, 4) = 0;
diamond.at<uchar>(3, 4) = 0;
diamond.at<uchar>(4, 3) = 0;
diamond.at<uchar>(4, 0) = 0;
diamond.at<uchar>(4, 1) = 0;
diamond.at<uchar>(3, 0) = 0;
diamond.at<uchar>(0, 4) = 0;
diamond.at<uchar>(0, 3) = 0;
diamond.at<uchar>(1, 4) = 0;
//创建x形元素
for (int i = 0; i < 5; i++) {
x.at<uchar>(i, i) = 255;
x.at<uchar>(4 - i, i) = 255;
}
}
int setThreshold(int thresholded);
void applyThreshold(Mat &result);
Mat getEdges(const Mat &image);
Mat getCorner(const Mat &image);
void drawOnImage(const Mat &binary, Mat &image);
};
在这个类中定义了一个构造函数MorphoFeatures(),用来初始化参数,也就是定义了四个不同形状的元素做为后面进行膨胀与腐蚀操作时的结构元素。在主程序设置了断点,观察构造函数执行时初始化参数的动作有没有进行,发现并没有执行构造函数,不知道为什么,请有看到此文的大神给予指导,谢谢!后面附图看断点处的参数状况:
MorphoFeatures类定义的对象morpho里面的参数值看起来构造函数根本没有执行,是怎么回事呢?