Está en la página 1de 12

OpenCV

Introduccin

Leer una
imagen
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/
highgui.hpp>
int main() {
// leemos la imagen
cv::Mat image=
cv::imread("img.jpg");
// creamos la ventana
cv::namedWindow("My Image");
// mostramos la imagen
cv::imshow("My Image", image);
// retardo
cv::waitKey(5000);
return 1;
}

RGB a escala
de grises

/// Convertir a escala de grises


cvtColor(imagen, imagen_g, CV_RGB2GRAY);

Elementos
estructurales
erosion_type =MORPH_ELLIPSE;
erosion_type = MORPH_CROSS;
erosion_type = MORPH_RECT
!
!
!

Mat element = getStructuringElement( erosion_type,


Size(3, 3), Point( 1, 1 ) );

Dilatacin

dilate( image, imagen_dilatada, element );


!

imshow( "Dilatacin", imagen_dilatada );

Erosin

erode( image, imagen_erosionada, element );


!

imshow( "Erosin", imagen_erosionada);

Apertura

open( image, imagen_apertura, element );


!

imshow( "Apertura", imagen_apertura);

Cierre

close( image, imagen_cierre, element );


!

imshow( "Cierre", imagen_cierre);

Filtro Sobel
/// Gradiente X
Sobel( src_gray, grad_x, CV_16S, 1, 0, 3, scale, delta,
BORDER_DEFAULT );
convertScaleAbs( grad_x, abs_grad_x );
!

/// Gradiente Y
Sobel( src_gray, grad_y, CV_16S, 0, 1, 3, scale, delta,
BORDER_DEFAULT );
convertScaleAbs( grad_y, abs_grad_y );
!

/// Gradiente total


addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad );

Filtro Gaussiano

GaussianBlur( image, image, Size(3,3), 0, 0,


BORDER_DEFAULT );

Filtros

/// Definimos el kernel


kernel = Mat::ones( 5, 5, CV_32F )/ (5*5);
!

/// Aplicamos el filtro


filter2D(src, dst, -1 , kernel, Point( 1, 1 ), 0,
BORDER_DEFAULT );

Umbral
Binary
Binary Inverted
Threshold Truncated
Threshold to Zero
Threshold to Zero Inverted
!
!

threshold( src_gray, dst, threshold_value,


max_BINARY_value,threshold_type );
!

threshold_value = 0;
threshold_type = 3;
max_value = 255;
max_type = 4;
max_BINARY_value = 255;

También podría gustarte