OpenCV (1) OpenCV Hello World
1. C++ OpenCV Hello world:
Open an image and read it into a matrix.
#include<iostream> #include<opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { Mat img = imread("mini.jpg"); imshow("Image", img); // "Image" is the name of the window waitKey(0); destroyAllWindows(); return 0; }
Linux makefile.
CXX=g++ LIBS=-lopencv_world .PHONY: debug, main, clean debug: dbgmain.out main: main.out dbgmain.out: main.cpp $(CXX) $^ -g -o $@ $(LIBS) main.out: main.cpp $(CXX) $^ -O3 -o $@ $(LIBS) clean: rm -fr *.out
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZrN_pUYBcFxx8MMuCeaYVVwiRmfJBErI6cEZwpfAYFL50GMIC_8PDdQgGSNAc5x9oYrhlDIQGrG6EbrB9J4zZeO9-_JYqTv-fwZY4EIazNEcEQXNH0g2BKKu5LvD_o_A-SvQvw_2Sqbc/s320/2018-05-27+14-20-11+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
2. C++ OpenCV Hello world 2:
Use GaussianBlur to blur the image.
#include#include using namespace std; using namespace cv; int main() { Mat img = imread("mini.jpg"); // imshow("Image", img); Mat blur_img; GaussianBlur(img, blur_img, Size(5, 5), 10, 10); imshow("Blur Image", blur_img); waitKey(0); destroyAllWindows(); return 0; }
The declaration of of GaussianBlur:
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT);
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIpxGboe7mvH1UA4V1bDPfz3eiu7ItBDkrCVNd5BoMN0T3LKC-A10CGfFiCIDyhYitjxwpNe_RUxYcCN53cIo682WqsjM7Jo5ObuODzwm2bMjDWPP6PXzkCN6x0ajX2Ee5vlorZwxu40I/s320/2018-05-27+14-21-04+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
Change the size of the kernel to 50*50.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8JpMtXFahbdqTQ0urqw8lPkpJhkR1eXO5_CDQ225TnuSr_1xuvf0sNFbo0wpQEQeUY8NLTzWlf4VNoYgnGx4X7r3B-Z30KWE-KeA74l3r1804CqaRrrL9y-Mg4ZEsPl17L7TJoY9GDwk/s320/2018-05-27+14-23-44+%25E7%259A%2584%25E8%259E%25A2%25E5%25B9%2595%25E6%2593%25B7%25E5%259C%2596.png)
Reference
[1] Adrian Kaehler, Gary Bradski, Learning OpenCV 3 , O'Reilly Media (2017)