Fun Computer Vision opencv tutorials and ..

Multiple people tracking 

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 colors channels

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<Vec3b>(y, x)[0]    to Access the pixel at Y and X position. !For 0 color channel. 
and this<Vec3b>(y, x)[1]    Same but different color. 
and also<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;"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<Vec3b>(y, x)[0] =<Vec3b>(y, x)[0]* (iSliderValue1 )/200  ;
    // Do it for another color<Vec3b>(y, x)[1] =<Vec3b>(y, x)[1]* (iSliderValue2 )/200 ;
    // If you wat also for the last one<Vec3b>(y, x)[2] =<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 :) 

opencv tracking

opencv tutorial

Opencv Simple instalation.

From Opencv 3.0 Cmake to Opencv 3.1 prebuild Libs

I wrote about opencv instalation since the release of version 3 and Visual Studio 2015.. In early build of opencv 3.0 there is no precompiled library for VS2015 and I wrote about instalation using CMAKE here . This is still usefull when you need non standard capabilities. You can manage build process and target specific functions and properties. Opencv version 3.1 was shipped with prebuild libs for Visual studio 2015 and everithing is much more simple.. Instation and basic setup is discussed in tutorial here .

Install Opencv, Visual studio 2015 with NUGET

The most simple way without setting the global enviromental variables and staff like location of headers and libs is use the NUGET packages.. 

You can install in nuget package console.. DONT be afraid of CONSOLE. PLEASE. 

1.Open Nuget console 

2. Create empty Visual C++ project

3. Add a source File and write some code.. 

4. Add NUGET package

5. Compile and have a fun.. RLY simple in less than 4 minutes.. 

Again please dont be afraid of console again.. This is much more simple than anaything.. 

Opencv Nuget Console options 

After the PM> you can write commands for Nuger console.. And install Opencv is rly simple. For default configuration like in prebuild libs just use.. 

Opencv Default Build 3.1.0

PM>  Install-Package opencvdefault

Enabled advanced CPU instructions. With OpenMP. No TBB/IPP. vc12/vc14, x64/x86 available.

PM>  Install-Package opencv3.1



Opencv NUGET console

Opencv install

Opencv 3.1

Opencv Installation NUGET

Opencv Install

opencv 3,1 nuget

opencv 3.1 nuget instal visual studio

Feel free to share this article.. Thanks a lot

My iceland video tracking example

Video tracking stabilization opencv

i know that, I did not write anything interesting for a long time.. I am working on it..

Transparent mask tutorial is Here

Feel free to share this article.. Thanks a lot

Microsoft cognitive-services VS Google Vision API

Which image api recognition engine is bigger gentleman ?

Check the result.. This is just a funny comparison.. I did not mean this rude. You get it, when you check the result of this outstanding api..  Microsoft has realy truly stunning results. 

Microsoft cognitive-services VS Google Vision API

Microsoft cognitive-services image clasification result

{ "text": "a beautiful woman standing on a beach", "confidence": 0.6798031586203954 }

There is much more information about the image and they are impresive.. A beautiful woman.. Ok lets check google result,, 

Google vision api More neutral 

and let say, More or less ok.. 

"description": "clothing",  "description": "vacation", ¨description": "beauty", 
  "description": "photo shoot",  "description": "sun tanning",  "description": "sports",
 "description": "volleyball",

Microsoft cognitive-services VS Google Vision API

Microsoft cognitive-services image clasification result

{ "text": "a woman walking down a beach next to the ocean", "confidence": 0.5507436156974482 } ] }

Google vision api More neutral 

"description": "clothing", "description": "vacation", "description": "black hair", "description": "beauty", "description": "sea", "description": "model", "description": "swimwear",  "description": "supermodel",  "description": "photo shoot",

Feel free to share this article.. Thanks a lot

I will be back soon. Tutorials and more about Computer vision, technology and more

Blog techblog computer vision

Fotka zveřejněná uživatelem @vladakuc,
Fotka zveřejněná uživatelem @vladakuc,

Fotka zveřejněná uživatelem @vladakuc,

Median flow tracker code coming soon

  • Simple median flow tracker base od goodFeaturesToTrack
  •  calcOpticalFlowPyrLK
  • TODO complete forward backwards tracking and feature filtering. I already have forward, backwards LK tracker, without filtering (just prepared NORM computation).
  • TODO complete redetection. White rectangles are redetection with online learning by RTrees opencv 3.1 support. Rtrees work great. I only need better features. Do you have any advice or tips?
  • From the initial Rectangle is generated several positive examples and negatives from the rest of image. Rtrees learning and prediction can run very fast. I still haven't got a good features. Feature extracting took some time to. 
  • TODO Forward backward + redetection. 
  • 300 lines of code 
Final result will be 

TLD tracker

I would like to release this in 4 next tutorials. 

Forward backwards median flow tracker

Rtrees learning ( new features ) and prediction with single scale detection sliding window

Complete TLD tracker

Slow Multi target TLD tracker

Share please

Feel free to share this article.. Thanks a lot

Featured Post

Opencv 3.1 Tutorial Optical flow (calcOpticalFlowFarneback)

Farneback Optical flow Share this for more tutorials and computer vision post from me.. Thanks best Vladimir Optical Fl...

Thanks for sharing. ;)


Popular Posts

Powered by Blogger.

Follow by Email