1

I am new to OpenCV so can anyone help with the answer given here for better understanding.I am not able to get what is "angle" and "square" in following code

                if (approx.size() == 4 &&
                fabs(contourArea(Mat(approx))) > 1000 &&
                isContourConvex(Mat(approx)))
            {
                double maxCosine = 0;

                for (int j = 2; j < 5; j++)
                {
                    CGFloat angle;
                    double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));
                    maxCosine = MAX(maxCosine, cosine);
                }

                if (maxCosine < 0.3)
                    squares.push_back(approx);
            }
Community
  • 1
  • 1
Zღk
  • 805
  • 7
  • 23

2 Answers2

0

Angle is a function that is at the top of the question. It takes 3 points and returns an angle value.

It looks like squares is some sort of data structure of vectors. My C++ is rusty, so I can't parse that type declaration without doing some more research (and I haven't had enough coffee for that.)

Duncan C
  • 115,063
  • 19
  • 151
  • 241
0

Worked on my question last night and got my answer here it is

std::vector<std::vector<cv::Point> > squares;
double angle( cv::Point pt1, cv::Point pt2, cv::Point pt0 ) {
double dx1 = pt1.x - pt0.x;
double dy1 = pt1.y - pt0.y;
double dx2 = pt2.x - pt0.x;
double dy2 = pt2.y - pt0.y;
return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);

}

Zღk
  • 805
  • 7
  • 23