Marcel Neidinger
April 27, 2017
180

# It seeeeeez! - Computer Vision with OpenCV

A (more scientific) little workshop on computer vision with C++/OpenCV.

April 27, 2017

## Transcript

1. It seeeeeez!
Computer Vision with OpenCV
Marcel Neidinger
Department of Mathematics and Computer Science,
University of Basel
April 27, 2017

2. Derivation of Gradient Form for Images
Introduce transformation V : R3 → R2
(
3
x
)
yt →
(
2
x − v1t
)
y − v2t (1)
Rewrite I(x, y, t) = ˜
I(V(x, y, t)) and use chain-rule for
derivative
I(x − v1t, y − v2t) ·
(
1 0 −v1
0 1 −v2
)
(2)
We search for ∂I
∂t
→ third component
∂I
∂t
= −
(
v1
·
∂I
∂x
+ v2
∂I
∂y
)
I ·⃗
v) (3)
It seeeeeez! Computer Vision with OpenCV 2 / 1

3. Derivation of Gradient Form for Images
Introduce transformation V : R3 → R2
(
3
x
)
yt →
(
2
x − v1t
)
y − v2t (1)
Rewrite I(x, y, t) = ˜
I(V(x, y, t)) and use chain-rule for
derivative
I(x − v1t, y − v2t) ·
(
1 0 −v1
0 1 −v2
)
(2)
We search for ∂I
∂t
→ third component
∂I
∂t
= −
(
v1
·
∂I
∂x
+ v2
∂I
∂y
)
I ·⃗
v) (3)
It seeeeeez! Computer Vision with OpenCV 2 / 1

4. OpenCV is practical
It seeeeeez! Computer Vision with OpenCV 3 / 1

5. OpenCV: History
Started at Intel Research
Cross-plattform library for CV
Today: More then a CV Library (machine learning)
It seeeeeez! Computer Vision with OpenCV 4 / 1

6. Programming OpenCV
+ =
It seeeeeez! Computer Vision with OpenCV 5 / 1

7. Programming OpenCV
+ =
It seeeeeez! Computer Vision with OpenCV 5 / 1

8. Programming OpenCV
+ =
It seeeeeez! Computer Vision with OpenCV 5 / 1

9. Programming OpenCV
+ =
It seeeeeez! Computer Vision with OpenCV 5 / 1

10. Programming OpenCV
OpenCV is polygamous.
- Florian Spiess
It seeeeeez! Computer Vision with OpenCV 6 / 1

11. Programming OpenCV
OpenCV is polygamous.
- Florian Spiess
We will still use C++ in this workshop.
Why?
It’s the root language of OpenCV(fastest)
Most examples are in C++(followed by python)
It seeeeeez! Computer Vision with OpenCV 6 / 1

12. Programming OpenCV
OpenCV is polygamous.
- Florian Spiess
We will still use C++ in this workshop.
Why?
It’s the root language of OpenCV(fastest)
Most examples are in C++(followed by python)
I’m a c++ fanboy and this is my workshop
It seeeeeez! Computer Vision with OpenCV 6 / 1

#include
int main(int argc, char** argv)
{
cv::Mat img;
}
It seeeeeez! Computer Vision with OpenCV 7 / 1

14. Displaying the image
[...]
cv::namedWindow(”debug”, cv::CV_WINDOW_AUTOSIZE);
imshow(”debug”, img);
while( true )
{
if( cv::waitKey(0) != −1 )
{
break;
}
}
It seeeeeez! Computer Vision with OpenCV 8 / 1

15. Theory: Segmenting images
It seeeeeez! Computer Vision with OpenCV 9 / 1

16. Segementation in OpenCV
// Create new image to store greyscale
cv::Mat imgGray, imgThresh;
cv::cvtColor( img, imgGray, cv::CV_BGR2GRAY );
// Threshold
int value = 20;
int maxval = 255;
cv::threshold( imgGray, imgThresh, value, maxval,
cv::THRESH_BINARY);
dst(x, y) =
{
maxval, if src(x, y) > value
0, else
(4)
It seeeeeez! Computer Vision with OpenCV 10 / 1

17. OpenCV: Finding contours
std::vector > contours;
std::vector hierarchy;
cv::findContours( imgThresh, contours, hierarchy,
CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::
Point(0,0) );
It seeeeeez! Computer Vision with OpenCV 11 / 1

18. OpenCV: Practical example
Enough examples.
Let’s write a tennis ball
tracker
It seeeeeez! Computer Vision with OpenCV 12 / 1

19. OpenCV: And moving images?
VideoCapture cap(0);
if( !cap.isOpened() )
{
return −1;
}
for(;;)
{
Mat frame;
cap >> frame;
// Treat like normal picture
}
It seeeeeez! Computer Vision with OpenCV 13 / 1

20. Beyond the scope
This barely scratched the surface of what OpenCV can do
Advanced tracking and object recognition methods
Video analysis capabilities
Neighbor …)
Support for OpenCL and CUDA
Integration into e.g. TensorFlow
It seeeeeez! Computer Vision with OpenCV 14 / 1

21. Beyond the scope
This barely scratched the surface of what OpenCV can do
Advanced tracking and object recognition methods
Video analysis capabilities
Neighbor …)
Support for OpenCL and CUDA
Integration into e.g. TensorFlow
Theorem
Rule of Thumb: If there is an algorithm in computer vision,
OpenCV has a highly optimized implementation readily available.
It seeeeeez! Computer Vision with OpenCV 14 / 1

22. Questions?