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

/ , OpenCV

6.

http://howto.nicubunu.ro/gears/gears_16.png

:
www.uralvision.blogspot.com


perevalovds@gmail.com

/ 2010


- , .
,
, .
3d .
3d .

http://cvpr.uni-muenster.de/research/rack/index.html


, ,
, 3d-,
, ,

- ( )
- ( )
- (
, )

, ,
?



, .
- ,
.
, .

.


1.
.
,
.
2.

, -
, ,
.


.
void Sobel(const Mat& src, //
Mat& dst,
// , - src
int ddepth,
// , , CV_32F
int xorder,
// x
int yorder,
// y
int ksize=3,
// : 1, 3, 5, 7
double scale=1, double delta=0,
//
int borderType=BORDER_DEFAULT)
//

1, 2, 3
( xorder x, yorder y).
( ,
.)

Mat image = imread( "lodka.jpg" ); //


imshow( "image", image ); //
Mat imageDX, imageDY;
Sobel( image, imageDX, CV_32F, 1, 0,
3, 1.0 / 255.0 );
// x
Sobel( image, imageDY, CV_32F,
0, 1,
3, 1.0 / 255.0 );
// y

, .
- .


,

sqrt( imageDX^2 + imageDY^2 ) - .
, .
Mat grayX, grayY;
cvtColor( imageDX, grayX, CV_RGB2GRAY );
cvtColor( imageDY, grayY, CV_RGB2GRAY );
pow(grayX, 2, grayX);
pow(grayY, 2, grayY);
Mat contImg = grayX + grayY;
sqrt(contImg, contImg);
contImg.convertTo( temp, CV_8UC3, 255.0 );
Mat binary;
threshold( contImg, binary, 0.7, 1.0, CV_THRESH_BINARY );



1. Scharr() ,
2. Laplacian(),
3. (. ).
, .
:
,
.
: .


,
,
.
.
- ,
"".

, .


void Canny( const Mat& image,
// , 1-, 8-
Mat& edges,
//
double threshold1,
//, - ,
double threshold2,
// -
int apertureSize=3,
//
bool L2gradient=false //
// , sqrt( dx*dx + dy * dy),
// |dx| + |dy|
);

Mat imageGray, edges;


cvtColor( image, imageGray, CV_RGB2GRAY );
Canny( imageGray, edges, 230, 150 );


-
, ..
.

:
- .
- (, ).
- ,
.


void findContours(const Mat& image,

// ,
//1-, 8-
// (0 0)
vector<vector<Point> >& contours, //
int mode,
//
int method,
//
Point offset=Point()
//

)
mode:
CV_RETR_EXTERNAL - ,
CV_RETR_LIST
-
, . :
CV_RETR_CCOMP
- 2- - ,
CV_RETR_TREE
- ,
method:
CV_CHAIN_APPROX_NONE -
CV_CHAIN_APPROX_SIMPLE -
CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_TC89_KCOS - Teh-Chin

vector<vector<Point> > contours;


findContours( edges, contours, CV_RETR_LIST, CV_CHAIN_APPROX_TC89_L1 );
Mat draw = image.clone();
drawContours( draw, contours, -1, Scalar( 255, 0, 0 ) );
imshow( "find cont", draw );


, ,

- ,
- , ,
- ,
,
.

- ,
.
- ,
.

Оценить