1. 程式人生 > >opencv求畫素總數並進行篩選

opencv求畫素總數並進行篩選


 
    vector<Vec4i> hierarchy;
    vector<vector<Point>> contours;
    findContours(src, contours, hierarchy, RETR_LIST, CHAIN_APPROX_NONE);
    int i;
    for (i = 0; i < contours.size(); i++) {
        Mat c =(Mat) contours[i];
        Scalar color(0, 0, 0);
        int a = fabs(contourArea(c));
        if (a < 2000) {
            drawContours(src, contours, i, color, CV_FILLED);
        }
    }