-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ]

, 05 2017 . 11:33 +
, . , , .

- . . openCV 2.4.

: .


() ().

:

Mat src = imread("1.jpg"); // 

opencv BGR. BGR , HSV.
HSV ( HSB) Hue, Saturation, Value (Brightness), :
Hue , .. .

Saturation . , , , .

Value (Brightness) () . , ( ). , (0% )

image

, .

HSV Hue Saturation Value .

//   HSV
Mat hsv = Mat(src.cols, src.rows, 8, 3); //
vector splitedHsv = vector();
cvtColor(src, hsv, CV_BGR2HSV);
split(hsv, splitedHsv);

. OpenCV 34 72. . 21 110.

const int GREEN_MIN = 21;
const int GREEN_MAX = 110;

. . , , . , .

for (int y = 0; y < hsv.cols; y++) {
	for (int x = 0; x < hsv.rows; x++) {
		//  HSV- 
		int H = static_cast(splitedHsv[0].at(x, y));        // 
		int S = static_cast(splitedHsv[1].at(x, y));        // 
		int V = static_cast(splitedHsv[2].at(x, y));        // 
		
		//          ,   
		if ((V < 20) || (H < GREEN_MIN) || (H > GREEN_MAX)) {
			src.at(x, y)[0] = 255;
			src.at(x, y)[1] = 255;
			src.at(x, y)[2] = 255;
		}
	}
}

:



, .

.

( ) . . , . . . , . . , .

( ) . , , , .

. . .

int an = 5;
//     .
Mat element = getStructuringElement(MORPH_ELLIPSE, Size(an * 2 + 1, an * 2 + 1), Point(an, an));
dilate(src, tmp, element);
erode(tmp, tmp, element);


.

, , . , .

Mat grayscaleMat;
cvtColor(tmp, grayscaleMat, CV_BGR2GRAY);

//  
Mat mask(grayscaleMat.size(), grayscaleMat.type());
Mat out(src.size(), src.type());
threshold(grayscaleMat, mask, 200, 255, THRESH_BINARY_INV);

//      
out = Scalar::all(255);
//    
src.copyTo(out, mask);


, .

.

->
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/332464/

:  

: [1] []
 

:
: 

: ( )

:

  URL