铸造为矢量(Casting as a vector)

编程入门 行业动态 更新时间:2024-10-26 04:23:20
铸造为矢量<2f>(Casting as a vector<2f>)

我正在使用OpenCV的highgui包括能够在我的图像上获得鼠标点击位置。 我已经定义了一个向量<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上给出了一个错误,并说错误:Expression必须具有类类型。 任何人都可以建议如何投射为矢量结构? 或者我做错了什么?

I'm using OpenCV's highgui include to be able to get mouse click locations on my image. I've defined a vector<2f> that I would like to store the points that have been clicked within, but unfortunately, I think I'm doing something wrong:

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

My compiler gives me an error on param and says Error: Expression must have class type. Can anyone suggest how else to cast as a vector structure? or what I am doing incorrectly?

最满意答案

(vector<Point2f>*)param.push_back(Point2f(x,y));

应该:

reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y)); (vector<Point2f>*)param.push_back(Point2f(x,y));

Should be:

reinterpret_cast<vector<Point2f>*>(param)->push_back(Point2f(x,y));

更多推荐

本文发布于:2023-08-07 13:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464898.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矢量   Casting   vector

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!