Ask Your Question
1

Hough Circles Small Question

asked 2014-10-21 08:37:51 -0600

Moonguard gravatar image

updated 2020-11-17 04:05:25 -0600

#include <cv.h>
#include <highgui.h>
#include <math.h>

using namespace cv;

int main(int argc, char** argv)
{
    Mat img, gray;
    if( argc != 2 && !(img=imread(argv[1], 1)).data)
        return -1;
    cvtColor(img, gray, CV_BGR2GRAY);
    // smooth it, otherwise a lot of false circles may be detected
    GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
    vector<Vec3f> circles;
    HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
                 2, **gray->rows/4**, 200, 100 );
    for( size_t i = 0; i < circles.size(); i++ )
    {
         Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
         int radius = cvRound(circles[i][2]);
         // draw the circle center
         circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
         // draw the circle outline
         circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
    }
    namedWindow( "circles", 1 );
    imshow( "circles", img );
    return 0;
}

In this example what is "->" sign at "gray->rows/4 " part and what does it do? I am writing a program using that method and I simply copied that part but I have no idea what that is and I would like to know it.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-10-21 09:15:23 -0600

thdrksdfthmn gravatar image

It is basic C++: When you are using a pointer to a class, the class members are accessed by -> and not by ..

For better understanding, please read this and everything linked to that that you can find on Google

But in your case there is something wrong; it should be . instead of ->. Probably, as you mentioned, you have copied the code from more sources and in one place there was something like a pointer to the gray, but I do not understand why.

edit flag offensive delete link more

Comments

Thanks, its an openCV documentation. You can find the example here: http://docs.opencv.org/modules/imgproc/doc/feature_detection.html

I simply did not understand the pointer part, so I do not know why they used -> instead of.

Moonguard gravatar imageMoonguard ( 2014-10-21 10:19:37 -0600 )edit

Interesting, I have no why is it like that, I think it is a bug, but if anyone knows why, please tell us too

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-10-21 10:34:24 -0600 )edit

About the pointers, the idea is they are "variables" that store the address of some object, like references. It is not a professional affirmation, but this made it more clear for me to understand them, hope that for you too. They are very useful when using interfaces and polymorphism.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-10-21 10:39:39 -0600 )edit

Yeah I try to think like that too. Its a bit confusing though.

Moonguard gravatar imageMoonguard ( 2014-10-22 01:44:29 -0600 )edit

Question Tools

Stats

Asked: 2014-10-21 08:37:51 -0600

Seen: 284 times

Last updated: Oct 21 '14