Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
C++
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]
Posted
Updated 17-Sep-14 16:57pm
v4
Comments
barneyman 17-Sep-14 22:58pm    
void* is generally used as a mechanism to pass arbitrary data around ... the param in this case is actually a memory pointer to a vector of cv::points

The function is taking that pointer, materialising/casting it to ptPtr and then adding a new point to the back of the vector

1 solution

Basically what happens in this line
C++
std::vector<cv::point xmlns:cv="#unknown">* ptPtr = (std::vector<cv::point>*)param;</cv::point></cv::point>

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900