我正在使用 OpenCV 的 highgui include 来获取图像上的鼠标点击位置。我已经定义了一个 vector<2f> ,我想存储在其中单击的点,但不幸的是,我认为我做错了什么:
void on_mouse(int mouseEvent, int x, int y, int flags, void* param)
{
if( mouseEvent == CV_EVENT_LBUTTONDOWN) {
printf("Clicked image at (%d,%d)\n", x, y);
(vector<Point2f>*)param.push_back(Point2f(x,y));
}
}
我的编译器在 param 上给我一个错误,并说错误:表达式必须具有类类型。 谁能建议如何将其转换为 vector 结构?或者我做错了什么?
最佳答案
(vector<Point2f>*)param.push_back(Point2f(x,y));
应该是:
reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y));
关于c++ - 转换为 vector <2f>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13634600/