Algorithm of non-maximal value suppression algorithm __

Source: Internet
Author: User
non-maximal value suppression

Non-maximal value suppression (NMS), which can be understood as a local maximum search, that is, the maximum value within the search neighborhood. Pedestrian detection later, the detection of the window to perform a non-maximum value suppression of the window fusion, thereby filtering out some internal windows, etc., to achieve the window fusion effect, so that the detection accuracy higher. The following is a detailed analysis of the non-maximal-value suppression functions in OpenCV. See the following procedure for details.

Achieve non-maximum suppression of detected Rectangle window//numboxes: Number of Windows//points: Top left corner coordinate point//oppositepoints: Window lower right corner coordinate point//score: Window score//overlapthreshold: overlap threshold Value control//numboxesout: Output Window number//pointsout: Output window upper left corner coordinate point//oppositepoints: Output window lower right corner coordinate point//scoreout: Output Window score int nonmaximumsuppress
                          Ion (int numboxes, const cvpoint *points, const cvpoint *oppositepoints, const float *score,
                          float overlapthreshold, int *numboxesout, Cvpoint **pointsout,
    Cvpoint **oppositepointsout, float **scoreout) {int I, J, index;   float* Box_area = (float*) malloc (numboxes * sizeof (float));          Define window area variables and allocate space int* indices = (int*) malloc (numboxes * sizeof (int));    Define the window index and allocate space int* is_suppressed = (int*) malloc (numboxes * sizeof (int)); Defines whether to suppress table flags and allocate space//Initialize indices, is_supperssed, Box_area information for (i = 0; i < numboxes; i++) {Indices
        [I] = i;
        Is_suppressed[i] = 0; Box_area[i] = (float) ((oppositepoints[i].x-points[i].x + 1) * (OPPOSITEPOINTS[I].Y-POINTS[I].Y + 1));
    }//The input window is sorted by fractional ratio and the sorted number is placed in indices sort (numboxes, score, indices); for (i = 0; i < numboxes; i++)//Cycle all Windows {if (!is_suppressed[indices[i]])//Judgment window Whether the port is suppressed {for (j = i + 1; j < Numboxes, j + +)//loops the window after the current window {if (! IS_SUPPRESSED[INDICES[J])//Determine if the window is suppressed {int x1max = max (points[indices[i]].x, POI                     nts[indices[j]].x);     Two window upper left corner x coordinate max value int x2min = min (oppositepoints[indices[i]].x, oppositepoints[indices[j]].x);                     Find the bottom right corner of the two window x coordinate minimum value int y1max = max (points[indices[i]].y, POINTS[INDICES[J]].Y);     Find the upper left corner of the two window y-coordinate max int y2min = min (oppositepoints[indices[i]].y, oppositepoints[indices[j]].y); 
                 Find the lowest y-coordinate of the bottom right corner of two windows   int overlapwidth = X2min-x1max + 1;           Computes the width of two rectangles overlapping int overlapheight = Y2min-y1max + 1;
                        Calculates the height if the two rectangles overlap if (overlapwidth > 0 && overlapheight > 0) {    float Overlappart = (overlapwidth * overlapheight)/box_area[indices[j]]; 
                        Calculate the overlap ratio if (Overlappart > Overlapthreshold)//Determine if the overlap ratio exceeds the overlap threshold           {Is_suppressed[indices[j]] = 1; Mark window J as suppressed}}}}} *numbox    esout = 0;    Number of initialization output Windows 0 for (i = 0; i < numboxes; i++) {if (!is_suppressed[i]) (*numboxesout) + +;           Number of statistics output windows} *pointsout = (Cvpoint *) malloc ((*numboxesout) * sizeof (cvpoint));   Allocate Output Window upper-left corner coordinate space *oppositepointsout = (Cvpoint *) malloc ((*numboxesout) * sizeof (cvpoint)); DistributionOutput window lower right corner coordinate space *scoreout = (float *) malloc ((*numboxesout) * sizeof (float));
    Allocate Output window score space index = 0;             for (i = 0; i < numboxes; i++)//traverse all input Windows {if (!is_suppressed[indices[i])
            Saves the window information that has not been suppressed to the output information {(*pointsout) [index].x = points[indices[i]].x; (*pointsout)
            [INDEX].Y = Points[indices[i]].y; (*oppositepointsout)
            [index].x = oppositepoints[indices[i]].x; (*oppositepointsout)
            [INDEX].Y = Oppositepoints[indices[i]].y; (*scoreout)
            [index] = score[indices[i]];
        index++;          }} free (indices);         Release indices space free (BOX_AREA);    Release Box_area space Free (is_suppressed);
Release is_suppressed space return LATENT_SVM_OK; }//Sort functions, sorted after the data in indices//N: Total number of sorts//x: With sort//indices: initial 0~n-1 number of static void sort (int n, const float* x, int* in
    dices) {int I, J; for (i = 0; i < n; i++) for (j = i + 1; J < N;
                J + +) {if (X[indices[j]] > X[indices[i]) {//float x_tmp = x[i];
                int index_tmp = Indices[i];
                X[i] = X[j];
                Indices[i] = Indices[j];
                X[J] = x_tmp;
            INDICES[J] = index_tmp;
 }
        }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.