October 2016


My favourite

  • Opencv tutorial people detection
  • Head people cascade download
  • Opencv tutorial optical flow
  • Opencv Video stabilization
  • Opencv car dataset download
  • Opencv tutorial Transparent mask
  • Opencv videowriter
  • Opencv FFMPEG
  • Opencv Canny edge and hough lines

  • Denoising easy opencv tutorial C++

    The Opencv library has build in powerful denoising algorithm based on the non-local means. The metdod is based on the theory published in article by Antoni Buades, Bartomu Coll, Jean-Michel Morel  here. The algorithm is relatively simple, but not so easy to implement. Basically, one single pixel is replace by the average of the colors of area around the most simular pixel. Let say we want to replace pixel and algorithm finding the replacement in some window. It find the most simular replacement and additionally take a smaller window over that most silular replacement and calculate mean value over that. 
    If we have first window of some size and second the smaller just one pixel. We probably replace the original one with the most simular. If the most simular one is the noise. It will be noise. This is great metod for calculating the output image from the sequence of imputs image to achieve better result. Video result is also impresive.. Check the results and enjoy the simple code. 

    fastNlMeansDenoisingColoredMulti opencv denoising method results

    This results are from my video. Upper part of the image is the denoised frame of the video calculated from the 4 surrounded frames. Original imputs is the lower part of the image. If you check the cropped part below the results are clearly visible. No to much blured image, sharp edges and much less noisy. This is exactly what we want to achieve. 

    Denoising opencv noise reduction
    Denoising video sample in opencv 3,1 noise reduction
    Denoising opencv noise reduction

    Iphone sequence of images noise reduction

    I just take the imput 5 image by iphone SE holded in hands. Result will be much better with 5 images using tripod. 

    Denoising opencv noise reductionDenoising opencv noise reduction
    Denoising opencv noise reduction

    Denoising opencv noise reductionDenoising opencv noise reduction
    ZOOM of one of the imput image

    Denoising opencv noise reduction

    Results of  fastNl Means Denoising Colored Multi method

    Denoising opencv noise reduction

    Noise reduction Zoom ot the result

    Denoising opencv noise reduction

    What do you think ? Let me know.. 

    Opencv denoising (noise reduction) c++ code

    There is nothing special. Fill the vector<Mat> buffer(5); buffer with input images calculate from buffer the method based on the templateWindowSize = 12 and searchWindowSize = 48. This is it.

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/photo.hpp>
    #include <opencv2\videostab.hpp>
    #include "opencv2/imgcodecs.hpp"
    #include "opencv2\highgui.hpp"
    #include "opencv2\imgproc.hpp"
    #include <iostream>
    using namespace cv; using namespace std; int main(int argc, char** argv) { vector buffer(5); Mat image; image = imread("i1.JPG", CV_LOAD_IMAGE_COLOR); buffer[0] = image; imshow("Display window", image); waitKey(2000); image = imread("i2.JPG", CV_LOAD_IMAGE_COLOR); buffer[1] = image; waitKey(2000); imshow("Display window", image); image = imread("i3.JPG", CV_LOAD_IMAGE_COLOR); buffer[2] = image; imshow("Display window", image); waitKey(2000); image = imread("i4.JPG", CV_LOAD_IMAGE_COLOR); buffer[3] = image; imshow("Display window", image); waitKey(2000); image = imread("i5.JPG", CV_LOAD_IMAGE_COLOR); buffer[4] = image; imshow("Display window", image); waitKey(2000); Mat img; int imgs_count = 5; fastNlMeansDenoisingColoredMulti(buffer, img, imgs_count / 2, imgs_count, 12, 48); namedWindow("Display window", WINDOW_AUTOSIZE); imshow("Display window", img); imwrite("result.jpg", img); waitKey(20000); return 0; }

    Denoising Colored Video example

    FastMeansDenoisingColoredMulti VS just DenoisingColored in Opencv with image stabilization video example

    opencv DenoisingColored

    C++ tutorial and code is here

    Smart noise reduction (denoise) Iphone SE video 

    I expect that i finish this tutorial until the end of this weak. This is what you can expect. Check my youtube video down on page. Opencv has awesome posibilities to remove noise in smart way. Much better results than dummy filters and blur methods.. 

    opencv noise remove compensation

    noise compensation opencv


    Multiple people tracking 

    Opencv tracking of multiple people example video and some ideas about the business behind.. 
    I would like to mention that this video is not related on my any curent business. This is just love to computer vision. 

    This short blog post should be about something else. 

    Multi target tracking

    Problem of computer vision business potencial

    • People point to any mistake of algorithm. Mistakes are visible. People dont care if the big data gives you huge statistics error. They are not able to count the milions line of something. 
    • They are able to count what they are really see on video. 
    Where is the point. Even the error is visible and sometines huge. This gives you better result than one man counting the people from the window all day long. 
    Are you able to track and monitor what every on screen doing and count targets and write the results somewhere. 


    Do not sell video. Sell the data

    This is important. Maybe the most important think. You are provide data about the day activity about the year activity what ever.  
    Not the person for one day counting of the trafic on the Prague town center crossing. 

    Video delivery or internet of things

    You have to solve the problem with stream video delivery to cloud as cheap as it posible. 

    There is one think. Internet of thinks. Maybe is better old aproach just manage the computer vision where the camera is located.. Computers are smaller and faster. The video delivery is problem.. You have to deal with so many problems. Insted of transfering just the data. 

    Benefits are that the people infront of the monitor just see your mistakes.

    Cost effective computer vision 

    There is maybe question what is effective. Process the video in cloud has also many advantages. Scales. Updates. Your algorithm is under control. You can handle what ever resolution. This is only issue of the cost of your solution. It is not necesary with some cameras to manage your own HW in that solution. 

    I have a lots of idea like that. I spent lots of time not only on algorithm itself. For example another huge topic is 

    Self configuration of computer vision algorithm

    Yes this one. Not a spend 3 hours or months to make perfect youtube video. There is no reason. 
    Algorithm should be somehow self configurating.  And it may not be perfect. Let the rest of the world accept error also in computer vision. 

    Have a nice evening and let me know. What do you think. 

    Tutorial comming soon. Hopefully 

    Opencv Tutorial colors channels

    Opencv C++ simple tutorial about the colors and color channels. There is couple of tricks you can play with in Opencv. It is fun and easy to use to achieve color mixing and gain the channel by for example slide bar.. Enjoy the coding.. 

    Opencv installation in Visual Studio 2015

    You can simple prepare the project inside the Visual Studio 2015 by Nuget Packages. This approach is easy for beginers and better than standard installation with all the environmental variables problems. Just follow the installation steps inside here 

    opencv colors channels

    Opencv colors introduction

    I always forget what is the right order of colors in the opencv. The purpose of this short tutorial is different. It is not necessary to know if the blue rectangle in RGB should be defined like [255 , 0 , 0] or [0, 0 , 255] . Hopefully it is still BGR that mean blue, green and red channel. Just to be clear and sure that anyone understand. You can change that order but for no reason the default order is BGR.

    There is more color space available in opencv and in practice there is a reason for that. There is also different scales for each colors.

    Example is simple. BLUE should be 0 to 255 for min and max value of the channel (CV_8U). Same blue color can have a same min and max visual levels but color is divided into more steps 0 to 65535(CV_16U).

    Opencv color space transformation basics

    There is also pure gray scale. GRAY is equal of small piece of blue plus small piece of green and small piece of the last one. Something like Gray = 0.3 x R + 0.3 x G + 0.3 x B. Ok constants are different but who cares if there is 0.299 in R channel and lots of green color. This is it in principle.

    Also there is much more color spaces. Some of than are better because of let say endurance against the intensity of light conditions.

    But all you need to know for beginning is just cvtColor command.

    Comand has 3 parameters. Input_Image and output_Image and from_to_color_space.

    cvtColor( YourMat, YourOutputMat, CV_BGR2GRAY); sometimes in opencv 3.1 is only BGR2GRAY.

    You can use transformation to CV_BGR2HSV and back should be CV_HSV2BGR. ALL make sense but no BGR in world, where everyone using RGB.

    Opencv tutorial Video color mixing

    In this tutorial there is only one milestone. Learn this 
    IMage.at<Vec3b>(y, x)[0]    to Access the pixel at Y and X position. !For 0 color channel. 
    and this 
    IMage.at<Vec3b>(y, x)[1]    Same but different color. 
    and also 
    IMage.at<Vec3b>(y, x)[2]    This should be Blue or Red thats depends on Opencv mood. Probably red.

    In tutorial we make a copy of the image by

    Into that copy just insert the image retrieve by video capture and each pixel of each color channel just multiply by value of slider. 

    Opencv dependencies 

    The code is well described and in right setting of Opencv 3.1 instalation works. For example the easies instalation in Visual studio is by NUGET packages described here 

    Proper setting of the video writer it should be found Here. The only magic is right instalation and proper size of output image. Ok codec also. 

    Opencv Video color channels example

    Opencv tutorial code

    #include "opencv2\highgui.hpp"
    #include "opencv2\imgproc.hpp"
    #include <vector>
    #include <stdio.h>
    #include <Windows.h>
    #include <iostream>

     using namespace cv;
    using namespace std;

    // slider globa value
    int iSliderValue1 = 0;
    int iSliderValue2 = 0;
    int iSliderValue3 = 0;

    int main(int argc, const char** argv)
     // read video or cap(0) the web cam
    VideoCapture cap("mov.MOV");

    //prepare the writer for output
    VideoWriter outputVideo;

    outputVideo.open("video4.wmv", CV_FOURCC('W', 'M', 'V', '2'), 30, Size(1280, 960), true);

    for (;;)

    bool Is = cap.grab();
    if (Is == false) {
            cout << "Video Capture Fail" << endl;
    else {

    Mat img;
    Mat Original;
    cap.retrieve(img, CV_CAP_OPENNI_BGR_IMAGE);
    resize(img, img, Size(1280, 960));
    // we got a video in img and its copy in Original
    // Lets access all pixels in X and Y (Y,X) and also visit all colors [0-2]

    for (int x = 0; x < img.cols -1 ; x++)
    for (int y = 0; y < img.rows -1 ; y++)

    //Rewrite Original copy by IMG multipy by some value based on SLIDER value
    Original.at<Vec3b>(y, x)[0] = img.at<Vec3b>(y, x)[0]* (iSliderValue1 )/200  ;
        // Do it for another color
    Original.at<Vec3b>(y, x)[1] = img.at<Vec3b>(y, x)[1]* (iSliderValue2 )/200 ;
        // If you wat also for the last one
    Original.at<Vec3b>(y, x)[2] = img.at<Vec3b>(y, x)[2]* (iSliderValue3 )/200 ;


    // Simple slider , parameters are some description R, G and B
    // also some window prew, and update some value
    // the last parameter 215 is maximum value.....
    createTrackbar("R", "prew", &iSliderValue1, 215);
    createTrackbar("G", "prew", &iSliderValue2, 215);
    createTrackbar("B", "prew", &iSliderValue3, 215);

    // show the result
    namedWindow("prew", WINDOW_AUTOSIZE);
    imshow("prew", Original);
    // write the output
    outputVideo << Original;

    int key1 = waitKey(20);


    Share if you like it... Thanks :) 


    Follow by Email

    Powered by Blogger.