views:

108

answers:

3

could any one explain me logic behind this code??

   pt1.x = cvRound(x0 + 1000*(-b));
   pt1.y = cvRound(y0 + 1000*(a));
   pt2.x = cvRound(x0 - 1000*(-b));
   pt2.y = cvRound(y0 - 1000*(a));
+1  A: 

It looks like a and b are threshold values that are being used to move pt1 in one direction (inwards or outwards) and pt2 in the opposite direction.

Perhaps they are being used to increase/decrease the area of a rectangle for a bounds check?

Justin Ethier
they changed it to cartesian and then y they added a*1000, stuff like that,lines for( i = 0; i < MIN(lines->total,100); i++ ) { float* line = (float*)cvGetSeqElem(lines,i); float rho = line[0]; float theta = line[1]; CvPoint pt1, pt2; double a = cos(theta), b = sin(theta); double x0 = a*rho, y0 = b*rho; pt1.x = cvRound(x0 + 1000*(-b)); pt1.y = cvRound(y0 + 1000*(a)); pt2.x = cvRound(x0 - 1000*(-b)); pt2.y = cvRound(y0 - 1000*(a)); }
paddu
+1  A: 

You have a point defined by x0, y0. You're now creating two other point objects, one at (-b*1000, a*1000) and one at (b*1000, -a*1000) relative to the original point. Presumably the 1000 is to fix problems of scale, as the values a and b are on a different scale than the points x0, y0.

JSBangs
hi thanks, its from hough lines opencv code, could you explain me clearly
paddu
they changed it to cartesian and then y they added a*1000, stuff like that,lines for( i = 0; i < MIN(lines->total,100); i++ ) { float* line = (float*)cvGetSeqElem(lines,i); float rho = line[0]; float theta = line[1]; CvPoint pt1, pt2; double a = cos(theta), b = sin(theta); double x0 = a*rho, y0 = b*rho; pt1.x = cvRound(x0 + 1000*(-b)); pt1.y = cvRound(y0 + 1000*(a)); pt2.x = cvRound(x0 - 1000*(-b)); pt2.y = cvRound(y0 - 1000*(a)); }
paddu
please help me in expaining the logic behind the code
paddu
can u help me in loginc behind adding a*1000, after changing to cartesian
paddu
@paddu, there's no way to know why they are multiplying by 1000 just based on this code sample. I'd need more context, and really this is something you'll probably have to figure out for yourself.
JSBangs
1000 or other numerical value, its not matter, but after converting polar into cartesian coordinates, which should some x0 = rho * cos(theta), but my question is why they are multiplying 1000*a to rho * cos(theta).
paddu
A: 

hi thanks for your answer, but am haivng a doubt when i see the code they changed it to cartesian and normally when we write a slope intercept form line equation, this is confusing me.

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

int main(int argc, char** argv)
{
    IplImage* src;
    if( argc == 2 && (src=cvLoadImage(argv[1], 0))!= 0)
    {
        IplImage* dst = cvCreateImage( cvGetSize(src), 8, 1 );
        IplImage* color_dst = cvCreateImage( cvGetSize(src), 8, 3 );
        CvMemStorage* storage = cvCreateMemStorage(0);
        CvSeq* lines = 0;
        int i;
        cvCanny( src, dst, 50, 200, 3 );
        cvCvtColor( dst, color_dst, CV_GRAY2BGR );
#if 1
        lines = cvHoughLines2( dst,
                               storage,
                               CV_HOUGH_STANDARD,
                               1,
                               CV_PI/180,
                               100,
                               0,
                               0 );

        for( i = 0; i < MIN(lines->total,100); i++ )
        {
            float* line = (float*)cvGetSeqElem(lines,i);
            float rho = line[0];
            float theta = line[1];
            CvPoint pt1, pt2;
            double a = cos(theta), b = sin(theta);
            double x0 = a*rho, y0 = b*rho;
            pt1.x = cvRound(x0 + 1000*(-b));
            pt1.y = cvRound(y0 + 1000*(a));
            pt2.x = cvRound(x0 - 1000*(-b));
            pt2.y = cvRound(y0 - 1000*(a));
            cvLine( color_dst, pt1, pt2, CV_RGB(255,0,0), 3, 8 );
        }
paddu
@paddu: just fyi, instead of creating an additional answer, you should append this to your original question (click `edit` under the question).
egrunin