Thread: How to find the coordinates of a point w.r.t another point on an image using OpenCV

  1. #1
    Registered User capt.jack's Avatar
    Join Date
    Jun 2010
    Posts
    13

    How to find the coordinates of a point w.r.t another point on an image using OpenCV

    Hi,
    I wrote a program for detecting circles using Hough Transform using OpenCV in C. The program inputs 3 images, each image contains a fixed small circle and a big circle with variable position. The program then recognizes both the circles and marks the centres of both the circles. Now what I want to do is: in the output image the (x,y) coordinates of the centre of the bigger circle should be displayed with respect to the centre of the fixed smaller circle.

    In simple words, taking the centre of the smaller circle as the origin(0,0), I want to find the coordinates of the center of the bigger circle

    Here's the code for 'circle.cpp'

    Code:
    #include <cv.h>
    #include <highgui.h>
    #include <math.h>
    
    int main(int argc, char** argv)
    {
        IplImage* img;
        int n=3;
        char input[21],output[21];    
    
        for(int l=1;l<=n;l++)
        {    
          sprintf(input,"Frame%d.jpg",l);  // Inputs Images
    
          if(  (img=cvLoadImage(input))!= 0)
        {
            IplImage* gray = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );
            IplImage* canny=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
            IplImage* rgbcanny=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
            CvMemStorage* storage = cvCreateMemStorage(0);
            cvCvtColor( img, gray, CV_BGR2GRAY );
            cvSmooth( gray, gray, CV_GAUSSIAN, 9, 9 ); // smooth it, otherwise a lot of false circles may be detected
            cvCanny(gray,canny,50,100,3);
    
            CvSeq* circles = cvHoughCircles( canny, storage, CV_HOUGH_GRADIENT, 2, gray->height/4, 200, 100 );
            int i;
            cvCvtColor(canny,rgbcanny,CV_GRAY2BGR);
            for( i = 0; i < circles->total; i++ )
            {
                 float* p = (float*)cvGetSeqElem( circles, i );
                 cvCircle( rgbcanny, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(0,255,0), -1, 8, 0 );
                 cvCircle( rgbcanny, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
            }
            cvNamedWindow( "circles", 1 );
            cvShowImage( "circles", rgbcanny );
    
            //Displays Output images
            sprintf(output,"circle%d.jpg",l);  
            cvSaveImage(output,rgbcanny);    
            cvWaitKey(0);
        }
    }
        return 0;
    }
    And here are the 2 input and 2 output images:
    How to find the coordinates of a point w.r.t another point on an image using OpenCV-frame2-jpg How to find the coordinates of a point w.r.t another point on an image using OpenCV-frame1-jpg How to find the coordinates of a point w.r.t another point on an image using OpenCV-circle1-jpg How to find the coordinates of a point w.r.t another point on an image using OpenCV-circle2-jpg

    Please suggest what changes should I make in the code so that I can display in the output image the (x,y) coordinates of the center of the big circle w.r.t. the center of the small circle taken as origin(0,0)

    Thanx a lot

  2. #2
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Location
    Seattle, Washington
    Posts
    59
    I think we'd be more able to help if you commented this a bit better.
    This is a really specific question, and is hardly based on C Programming at all, so without knowing the inner workings of this OpenCV, and only having about four extremely brief comments to go on, I got no real advice.
    I might suggest declaring your variables at the top of their scope in C programs, but I guess this isn't necessary in C99.
    I'd recommend finding a board or thread more dedicated to OpenCV.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I have to agree with inequity, if you're stuck on the detail of how to use the library, then a forum which supports that library would be the best place to try first.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i find one point inside an arc..?
    By jana.malli in forum C++ Programming
    Replies: 1
    Last Post: 02-09-2011, 01:46 AM
  2. program to find the saddle point of a matrix ??
    By intermediatech in forum C Programming
    Replies: 28
    Last Post: 05-05-2010, 05:26 PM
  3. Struct Program to find Point in Rectangle
    By DMJKobam in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2009, 08:56 PM
  4. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 01:25 PM
  5. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM

Tags for this Thread