-3

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);    
}
Tejendra
  • 1,874
  • 1
  • 20
  • 32
jope
  • 33
  • 1
  • 3
  • Please add some info about what exactly this library is you are using. I just guessed it's OpenCV. – CherryDT May 09 '16 at 17:09
  • I'm not sure why sprintf has been chosen instead of stringstream, but when changing format put inside the sss string, you have to take in to consideration if there is enough memory to put two integers instead of one in there. – zoska May 09 '16 at 17:11
  • Thanks for all answers. This was the only alternative that I found in some tutorial to print my text near at the point that I create. Anyway if you have any and better option for this, it will be very nice. I really want to substitute the number of the point by the coordinate x,y of the same point. – jope May 09 '16 at 17:32

1 Answers1

0

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!

CherryDT
  • 25,571
  • 5
  • 49
  • 74