# Assignment 4: Block Matching and Harris Corner Detection
Gruppe 2: Albrecht Oster, Linus Helfmann
## Ex. 4.1 Dense Optical Flow by Block Matching
* implement the block matching method as shown in the lecture
* take two frames from the datasets "lane_detection" or "racecar" with variable distances in time (1, 2, x) and compute the vector flow field
* display a subset of flow vectors on the gray-value version of the first image, by drawing a respective line. adjust the grid density such that not too many vectors overlap (**RESULT**)
%% Cell type:code id: tags:
``` python
%matplotlib inline
import matplotlib.pyplot as plt
from skimage import io, data, feature, color, draw
from scipy import ndimage
import numpy as np
import cv2
car1 = io.imread('images/racecar/100.jpeg')
car2 = io.imread('images/racecar/102.jpeg')
fig = plt.figure(figsize=(15, 10))
ax1 = plt.subplot(1, 2, 1)
ax2 = plt.subplot(1, 2, 2)
ax1.imshow(car1)
ax2.imshow(car2)
```
%% Output
<matplotlib.image.AxesImage at 0x7ff2ffcfe2e8>
%% Cell type:code id: tags:
``` python
BLOCK_RADIUS = 20 #radius des Quadrats das verglichen wird
COMPARE_RADIUS = 20 #wie viele pixel in jede richtung vergleichen wir
STEP_SIZE = 30 # alle wie viele Pixel nehmen wir einen messpunkt
BORDER = BLOCK_RADIUS + COMPARE_RADIUS
def SSD(image1,image2,x1,y1,x2,y2,comp_sum):
#TODO zu nah am Rand abfangen
sum_pixel = 0
for x in range(-BLOCK_RADIUS, BLOCK_RADIUS+1):
for y in range(-BLOCK_RADIUS, BLOCK_RADIUS+1):
#I = image1[y1+y, x1+x].astype(int)
#J = image2[y2+y, x2+x].astype(int)
#sum_pixel += (I[0]-J[0])**2 + (I[1]-J[1])**2 + (I[2]-J[2])**2 #TODO evtl. direkt auf grau-Bild