-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 530910d
Showing
101 changed files
with
10,627 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.o | ||
*.dSYM | ||
*.csv | ||
*.out | ||
*.pyc | ||
.fuse* | ||
libuwimg* | ||
uwimg | ||
*.png | ||
*.jpg | ||
|
||
# OS Generated # | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
OPENCV=1 | ||
OPENMP=0 | ||
DEBUG=0 | ||
|
||
OBJ=load_image.o process_image.o args.o filter_image.o resize_image.o test.o harris_image.o matrix.o panorama_image.o flow_image.o | ||
EXOBJ=main.o | ||
|
||
VPATH=./src/:./ | ||
SLIB=libuwimg.so | ||
ALIB=libuwimg.a | ||
EXEC=uwimg | ||
OBJDIR=./obj/ | ||
|
||
CC=gcc | ||
AR=ar | ||
ARFLAGS=rcs | ||
OPTS=-Ofast | ||
LDFLAGS= -lm -pthread | ||
COMMON= -Iinclude/ -Isrc/ | ||
CFLAGS=-Wall -Wno-unknown-pragmas -Wfatal-errors -fPIC | ||
|
||
ifeq ($(OPENMP), 1) | ||
CFLAGS+= -fopenmp | ||
endif | ||
|
||
ifeq ($(DEBUG), 1) | ||
OPTS=-O0 -g | ||
COMMON= -Iinclude/ -Isrc/ | ||
else | ||
CFLAGS+= -flto | ||
endif | ||
|
||
CFLAGS+=$(OPTS) | ||
|
||
ifeq ($(OPENCV), 1) | ||
COMMON+= -DOPENCV | ||
CFLAGS+= -DOPENCV | ||
LDFLAGS+= `pkg-config --libs opencv` | ||
COMMON+= `pkg-config --cflags opencv` | ||
endif | ||
|
||
EXOBJS = $(addprefix $(OBJDIR), $(EXOBJ)) | ||
OBJS = $(addprefix $(OBJDIR), $(OBJ)) | ||
DEPS = $(wildcard src/*.h) Makefile | ||
|
||
all: obj $(SLIB) $(ALIB) $(EXEC) | ||
#all: obj $(EXEC) | ||
|
||
|
||
$(EXEC): $(EXOBJS) $(OBJS) | ||
$(CC) $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
|
||
$(ALIB): $(OBJS) | ||
$(AR) $(ARFLAGS) $@ $^ | ||
|
||
$(SLIB): $(OBJS) | ||
$(CC) $(CFLAGS) -shared $^ -o $@ $(LDFLAGS) | ||
|
||
$(OBJDIR)%.o: %.c $(DEPS) | ||
$(CC) $(COMMON) $(CFLAGS) -c $< -o $@ | ||
|
||
obj: | ||
mkdir -p obj | ||
|
||
.PHONY: clean | ||
|
||
clean: | ||
rm -rf $(OBJS) $(SLIB) $(ALIB) $(EXEC) $(EXOBJS) $(OBJDIR)/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# CSE 455 Homework 3 # | ||
|
||
Welcome friends, | ||
|
||
It's time for optical flow! | ||
|
||
To start out this homework, copy over your `process_image.c`, `filter_image.c`, `resize_image.c`, `harris_image.c`, and`panorama_image.c` files from hw1 to the `src` file in this homework. We will be continuing to build out your image library. | ||
|
||
## 1.1 Integral images ## | ||
|
||
Optical flow has to run on video so it needs to be fast! We'll be calculating structure matrices again so we need to do aggregated sums over regions of the image. However, instead of smoothing with a Gaussian filter, we'll use [integral images](https://en.wikipedia.org/wiki/Summed-area_table) to simulate smoothing with a box filter. | ||
|
||
Fill in `make_integral_image` as described in the wikipedia article. You may not want to use the `get_pixel` methods unless you do bounds checking so you don't run into trouble. | ||
|
||
## 1.2 Smoothing using integral images ## | ||
|
||
We can use our integral image to quickly calculate the sum of regions of an image. Fill in `box_filter_image` so that every pixel in the output is the average of pixels in a given window size. | ||
|
||
## 2. Lucas-Kanade optical flow ## | ||
|
||
We'll be implementing [Lucas-Kanade](https://en.wikipedia.org/wiki/Lucas%E2%80%93Kanade_method) optical flow. We'll use a structure matrix but this time with temporal information as well. The equation we'll use is: | ||
|
||
![][figs/flow-eq.png] | ||
|
||
## 2.1 Time-structure matrix ## | ||
|
||
We'll need spatial and temporal gradient information for the flow equations. Calculate a time-structure matrix. Spatial gradients can be calculated as normal. The time gradient can be calculated as the difference between the previous image and the next image in a sequence. Fill in `time_structure_matrix`. | ||
|
||
## 2.2 Calculating velocity from the structure matrix ## | ||
|
||
Fill in `velocity_image` to use the equation to calculate the velocity of each pixel in the x and y direction. For each pixel, fill in the `matrix M`, invert it, and use it to calculate the velocity. | ||
|
||
Try calculating the optical flow between two dog images: | ||
|
||
a = load_image("data/dog_a.png") | ||
b = load_image("data/dog_b.png") | ||
flow = optical_flow_images(b, a, 15, 8) | ||
draw_flow(a, flow, 8) | ||
save_image(a, "lines") | ||
|
||
It may look something like: | ||
|
||
![][lines.jpg] | ||
|
||
## 3. Optical flow demo using OpenCV ## | ||
|
||
Using OpenCV we can get images from the webcam and display the results in real-time. Try installing OpenCV and enabling OpenCV compilation in the Makefile (set `OPENCV=1`). Then run: | ||
|
||
optical_flow_webcam(15,4,8) | ||
|
||
|
||
## 4. Turn it in ## | ||
|
||
Turn in your `flow_image.c` on canvas under Assignment 3. | ||
|
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "args.h" | ||
|
||
void del_arg(int argc, char **argv, int index) | ||
{ | ||
int i; | ||
for(i = index; i < argc-1; ++i) argv[i] = argv[i+1]; | ||
argv[i] = 0; | ||
} | ||
|
||
int find_arg(int argc, char* argv[], char *arg) | ||
{ | ||
int i; | ||
for(i = 0; i < argc; ++i) { | ||
if(!argv[i]) continue; | ||
if(0==strcmp(argv[i], arg)) { | ||
del_arg(argc, argv, i); | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
int find_int_arg(int argc, char **argv, char *arg, int def) | ||
{ | ||
int i; | ||
for(i = 0; i < argc-1; ++i){ | ||
if(!argv[i]) continue; | ||
if(0==strcmp(argv[i], arg)){ | ||
def = atoi(argv[i+1]); | ||
del_arg(argc, argv, i); | ||
del_arg(argc, argv, i); | ||
break; | ||
} | ||
} | ||
return def; | ||
} | ||
|
||
float find_float_arg(int argc, char **argv, char *arg, float def) | ||
{ | ||
int i; | ||
for(i = 0; i < argc-1; ++i){ | ||
if(!argv[i]) continue; | ||
if(0==strcmp(argv[i], arg)){ | ||
def = atof(argv[i+1]); | ||
del_arg(argc, argv, i); | ||
del_arg(argc, argv, i); | ||
break; | ||
} | ||
} | ||
return def; | ||
} | ||
|
||
char *find_char_arg(int argc, char **argv, char *arg, char *def) | ||
{ | ||
int i; | ||
for(i = 0; i < argc-1; ++i){ | ||
if(!argv[i]) continue; | ||
if(0==strcmp(argv[i], arg)){ | ||
def = argv[i+1]; | ||
del_arg(argc, argv, i); | ||
del_arg(argc, argv, i); | ||
break; | ||
} | ||
} | ||
return def; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef ARGS_H | ||
#define ARGS_H | ||
|
||
int find_arg(int argc, char* argv[], char *arg); | ||
int find_int_arg(int argc, char **argv, char *arg, int def); | ||
float find_float_arg(int argc, char **argv, char *arg, float def); | ||
char *find_char_arg(int argc, char **argv, char *arg, char *def); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#ifndef IMAGE_H | ||
#define IMAGE_H | ||
|
||
#include "matrix.h" | ||
#define TWOPI 6.2831853 | ||
|
||
#define MIN(a,b) (((a)<(b))?(a):(b)) | ||
#define MAX(a,b) (((a)>(b))?(a):(b)) | ||
|
||
// DO NOT CHANGE THIS FILE | ||
|
||
typedef struct{ | ||
int w,h,c; | ||
float *data; | ||
} image; | ||
|
||
// A 2d point. | ||
// float x, y: the coordinates of the point. | ||
typedef struct{ | ||
float x, y; | ||
} point; | ||
|
||
// A descriptor for a point in an image. | ||
// point p: x,y coordinates of the image pixel. | ||
// int n: the number of floating point values in the descriptor. | ||
// float *data: the descriptor for the pixel. | ||
typedef struct{ | ||
point p; | ||
int n; | ||
float *data; | ||
} descriptor; | ||
|
||
// A match between two points in an image. | ||
// point p, q: x,y coordinates of the two matching pixels. | ||
// int ai, bi: indexes in the descriptor array. For eliminating duplicates. | ||
// float distance: the distance between the descriptors for the points. | ||
typedef struct{ | ||
point p, q; | ||
int ai, bi; | ||
float distance; | ||
} match; | ||
|
||
// Basic operations | ||
float get_pixel(image im, int x, int y, int c); | ||
void set_pixel(image im, int x, int y, int c, float v); | ||
image copy_image(image im); | ||
image rgb_to_grayscale(image im); | ||
image grayscale_to_rgb(image im, float r, float g, float b); | ||
void rgb_to_hsv(image im); | ||
void hsv_to_rgb(image im); | ||
void shift_image(image im, int c, float v); | ||
void scale_image(image im, int c, float v); | ||
void clamp_image(image im); | ||
image get_channel(image im, int c); | ||
int same_image(image a, image b); | ||
image sub_image(image a, image b); | ||
image add_image(image a, image b); | ||
|
||
// Loading and saving | ||
image make_image(int w, int h, int c); | ||
image load_image(char *filename); | ||
void save_image(image im, const char *name); | ||
void save_png(image im, const char *name); | ||
void free_image(image im); | ||
|
||
// Resizing | ||
float nn_interpolate(image im, float x, float y, int c); | ||
image nn_resize(image im, int w, int h); | ||
float bilinear_interpolate(image im, float x, float y, int c); | ||
image bilinear_resize(image im, int w, int h); | ||
|
||
// Filtering | ||
image convolve_image(image im, image filter, int preserve); | ||
image make_box_filter(int w); | ||
image make_highpass_filter(); | ||
image make_sharpen_filter(); | ||
image make_emboss_filter(); | ||
image make_gaussian_filter(float sigma); | ||
image make_gx_filter(); | ||
image make_gy_filter(); | ||
void feature_normalize(image im); | ||
void l1_normalize(image im); | ||
void threshold_image(image im, float thresh); | ||
image *sobel_image(image im); | ||
image colorize_sobel(image im); | ||
image smooth_image(image im, float sigma); | ||
|
||
// Harris and Stitching | ||
image structure_matrix(image im, float sigma); | ||
image cornerness_response(image S); | ||
void free_descriptors(descriptor *d, int n); | ||
image cylindrical_project(image im, float f); | ||
void mark_corners(image im, descriptor *d, int n); | ||
image find_and_draw_matches(image a, image b, float sigma, float thresh, int nms); | ||
void detect_and_draw_corners(image im, float sigma, float thresh, int nms); | ||
int model_inliers(matrix H, match *m, int n, float thresh); | ||
image combine_images(image a, image b, matrix H); | ||
match *match_descriptors(descriptor *a, int an, descriptor *b, int bn, int *mn); | ||
descriptor *harris_corner_detector(image im, float sigma, float thresh, int nms, int *n); | ||
image panorama_image(image a, image b, float sigma, float thresh, int nms, float inlier_thresh, int iters, int cutoff); | ||
|
||
// Optical Flow | ||
image optical_flow_images(image im, image prev, int smooth, int stride); | ||
void optical_flow_webcam(int smooth, int stride, int div); | ||
void draw_flow(image im, image v, float scale); | ||
|
||
#ifndef __cplusplus | ||
#ifdef OPENCV | ||
#include "opencv2/highgui/highgui_c.h" | ||
#include "opencv2/imgproc/imgproc_c.h" | ||
#include "opencv2/core/version.hpp" | ||
#if CV_MAJOR_VERSION == 3 | ||
#include "opencv2/videoio/videoio_c.h" | ||
#include "opencv2/imgcodecs/imgcodecs_c.h" | ||
#endif | ||
image get_image_from_stream(CvCapture *cap); | ||
int show_image(image im, const char *name, int ms); | ||
#endif | ||
#endif | ||
|
||
#endif | ||
|
Oops, something went wrong.