practical introduction to (open) computer vision introduction to (open) computer vision hci 2...

82
practical introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Upload: dangthien

Post on 07-May-2018

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

practical introduction to

(open) computer visionhci 2 prototyping :: hasso plattner institutechristian holz

#5

Page 2: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

vision := low-level pixels scene graph

Page 3: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

today’s about image segmentation

Page 4: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 5: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 6: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

30sec brainstorming

Page 7: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

30sec brainstorminghow to count all cars? how to ignore the rest?

Page 8: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 9: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

30sec brainstorminghow to deal with occlusion? illumination?

Page 10: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 11: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 12: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 13: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 14: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 15: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

detecting components = easy

Page 16: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

assignment

Page 17: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

assignment

Page 18: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

goal = drawing

Page 19: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

goal = drawing

Page 20: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

shoes in contact with !oor

Page 21: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

shoes in contact with !oor

Page 22: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 23: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 24: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

30sec brainstorming(top-down camera setup)

Page 25: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

“thresholding”

Page 26: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

“thresholding”

remove everythingfarther than X

turn all values < Xinto black

=

Page 27: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

OpenCV

Page 28: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"

#include <ctype.h>#include <iostream>

using namespace cv;using namespace std;

int main( int argc, char** argv ){ VideoCapture cap; cap.open("video.avi");

if( !cap.isOpened() ) { cout << "Could not initialize capturing...\n"; return -1; }

namedWindow( "output", 0 );

for(;;) { Mat frame; cap >> frame; if( frame.empty() ) { break; } // // do something with frame // //...

imshow( "output", frame );

int c = waitKey(30); if( c == 'q' ) { break; } }

return 0;}

scaffold provided

Page 29: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

OpenCV reference (C++)http://opencv.willowgarage.com/documentation/cpp/

Page 30: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

OpenCV reference (C++)http://opencv.willowgarage.com/documentation/cpp/

Page 31: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

or search for documentation online, e.g. book Learning OpenCV

Page 32: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

cv::Mat img1 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img2 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img3 = cv::Mat( frame.size(), CV_32S );cv::Mat img4 = cv::Mat( frame.size(), CV_32FC2 );

creating images

Page 33: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

cv::Mat img1 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img2 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img3 = cv::Mat( frame.size(), CV_32S );cv::Mat img4 = cv::Mat( frame.size(), CV_32FC2 );

creating images

Page 34: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

cv::Mat img1 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img2 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img3 = cv::Mat( frame.size(), CV_32S );cv::Mat img4 = cv::Mat( frame.size(), CV_32FC2 );

creating images

CV_<bit depth><S/U/F>C<channels>

Page 35: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

cv::Mat img1 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img2 = cv::Mat( frame.size(), CV_8UC1 );cv::Mat img3 = cv::Mat( frame.size(), CV_32S );cv::Mat img4 = cv::Mat( frame.size(), CV_32FC2 );

creating images

img1.copyTo( img2 );

cv::Mat img5 = img1.clone();

Page 36: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

cv::imshow( "output", frame );

showing images

int c = cv::waitKey( 30 );if( c == 'q' ) { break;}

Page 37: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

tabletop systems

Page 38: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

raw image

Page 39: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

threshold

Page 40: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

threshold

double cv::threshold(const cv::Mat& src, cv::Mat& dst, double thresh, double maxVal, int thresholdType);

Page 41: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

threshold

Page 42: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

threshold

Page 43: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

camera image

Page 44: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

threshold

Page 45: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#nd contours

void cv::findContours( const cv::Mat& image, std::vector<std::vector<cv::Point> >& contours, int mode, int method, cv::Point offset = cv::Point());

Page 46: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#nd contours

void cv::findContours( const cv::Mat& image, std::vector<std::vector<cv::Point> >& contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cv::Point offset = cv::Point());

Page 47: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#nd contours

// modi!es imagevoid cv::findContours( const cv::Mat& image, std::vector<std::vector<cv::Point> >& contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cv::Point offset = cv::Point());

Page 48: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#nd contours

Page 49: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#nd contours

what about these?

Page 50: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#nd contours

what about these?

!lter by size, aspect, ...

Page 51: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#ltered contours

double cv::contourArea(const cv::Mat& contour);

// cv::Mat offers a CTOR for std::vector<cv::Point>

Page 52: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

“thresholding”

remove everythingfarther than X

turn all values < Xinto black

=

Page 53: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

remove everythingfarther than X

turn all values < Xinto black

=

“thresholding”

Page 54: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#t ellipse

x, y,minor, majorangle

Page 55: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#t ellipse

x, y,minor, majorangle

cv::RotatedRect cv::fitEllipse(const cv::Mat& points);

Page 56: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

#t ellipse

x, y,minor, majorangle

cv::RotatedRect cv::fitEllipse(const cv::Mat& points);

void cv::ellipse(cv::Mat& img, const cv::RotatedRect& box, const cv::Scalar& color, int thickness = 1, int lineType = 8);

Page 57: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 58: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

we’re done!

Page 59: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

oops, we made one assumption, remember?

Page 60: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

what now?

Page 61: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

what now?

30sec brainstorming

Page 62: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 63: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

“empty” scene (= bg)

Page 64: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

background subtraction

Page 65: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

background subtraction

// several ways

void cv::absdiff(const cv::Mat& src1, const cv::Mat& src2, cv::Mat& dst);

void cv::subtract(const cv::Mat& src1, const cv::Mat& src2, cv::Mat& dst);

void cv::addWeighted(const cv::Mat& src1, double alpha, const cv::Mat& src2, double beta, double gamma, cv::Mat& dst);

// dst = src1 * alpha + src2 * beta + gamma;

Page 66: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 67: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 68: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 69: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 70: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5
Page 71: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Wilson ITS ’10

Page 72: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Wilson ITS ’10

Page 73: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Kinect image

// dst = src * alpha + beta

img1.convertTo( img2, CV_8U, 10.0, -20.0 );

Page 74: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Kinect image

// dst = src * alpha + beta

img1.convertTo( img2, CV_8U, 10.0, -20.0 );

depth

Page 75: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Kinect image

// dst = src * alpha + beta

img1.convertTo( img2, CV_8U, 10.0, -20.0 );

α

Page 76: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

Kinect image

// dst = src * alpha + beta

img1.convertTo( img2, CV_8U, 10.0, -20.0 );

β

Page 77: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

assignment

1) !nd shoes in the depth image

2) draw a circle iff a shoe is making contact with the ground

for those who have done this already:

3) track the shoes

4) draw lines between corresponding circles

Page 78: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

practical introduction to

(open) computer visionhci research :: hasso plattner institutechristian holz

#5

Page 79: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

blur

Page 80: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

blur

void cv::blur(const cv::Mat& src, cv::Mat& dst, cv::Size ksize);

Page 81: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

blur

void cv::blur(const cv::Mat& src, cv::Mat& dst, cv::Size ksize);

odd size

Page 82: practical introduction to (open) computer vision introduction to (open) computer vision hci 2 prototyping :: hasso plattner institute christian holz #5

blur

void cv::blur(const cv::Mat& src, cv::Mat& dst, cv::Size ksize);