Upgrade to Pro — share decks privately, control downloads, hide ads and more …

It seeeeeez! - Computer Vision with OpenCV

It seeeeeez! - Computer Vision with OpenCV

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

Marcel Neidinger

April 27, 2017
Tweet

More Decks by Marcel Neidinger

Other Decks in Programming

Transcript

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

    View Slide

  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
    gradI(x, y, t) = grad˜
    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
    )
    = −(grad˜
    I ·⃗
    v) (3)
    It seeeeeez! Computer Vision with OpenCV 2 / 1

    View Slide

  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
    gradI(x, y, t) = grad˜
    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
    )
    = −(grad˜
    I ·⃗
    v) (3)
    It seeeeeez! Computer Vision with OpenCV 2 / 1

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  13. Loading an image
    #include
    int main(int argc, char** argv)
    {
    cv::Mat img;
    img = cv::imread(argv[1]);
    }
    It seeeeeez! Computer Vision with OpenCV 7 / 1

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  20. Beyond the scope
    This barely scratched the surface of what OpenCV can do
    Advanced object detection
    Advanced feature selection
    Advanced tracking and object recognition methods
    Video analysis capabilities
    Machine Learning Capabilities(Boosting, Cascaders, k-nearest
    Neighbor …)
    Support for OpenCL and CUDA
    Integration into e.g. TensorFlow
    It seeeeeez! Computer Vision with OpenCV 14 / 1

    View Slide

  21. Beyond the scope
    This barely scratched the surface of what OpenCV can do
    Advanced object detection
    Advanced feature selection
    Advanced tracking and object recognition methods
    Video analysis capabilities
    Machine Learning Capabilities(Boosting, Cascaders, k-nearest
    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

    View Slide

  22. Questions?

    View Slide