Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

/ , 2012

2. . .
.


www.uralvision.blogspot.com

perevalovds@gmail.com


1. . 4-, 6-, 8- .
. - .
2. : ,
.
3. .

4 OpenCV: . .
5. OpenCV.
6. OpenCV. . .
7. OpenCV: , min, max - .


.
, , .
V.
V , p1, p2
,
(p1, q0, q1, ..., qm, p2) .
, , "- ", .
Q
V1,..., Vn,
Q.

8-.
4- ( ).
: . (
15 perevalovds@gmail.com)

6-
6- ,
"":
1. ( 8)
2. , 4- (6-
, 4-).
, - " ".

,
Q.
, Q
.

,
.

.

,
.
,
A:
A A,
A.
A A,
A.


"" ""
. ( 1970-).
- () ()
. - R (
).
- "R-" . Q ,
R .
- "R-" . Q
R Q.

"" = + . .
"" = + . .


. .
, .
(, ).

1. A0 - . T0. A0\T0
("\" ".
2. A1 = (A0). T1. A1\T1.
...
, An .
- .

. ,
. , ,
, , .


, , .
-
- .
F( A )(x,y) = f( A(x1,y1): (x1,y1) O(x,y) ) -
f, , ,
.
, .

:
( - 8- , , R .)

1.
F(A)(x,y) = 1/9 * sum( a=-1..1, b=-1..1 ) A(x+a, y+b)
2. ,
F(A)(x,y) = min{ A(x+a, y+b): a=-1..1, b=-1..1 }
F(A)(x,y) = max{ A(x+a, y+b): a=-1..1, b=-1..1 }
: - , - , ,
, min max.

3.
F(A)(x,y) = { A(x+a, y+b): a=-1..1, b=-1..1 }


(Converging squares).
1984 . .
() .
. .
. , sxs.
1. Ts - .
2. T(s-1): Ts s-1.
, , T(s-1).
3. T(s-2)
...
s. T0 - 1x1 ,



( Gimp/Photoshop).

OpenCV: , ,

#include "highgui.h"
Mat img = imread( "image.png" );
imwrite( "image.png", img );

//
//

imshow( "image", img );


//
// cvWaitKey(0)
// cvWaitKey( N ) N , , N=1.

OpenCV:
.

Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1));
//, , ( - ).
:
MORPH_RECT -
MORPH_CROSS -
MORPH_ELLIPSE - .
, 4- :
Mat kernel = getStructuringElement(MORPH_CROSS, cv::Size( 3, 3 ));
8- :
Mat kernel = getStructuringElement(MORPH_RECT, cv::Size( 3, 3 ));
:
erode( img1, img2, kernel );
dilate( img1, img2, kernel );
- ,
( -
).

OpenCV:
:
mean( img ) - cv::Scalar.
1- :
float value = mean( img( cv::Rect( x-1, y-1, 3, 3 ) ) );
blur - (
).

min, max:
,
.
:
void medianBlur(const Mat& src, Mat& dst, int ksize)
Smoothes image using median filter
Parameters:
src The source 1-, 3- or 4-channel image. When ksize is 3 or 5, the image
depth should be CV_8U , CV_16U orCV_32F . For larger aperture sizes it can
only be CV_8U
dst The destination array; will have the same size and the same type as src
ksize The aperture linear size. It must be odd and more than 1, i.e. 3, 5, 7 ...

OpenCV:

floodFill

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. "",
.

You might also like