# BP Opencv tutorial ## Build Demo project ### 1. git clone project ![](https://i.imgur.com/8nLnBjv.png) ### 2. Install plugin ![](https://i.imgur.com/YRiBrQS.png) ### 3. Generate project ![](https://i.imgur.com/FWhxhNP.png) ### 4. Build project ![](https://i.imgur.com/wyDethg.jpg) Then you can try it. ## How to read example Our example is porting from [opencv website](https://docs.opencv.org/master/d7/da8/tutorial_table_of_content_imgproc.html) We use blueprint to implement same function. ## Introduction For use this plugin, You may want to do image processing or want to draw geometric figures. First you will need to create an image (CvMat). There are several methods you can try. ### 1. Read from texture ![](https://i.imgur.com/aDsQzMU.png) You can read from unreal texture2D then use function "UpdateTextureToCvMat" to convert texture to opencv mat. ### 2. Create Blank image Use Cv Zeros use 0 to fill image ![](https://i.imgur.com/yTVbZsq.png) Use Cv Ones use 1 to fill image ![](https://i.imgur.com/yrZ7A5y.png) Then you can show image to mesh or canvas. ### Show CvMat in mesh Video demo {%youtube x2hSo44PfvE %} Blueprint: ![](https://i.imgur.com/NLEFsUS.png) ### Show CvMat in canvas Blueprint: ![](https://i.imgur.com/1HiHkJU.png) Final we use smoothing example to finish tutorial. ## [Opencv Smoothing Images example](https://docs.opencv.org/master/dc/dd3/tutorial_gausian_median_blur_bilateral_filter.html) ## Initalize from texture Origin example is read the image from file. we change it read from texture. ```c const char* filename = argc >=2 ? argv[1] : "lena.jpg"; src = imread( samples::findFile( filename ), IMREAD_COLOR ); if (src.empty()) { printf(" Error opening image\n"); printf(" Usage:\n %s [image_name-- default lena.jpg] \n", argv[0]); return EXIT_FAILURE; } ``` ![](https://i.imgur.com/a0FsOS6.png) ## Show original image ```c if( display_caption( "Original Image" ) != 0 ) { return 0; } dst = src.clone(); if( display_dst( DELAY_CAPTION ) != 0 ) { return 0; } ``` ![](https://i.imgur.com/17qGl5G.png) ## blur ```c if( display_caption( "Homogeneous Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { blur( src, dst, Size( i, i ), Point(-1,-1) ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } ``` ![](https://i.imgur.com/ToFwWhK.png) ## GaussianBlur ```c if( display_caption( "Gaussian Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { GaussianBlur( src, dst, Size( i, i ), 0, 0 ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } ``` ![](https://i.imgur.com/J4GLrMj.png) ## medianBlur ```c if( display_caption( "Median Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { medianBlur ( src, dst, i ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } ``` ![](https://i.imgur.com/E4cKj1H.png) ## bilateralFilter ```c if( display_caption( "Bilateral Blur" ) != 0 ) { return 0; } for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) { bilateralFilter ( src, dst, i, i*2, i/2 ); if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } } ``` ![](https://i.imgur.com/j2r3Yg3.png) you can reference all example from opencv website https://docs.opencv.org/master/d7/da8/tutorial_table_of_content_imgproc.html We implement all example of opencv imgproc.