OscarAHB

Untitled

Sep 7th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <opencv2/imgproc/imgproc.hpp>
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/highgui/highgui_c.h>
  4. #include <opencv2\opencv.hpp>
  5.  
  6. using namespace cv;
  7. void conv2(Mat src, int kernel_size)
  8. {
  9.     Mat blur, kernel;
  10.     //Creo una matriz gaussiana
  11.     kernel = (Mat_<double>(3, 3) << 0.0102059, 0.115349, 0.135784, 0.1224548, 0.123354, 0.1665548, 0.155474, 0.1235547, 0.221468);
  12.     //kernel = Mat::ones(kernel_size, kernel_size, CV_32F) / (float)(kernel_size*kernel_size); //Estoy creando una matriz, este caso 1/100
  13.  
  14.     /// Apply filter
  15.     filter2D(src, blur, -1, kernel, Point(-1, -1), 0, BORDER_DEFAULT);
  16.     imshow("filter2D", blur);
  17. }
  18. void conv3(Mat src, int Gaussian_kernel)
  19. {
  20.     Mat blur;
  21.     GaussianBlur(src, blur, Size(Gaussian_kernel, Gaussian_kernel), 0, 0);
  22.     imshow("GaussianFilter", blur);
  23. }
  24. int main(int argc, char** argv)
  25. {
  26.     namedWindow("window", CV_WINDOW_AUTOSIZE);
  27.     //Cargamos el video desde un archivo
  28.     VideoCapture vc("../data/Jordan.mp4");
  29.     Mat frame;
  30.     //Verificamos que el video se ha podido cargar
  31.     if (!vc.isOpened()) return -1;
  32.     //Obtenemos cuadro por segundo
  33.     double fps = vc.get(CV_CAP_PROP_FPS);
  34.     //Calculamos tiempo de espera entre cada imagen a mostrar
  35.     int delay = 1000 / fps;
  36.     // Es para aumentar el tamaño de blur
  37.     while (true)
  38.     {
  39.         //Cargar el primer cuadro en frame
  40.         vc.read(frame);
  41.         imshow("window", frame);
  42.         Mat src = frame;
  43.         //o waitKey(); para ir con cada tecla.
  44.         conv2(src, 7);
  45.         conv3(src, 3);
  46.         //la función waitKey() espera a indefinidamente a que se presione una tecla,
  47.         waitKey(10);
  48.         if (waitKey(delay) == 27) break;
  49.     }
  50.     return 0;
  51.     destroyWindow("window");
  52. }
Add Comment
Please, Sign In to add comment