在openCV的canny检测中,我想用一个类完成这个事,但是传参的时候出现若干问题
class MyCanny{
private:
Mat src, src_gray;
Mat dst, detected_edges; // input and output matrix
int lowThreshold = 0;
const int max_lowThreshold = 100;
const int ratio = 3;
const int kernel_size = 3;
const char* window_name = "Edge Map"; // some parameters
public:
explicit MyCanny(const Mat &img); // 构造函数,用于对类的对象赋值,由于数据是private的,只能通过此种方式赋值
MyCanny(); // constructor
Mat get_dst(); // 可以不需要通过static静态就获得dst矩阵
void canny_process(); // 用于进行主要的CannyEdge处理过程
void canny_threshold(int pos, void* userdata);
}
然后是函数成员
void MyCanny::canny_process() {
createTrackbar("Min Threshold:", window_name, &lowThreshold, max_lowThreshold, canny_threshold);
//(Reference to non-static function member must be called, so I have to make this function static,
//but static function can't access data from class)
canny_threshold(0, nullptr);
waitKey(0);
}
void MyCanny::canny_threshold(int pos, void *userdata) {
//(how to send data from class to this function if I made this function static)
blur(src_gray, detected_edges, Size(3, 3));
Canny(detected_edges, detected_edges, lowThreshold, lowThreshold * ratio, kernel_size);
dst = Scalar::all(0);
src.copyTo(dst, detected_edges);
imshow(window_name, dst);
}
- 如果
canny_threshold
这个函数不是静态static的,createTrackbar的最后一个参数就不能引用 - 如果它静态了,就没法获得类的数据了
所以我该怎么给他传参?,肯定是通过这个void* userdata了