Search code examples
c++coordinatestracker

C++ point coordinates


I made a simple tracker. So now i need to get the coordinates of the same points. I need to print the same coordinates like (x,y) instead the number of the point.

How can i do it. I'm using Linux.

Please be a little specific because I am learning C++ and I am not an expert.

for(i = 0; i < n; i++){    
    if(visi.at<int>(i,0) == 0) 
        continue;
    p1 = cv::Point(shape.at<double>(i,0),shape.at<double>(i+n,0));

    c1 = CV_RGB(255,255,0); 
    c2 = CV_RGB(255,0,0);
    c3 = CV_RGB(0,0,0);
    c4 = CV_RGB(255,255,255);

    cv::circle(image,p1,1,c3);
    cv::circle(image,p1,2,c1); 
    cv::circle(image,p1,3,c2);  

    sprintf(sss,"%d",i); text = sss;
    cv::putText(image,text,p1,CV_FONT_HERSHEY_SIMPLEX,0.3,c4);    
}

Solution

  • I don't know the library, just googled cv::Point, but I'd guess:

    sprintf(sss, "(%d,%d)", p1.x, p1.y);
    

    See http://docs.opencv.org/3.1.0/db/d4e/classcv_1_1Point__.html#pub-attribs

    EDIT: As commenter zoska correctly pointed out, you also have to make sure that there is enough space allocated for the sss string buffer to hold the whole formatted value!