簡體   English   中英

在這種情況下,> =意味着什么

[英]What does >= means in this context

我正在嘗試理解使用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);
            }
        }
    }
}

基於cv::Mat上的OpenCV 文檔,這個表達式返回一個通道掩碼(一個cv::Mat ),然后將其分配給灰色(另一個cv::Mat ):

比較: A cmpop B, A cmpop alpha, alpha cmpop A ,其中cmpop是以下之一: >, >=, ==, !=, <=, < 比較結果是一個8位單通道掩碼,其元素設置為255(如果特定元素或元素對滿足條件)或0。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM