c++ - 转换为 vector <2f>

标签 c++ opencv

我正在使用 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/

相关文章:

c++ - C++ 中的 11db 错误; Xcode。

c++ - 如何在 Windows 上安装 MySQL C++ 驱动程序

c++ - 可移植分支预测提示

python - 我如何在 python 3.8 上导入 cv2

opencv - OpenCV const矩阵-不总是const吗?

c++ - 为什么STL中队列有front而priority queue有top?

c++ - 如何通过引用构造 vector 的子范围?

python - 如何将本地编译的 OpenCV 添加到 Python 路径?

java - 无法在 Android 上使用 OpenCV 在 for 循环中裁剪图像

python - 如何使用多处理并行处理 OpenCV 图像?