OOP opencv trackbar
OOP opencv trackbar
我正在尝试制作这个OOP,所以我创建了一个实现跟踪栏回调函数的类。
这是我的课
class Contours
{
public:
static Mat src_gray;
static int thresh;
Contours(Mat, int);
~Contours(void);
static void callback(int, void* );
private:
};
Contours::Contours(Mat src_gray,int thresh){
this->src_gray=src_gray;
this->thresh=thresh;
}
Contours::~Contours(void){}
void Contours::callback(int, void*)
{int largest_area=0;
int largest_contour_index=0;
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Detect edges using canny
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
/// Find contours
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// Draw contours
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
cout<<contours.size()<<endl;
for( int i = 0; i< contours.size(); i++ )
{
double a=contourArea( contours[i],false); // Find the area of contour
if(a>largest_area){
largest_area=a;
largest_contour_index=i; } //Store the index of largest contour
//Scalar color = Scalar(255,255,255 );
//drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
cout<<"cnt maxim: "<<largest_contour_index<<endl;
Scalar color = Scalar(255,255,255 );
drawContours( drawing, contours, largest_contour_index, color, 2, 8, hierarchy, 0, Point() );
/// Show in a window
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
imshow( "Contours", drawing );
//imwrite("sada.png",drawing);
}
并调用函数
createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, &Contours::callback );
我得到
错误5 错误 LNK2001:未解析的外部符号"公共:静态类 cv::垫子轮廓::src_gray"(?src_gray@Contours@@2VMat@cv@@A) D:\Licenta\手部符号识别\Algoritmi.obj 手部符号识别
错误6 错误 LNK2001:未解析的外部符号"public: static int Contours::thresh" (?thresh@Contours@@2HA) D:\Licenta\手部符号识别\Algoritmi.obj 手部符号识别
知道为什么吗?
也许使用不同的方法来解决"静态回调"问题:
class Contours
{
public:
Mat src_gray; // non-static
int thresh;
Contours(Mat, int);
void callback(int, void* ); // non-static
};
void callback(int value, void*ptr) // static global
{
Contours* cnt = (Contours*)ptr; // cast 'this'
cnt->callback(value,0); // call non-static member
}
int main()
{
Mat gray = ...
Contours cnt(gray,17);
// now pass the address of cnt as additional void* Ptr:
createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, callback, &cnt );
...
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 安装opencv失败-粘贴CMakeError.log的内容
- C++中的openCV Mat访问冲突
- OpenCV Android C++ imwrite not found
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- C++ OpenCV 卡尔曼滤波器构造函数错误
- OOP opencv trackbar
- opencv HoughCircle and trackbar
- OpenCV Trackbar回调函数和意外的状态变化