2014-12-08 3 views
0

this OOP를 만들려고 했으므로 트랙 바에 대한 콜백 함수를 구현하는 클래스를 만들었습니다. OOP opencv 트랙 바

내 클래스

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); 
} 

내가

오류 5 오류 LNK2001 얻을

createTrackbar(" Canny thresh:", "Source", &thresh, max_thresh, &Contours::callback); 

함수를 호출 할 수 있습니다 : 확인되지 않은 외부 기호를 "공공 정적 클래스 이력서 :: 매트 윤곽 :: src_gray "(? src_gray @ Contours @@ 2VMat @ cv @@ A) D : \ Licenta \ 손 기호 인식 \ Algoritmi.obj 손 기호 인식

오류 6 오류 LNK2001 : 확인되지 않은 외부 기호 "공공 정적 INT 윤곽선 :: 타작"D (윤곽 @@ 2HA @ 타작은?) : \ Licenta \ 손

어떤 아이디어 인식에 서명 Algoritmi.obj 손 \ 인식에 서명 왜?

+1

사람들은 링커 오류입니다. 코드가 컴파일되고 아마도 프로젝트 설정 문제 일 것입니다. Visual Studio에서 좋은 점은 오류 코드가 의미하는 바를 찾기 위해 검색 할 수 있다는 것입니다 (예 : LNK2001). – Simon

+0

imgproc 및 highui 라이브러리를 포함 시켰습니까? – GPPK

+0

@GPPK 예, 했어요. –

답변

0

어쩌면 '정적 콜백'문제에 대한 다른 접근 방법을 사용

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); 
    ... 
+0

이것은 완벽하게 작동합니다. & cnt 매개 변수를 이해하지 못하는데, 어디에서 왔으며 왜 거기에 넣어야합니까? . –

+0

컨투어 객체의 주소를 createTrackbar()에 넘겨 주면 콜백 함수로 전달됩니다. – berak

관련 문제