I want to use cv :: setMouseCallback inside my settings class to select an image area. This is my code:
void Settings::on_buttonXML_clicked(){ cv::VideoCapture webcam; webcam.open(INDEX); webcam.read(src); color = Scalar(0,0,255); coor_num = 0; xmlPath="C:/myregion.xml"; cv::namedWindow("imageWindow", CV_WINDOW_AUTOSIZE ); cv::imshow("imageWindow", src); cv::setMouseCallback( "imageWindow", onMouse, 0 ); cv::waitKey(0); } void Settings::onMouse(int event, int x, int y, int, void* ) { if (event == CV_EVENT_LBUTTONUP) { Point2f p(x, y); coor.push_back(p); line(src,p,p,color); if(coor.size()>1) line(src, p, coor[coor.size()-2], color); imshow("imageWindow", src); } else if (event == CV_EVENT_RBUTTONUP && coor.size()>2){ line(src, coor[0], coor[coor.size()-1], color); getPointsInContour(coor); imshow("imageWindow", src); waitKey(2000); exit(0); } } void Settings::savePointsAsXML(vector<Point2f> & contour){ TiXmlDocument doc; TiXmlDeclaration decl("1.0", "", ""); doc.InsertEndChild(decl); for(int i = 0; i < contour.size(); i++) { TiXmlElement point("point"); point.SetAttribute("x",contour[i].x); point.SetAttribute("y",contour[i].y); doc.InsertEndChild(point); } if(doc.SaveFile(xmlPath.c_str())) cout << "file saved succesfully.\n"; else cout << "file not saved, something went wrong!\n"; } void Settings::getPointsInContour(vector<Point2f> & contour){ vector<Point2f> insideContour; for(int j = 0; j < src.rows; j++){ for(int i = 0; i < src.cols; i++){ Point2f p(i,j); if(cv::pointPolygonTest(contour,p,false) >= 0)
I get tons of undefined links to Settings: coor, Settings: src, Settings: color. I am having trouble understanding what should be static to work. This is my headline:
class Settings { private: static void onMouse(int event, int x, int y, int, void* ); static void savePointsAsXML(std::vector<cv::Point2f> & contour); static void getPointsInContour(std::vector<cv::Point2f> & contour); static cv::Scalar color; static std::vector<cv::Point2f> coor; static int coor_num; static std::string xmlPath; static cv::Mat src;
What am I missing in my code?