帮助理解以下代码? [英] Help in understanding the following code?
问题描述
我试图将鼠标位置存储在矢量中,然后调用矢量元素来显示我的点数。我偶然发现了stackoverflow.com中的这个帖子( http://stackoverflow.com/questions/24586013/opencv-storing-the-coordinates-of-the-points-clicked-by-mouse-left-button [ ^ ]
我无法理解以下代码行,如果有人能解释代码的含义,我将非常感激。
I was trying to store my mouse positions in a vector and then call the vector elements to display my points. I stumbled upon this thread in stackoverflow.com (http://stackoverflow.com/questions/24586013/opencv-storing-the-coordinates-of-the-points-clicked-by-mouse-left-button[^]
I couldn't understand the following lines of code and would really appreciate if someone can explain me the meaning of the code.
void onMouse(int evt, int x, int y, int flags, void* param) {
if(evt == CV_EVENT_LBUTTONDOWN) {
std::vector<cv::Point>* ptPtr = (std::vector<cv::Point>*)param; // Especially this line
ptPtr->push_back(cv::Point(x,y));
}
}
[您的代码已损坏,因此我将其修复为原始版本]
[Your code was corrupted, so I fixed it back to the original]
推荐答案
基本上这行发生了什么
Basically what happens in this line
std::vector<cv::point xmlns:cv="#unknown">* ptPtr = (std::vector<cv::point>*)param;</cv::point></cv::point>
是输入参数 param 被类型转换为类型的指针std :: vector< cv :: Point>
然后将坐标(x,y)添加到数组/向量中。
在这里,您可以阅读有关 std :: vector 的更多信息[ ^ ]
is that the input argument param is being type cast into a pointer of type std::vector<cv::Point>
Then the coordinates (x,y) is added to the array/vector.
Here you can read more about std::vector[^]
这篇关于帮助理解以下代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!