Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mat rgb;
- // downsample and use it for processing
- pyrDown(large, rgb );
- pyrDown(rgb, rgb);
- pyrDown(rgb, rgb);
- //pyrDown()
- Mat small;
- cvtColor(rgb, small, CV_BGR2GRAY);
- // morphological gradient
- Mat grad;
- Mat morphKernel = getStructuringElement(MORPH_ELLIPSE, Size(10, 10));
- morphologyEx(small, grad, MORPH_GRADIENT, morphKernel);
- // binarize
- Mat bw;
- threshold(grad, bw, 0.0, 255.0, THRESH_BINARY | THRESH_OTSU);
- // connect horizontally oriented regions
- Mat connected;
- morphKernel = getStructuringElement(MORPH_RECT, Size(1, 5));
- morphologyEx(bw, connected, MORPH_CLOSE, morphKernel);
- // find contours
- Mat mask = Mat::zeros(bw.size(), CV_8UC1);
- vector<vector<Point>> contours;
- vector<Vec4i> hierarchy;
- findContours(connected, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
- // filter contours
- int biggest = getMaxAreaContourId(contours);
- std::vector<int> uniqueColors;
- std::vector<Mat> ROI_store;
- std::map<cv::Mat, int> colorMap;
- for (int idx = 0; idx >= 0; idx = hierarchy[idx][0])
- {
- Rect rect = boundingRect(contours[idx]);
- Mat maskROI(mask, rect);
- maskROI = Scalar(0, 0, 0);
- // fill the contour
- drawContours(mask, contours, idx, Scalar(255, 255, 255), CV_FILLED);
- // ratio of non-zero pixels in the filled region
- double r = (double)countNonZero(maskROI) / (rect.width*rect.height);
- cout << "hello mary louZ" << endl;
- cout << "RGB width : " << rgb.cols<< endl;
- cout << "Rect width : " << rect.width << endl;
- if (r > .35
- /*
- // may work on ios but not here
- && (rgb.cols /4 < rect.width < rgb.cols / 2)
- && (rgb.rows / 4 < rect.height < rgb.rows / 2)
- */
- && (inRange(rgb.cols / 4, rgb.cols / 2, rect.width))
- //|| inRange(rgb.rows / 4, rgb.rows / 2, rect.height))
- //&& (rgb.cols / 4 < rect.width) && (rect.width < rgb.cols / 2)
- //&& (rgb.rows / 4 < rect.height) && (rect.height < rgb.rows / 2)
- //&& (800 > rect.width) && (800 > rect.height)
- //&& ( 10 <= rect.width - rect.height <= 10)
- )
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement