The goal of this section is to present you to most interesting OpenCV python samples provided with OpenCV. Some are pretty smart and deserve to be quickly commented on how they works and what are the others possible applications of the technology they use. They all can be downloaded on the official website here, but I had also put them with my sources here or on my Github.
The goal of this script is to calculate the minimum area to enclose a set of points generated on an image. Points are surronded by both a circle and a rectangle. OpenCV provides two functions to do it MinEnclosingCircle which takes in argument a list of points and MinAreaRect2 which also takes a list of points.
Motempl does a similar jobs than the examples in the tutorial for motion detection with the background but in far more complex. If you take a look at the script it uses various complex functions like UpdateMotionHistory to keep a motion history,CalcMotionGradient,SegmentMotion or_CalcGlobalOrientation_. I strongly recommend you to try to understand it and even more if you are interested in movement detection, background detection etc.
This script on multiples aspect. First it shows all the functionalities of HighGUI by showing how to grab a mouse click and mouse movement. Second it shows how to use the watershed algorithm which is not easy to use.
As you can guess this script show an example of the usage of CalcOpticalFlowPyrLK. This script shows another way to detect corner and as we can see it is really efficient. It basically works the same way than showed in the tutorial for edge detection but a way smarter.
- It convert the image in black and white
- It uses GoodFeaturesToTrack to find edges
- Then the script call FindCornerSubPix to refine the corners location
- Call CalcOpticalFlowPyrLK and keep only points that have a good status
This script intent to track movement using CalcOpticalFlowFarneback. In this case all the points are static and can track a movement the direction and the speed. Indeed longer the line is faster the object is moving. The code itself is quite fair and straightforward.
This script is for far the smarter of all. It assemble the best OpenCV technology in a script. It use the HSV colorspace to work. Then it uses histograms and backprojection associated with the camshift algorithm. Camshift is the ultimate algorithm to track evey object over an image whatever his size or his color. Anymore the code is pretty smart and well-commented so don’t hesitate to take a look !