Вы находитесь на странице: 1из 26

/ , OpenCV

4. , ,
. :

http://www.svi.nl/wikiimg/SeedAndThreshold_02.png

:
www.uralvision.blogspot.com


perevalovds@gmail.com

/ 2010


1.
2.
3.
4.
5. :
-

cpp, ,

imwrite
- (png jpg)
- (png jpg)

split

merge
-
resize
- (*)
cvtColor - (*)
* -
1,
. uralvision.blogspot.com

split merge -
split
.
merge
.

,
.

split merge -
:

void split ( const Mat& mtx, vector<Mat>& mv )


mtx -
mv - 1-

void merge ( const vector<Mat>& mv, Mat& dst )


mv - 1-
dst -

split merge -
- ,
1- , .
Mat image = imread("C:\\abc-blocks.png");
imshow( "Input image", image );

//

vector<Mat> planes;
split( image, planes ); // image planes
imshow( "Blue", planes[0] ); imshow( "Green", planes[1] ); imshow( "Red", planes[2] );
vector<Mat> planesIzm( 3 );
// Red Blue :
planesIzm[0] = planes[2]; planesIzm[1] = planes[1];
Mat imageIzm;
merge( planesIzm, imageIzm );
imshow( "Result", imageIzm );

planesIzm[2] = planes[0];

// 0.299*R + 0.587*G + 0.114*B


//(, -, cvtColor)
Mat gray = 0.299*planes[2] + 0.587*planes[1] + 0.114*planes[0];
imshow( "Gray", gray );

split merge -

split merge -
1.
split merge?
2. -
imageIzm, image?
-
2.


threshold

adaptiveThreshold - (*)
min, max
- ,
(*)
abs
-
(*)
pow
-
(*)
sqrt
-
(*)
randu
- (*)

threshold -
threshold
.

.

threshold -
:
double threshold(const Mat& src, Mat& dst,
double thresh, double maxVal,
int thresholdType)
src dst - 1- .
, dst src.
thresh - ,
maxVal - ( THRESH_BINARY,
THRESH_BINARY_INV )
thresholdType - :
THRESH_BINARY
THRESH_BINARY_INV
THRESH_TRUNC
THRESH_TOZERO
THRESH_TOZERO_INV
THRESH_OTSU (- , )

threshold -
thresholdType - :
THRESH_BINARY
THRESH_BINARY_INV
THRESH_TRUNC
THRESH_TOZERO
THRESH_TOZERO_INV
THRESH_OTSU (- , )

threshold -
- ,
( , - )
Mat image = imread("C:\\billiard.png");
//
imshow( "Input image", image );
vector<Mat> planes;
split( image, planes );
Mat gray = 0.299*planes[2] + 0.587*planes[1] + 0.114*planes[0];
double thresh = 50.0; //,
threshold( gray, gray, 50.0, 255.0, CV_THRESH_BINARY );
imshow( "Threshold", gray );

threshold -

: " ".
-
.


floodFill


dilate
- (*)
erode
-
(*)

floodFill -
floodFill ,
(x, y), ,
4- 8- .
: - .
1. ,
, .
2.
( " + " -
).
3. 1
,
.

floodFill -
:
int floodFill(Mat& image, Point seed, Scalar newVal,
Rect*
rect=0,
Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
int flags=4)
image - , 1- 3-, 8 32-.
seed - ,
rect -
loDiff, upDiff -
( - ,
flags |= FLOODFILL_FIXED_RANGE)
, valueNew
value - loDiff <= valueNew <= value + upDiff.
flags = 4 8 - .
- .

floodFill -
OpenCV:
Point - int x, y;
Rect -
int x, y, width, height;
Scalar - ,
, Scalar( 255 ) - 1- ,
Scalar( 255, 255, 255 ) - 3-

floodFill -
- - .
. - threshold,
floodFill, ,
.
const int minRectDim = 25; //
const int maxRectDim = 35;
//
for (int y=0; y<gray.rows; y++) {
for (int x=0; x<gray.cols; x++) {
int value = gray.at<uchar>(y, x);
if ( value == 255 ) {
// - 255,
// 200
Rect rect;
//
int count = floodFill( gray, Point( x, y ), Scalar( 200 ), &rect );

floodFill -
//
if ( rect.width >= minRectDim && rect.width <= maxRectDim
&& rect.height >= minRectDim && rect.height <= maxRectDim )
{
//
int x = rect.x + rect.width / 2;
int y = rect.y + rect.height / 2;
//
int rad = ( rect.width + rect.height ) / 4;
// 2
circle( image, Point( x, y ), rad, Scalar( 255, 0, 255 ), 2 );
}
}
}
}
imshow( "out", image );

floodFill -

floodFill -

- .
,
.
, .
,
, "" .
:
1. ,
.
2. "",
.


1
- . , uralvision.blogspot.com
2
- . split merge.

Вам также может понравиться