Mat img = imread("perecek/1.png", IMREAD_COLOR); Mat hsv; cvtColor(img, hsv, COLOR_BGR2HSV); vector chs; split(hsv, chs); Mat mask; imshow("1", chs[0]); imshow("2", chs[1]); imshow("3", chs[2]); inRange(chs[1], 100, 255, mask); imshow("mask", mask); vector> conts; vector hier; int perecek = 0; findContours(mask, conts, hier,RETR_TREE, CHAIN_APPROX_NONE); //drawContours(img, conts, -1, Scalar(255, 0, 0), 2); for (int i = 0; i < conts.size(); ++i) { int szamlalo = 0; if (hier[i][3] == -1) { Scalar color(rand() & 255, rand() & 255, rand() & 255); drawContours(img, conts, i, color, 2); int index = 0; for (index = hier[i][2]; index != -1; index = hier[index][0]) { szamlalo++; drawContours(img, conts, index, color, 2); } if (szamlalo == 3) { perecek++; } } } imshow("src1", img); cout << perecek << endl; waitKey(); return 0;