Я пытаюсь понять код, который использует библиотеку OpenCV для идентификации квадратов на любом изображении. Эта линия ближе к концу - «gray = gray0> = (l + 1) * 255/N;». Я никогда не видел> = используется таким образом, и не похоже, что он делает сравнение. Что делает этот оператор в этой строке?Что значит> = означает в этом контексте
static void findSquares(const Mat& image, vector<vector<Point> >& squares)
{
Mat pyr, timg, gray0(image.size(), CV_8U), gray;
pyrDown(image, pyr, Size(image.cols/2, image.rows/2));
pyrUp(pyr, timg, image.size());
vector<vector<Point> > contours;
for (int c = 0; c < 3; c++)
{
int ch[] = { c, 0 };
mixChannels(&timg, 1, &gray0, 1, ch, 1);
// try several threshold levels
for (int l = 0; l < N; l++)
{
// hack: use Canny instead of zero threshold level.
// Canny helps to catch squares with gradient shading
if (l == 0)
{
// apply Canny. Take the upper threshold from slider
// and set the lower to 0 (which forces edges merging)
Canny(gray0, gray, 0, thresh, 5);
// dilate canny output to remove potential
// holes between edge segments
dilate(gray, gray, Mat(), Point(-1, -1));
}
else
{
// apply threshold if l!=0:
// tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0
gray = gray0 >= (l + 1) * 255/N;
}
.....
Обновленный
// find contours and store them all as a list
findContours(gray, contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
vector<Point> approx;
// test each contour
for (size_t i = 0; i < contours.size(); i++)
{
// approximate contour with accuracy proportional
// to the contour perimeter
approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);
// square contours should have 4 vertices after approximation
// relatively large area (to filter out noisy contours)
// and be convex.
// Note: absolute value of an area is used because
// area may be positive or negative - in accordance with the
// contour orientation
if (approx.size() == 4 &&
fabs(contourArea(Mat(approx))) > 1000 &&
isContourConvex(Mat(approx)))
{
double maxCosine = 0;
for (int j = 2; j < 5; j++)
{
// find the maximum cosine of the angle between joint edges
double cosine = fabs(angle(approx[j % 4], approx[j - 2], approx[j - 1]));
maxCosine = MAX(maxCosine, cosine);
}
// if cosines of all angles are small
// (all angles are ~90 degree) then write quandrange
// vertices to resultant sequence
if (maxCosine < 0.3)
squares.push_back(approx);
}
}
}
}
'> =' то же самое старый оператор сравнения (технически * реляционный оператор *), однако вы используете его на 'Mat', поэтому вы вызываете перегруженный оператор. Это то же самое, что и функция, имя которой 'operator> =', и она может что-то вернуть, мы не можем сказать только из этого кода. Обратитесь к определению класса 'Mat', чтобы узнать, что он говорит о своих перегруженных операторах. Для перегруженных реляционных операторов принято возвращать 'bool' так, чтобы они вели себя аналогично встроенным операторам; но это не строгое требование –
Я должен согласиться с @ M.M. Фрагмент кода, который вы предоставили, и, в частности, это назначение выглядит странно, если не сказать больше. 1) выражение возвращает boolean, но 'gray' -' cv :: Mat' и 2) само выражение выглядит некорректным. Вы не можете использовать '> =' точно так же, как между 'cv :: Mat' (здесь' gray0') и числом ('(l + 1) * 255/N)' является числом). – rbaleksandar
Существует некоторая потоковая документация [здесь] (http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#matrixexpressions) –