Skip to content

Commit

Permalink
Remove opticalflow_aux
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Zhao committed May 12, 2017
1 parent 1ec67b6 commit 76d45ed
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 161 deletions.
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ set(COMMON
set(CODEFILES
run_dense.cpp
oflow.cpp
# patch.cpp
patchgrid.cpp
refine_variational.cpp
# FDF1.0.1/image.c
FDF1.0.1/image.cpp
FDF1.0.1/opticalflow_aux.cpp
)

# GrayScale, Optical Flow
Expand Down
115 changes: 0 additions & 115 deletions src/FDF1.0.1/opticalflow_aux.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions src/FDF1.0.1/opticalflow_aux.h

This file was deleted.

66 changes: 66 additions & 0 deletions src/kernels/flowUtil.cu
Original file line number Diff line number Diff line change
Expand Up @@ -889,4 +889,70 @@ namespace cu {
d_wx, d_wy, src->height, src->width, src->stride);
}


void computeSmoothness(
image_t *dst_horiz, image_t *dst_vert, const image_t *uu, const image_t *vv, float *deriv_flow, const float quarter_alpha) {

const int width = uu->width, height = vv->height, stride = uu->stride;
image_t *ux = image_new(width,height),
*vx = image_new(width,height),
*uy = image_new(width,height),
*vy = image_new(width,height),
*smoothness = image_new(width,height);

// compute derivatives [-0.5 0 0.5]
cu::imageDerivative(ux->c1, uu->c1, deriv_flow, height, width, stride, true);
cu::imageDerivative(vx->c1, vv->c1, deriv_flow, height, width, stride, true);
cu::imageDerivative(uy->c1, uu->c1, deriv_flow, height, width, stride, false);
cu::imageDerivative(vy->c1, vv->c1, deriv_flow, height, width, stride, false);

cu::smoothnessTerm(
dst_horiz->c1, dst_vert->c1, smoothness->c1,
ux->c1, uy->c1, vx->c1, vy->c1,
quarter_alpha, epsilon_smooth,
height, width, stride);

// Cleanup extra columns
for(int j = 0; j < height; j++){
memset(&dst_horiz->c1[j*stride+width-1], 0, sizeof(float)*(stride-width+1));
}
// Cleanup last row
memset( &dst_vert->c1[(height-1)*stride], 0, sizeof(float)*stride);

image_delete(ux); image_delete(uy); image_delete(vx); image_delete(vy);
image_delete(smoothness);
}

void getDerivatives(
const color_image_t *im1, const color_image_t *im2, float *pDeviceKernel,
color_image_t *dx, color_image_t *dy, color_image_t *dt,
color_image_t *dxx, color_image_t *dxy, color_image_t *dyy, color_image_t *dxt, color_image_t *dyt)
{
// derivatives are computed on the mean of the first image and the warped second image
color_image_t *tmp_im2 = color_image_new(im2->width,im2->height);

int height = im2->height;
int width = im2->width;
int stride = im2->stride;

cu::getMeanImageAndDiff(im1->c1, im2->c1, tmp_im2->c1, dt->c1, im1->height, im1->stride);

// compute all other derivatives
cu::colorImageDerivative(dx->c1, tmp_im2->c1, pDeviceKernel, height, width, stride, true); // horizontal
cu::colorImageDerivative(dy->c1, tmp_im2->c1, pDeviceKernel, height, width, stride, false);
cu::colorImageDerivative(dxx->c1, dx->c1, pDeviceKernel, height, width, stride, true);
cu::colorImageDerivative(dxy->c1, dx->c1, pDeviceKernel, height, width, stride, false);
cu::colorImageDerivative(dyy->c1, dy->c1, pDeviceKernel, height, width, stride, false);
cu::colorImageDerivative(dxt->c1, dt->c1, pDeviceKernel, height, width, stride, true);
cu::colorImageDerivative(dyt->c1, dt->c1, pDeviceKernel, height, width, stride, false);

// free memory
color_image_delete(tmp_im2);
}

void subLaplacian(image_t *dst, const image_t *src, const image_t *weight_horiz, const image_t *weight_vert){
cu::subLaplacianHoriz(src->c1, dst->c1, weight_horiz->c1, src->height, src->width, src->stride);
cu::subLaplacianVert(src->c1, dst->c1, weight_vert->c1, src->height, src->stride);
}

}
10 changes: 10 additions & 0 deletions src/kernels/flowUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ namespace cu {
void warpImage(
color_image_t *dst, image_t *mask, const color_image_t *src, const image_t *wx, const image_t *wy);

void computeSmoothness(
image_t *dst_horiz, image_t *dst_vert, const image_t *uu, const image_t *vv, float *deriv_flow, const float quarter_alpha);

void getDerivatives(
const color_image_t *im1, const color_image_t *im2, float *pDeviceKernel,
color_image_t *dx, color_image_t *dy, color_image_t *dt,
color_image_t *dxx, color_image_t *dxy, color_image_t *dyy, color_image_t *dxt, color_image_t *dyt);

void subLaplacian(image_t *dst, const image_t *src, const image_t *weight_horiz, const image_t *weight_vert);

}

#endif // end __KERNEL_FLOW_UTIL_H__
Expand Down
15 changes: 8 additions & 7 deletions src/refine_variational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ namespace OFC {

// warp second image
auto start_image_warp = now();
// image_warp(w_im2, mask, im2, wx, wy);
cu::warpImage(w_im2, mask, im2, wx, wy);
calc_print_elapsed("RefLevelOF image_warp", start_image_warp);

// compute derivatives
auto start_get_derivs = now();
get_derivatives(im1, w_im2, pDeviceColorDerivativeKernel, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz);
cu::getDerivatives(im1, w_im2, pDeviceColorDerivativeKernel, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz);
calc_print_elapsed("RefLevelOF get_derivatives", start_get_derivs);

// erase du and dv
Expand All @@ -190,17 +189,19 @@ namespace OFC {

// compute robust function and system
auto start_smooth = now();
compute_smoothness(smooth_horiz, smooth_vert, uu, vv, pDeviceDerivativeKernel, vr.tmp_quarter_alpha );
cu::computeSmoothness(smooth_horiz, smooth_vert, uu, vv, pDeviceDerivativeKernel, vr.tmp_quarter_alpha );
calc_print_elapsed(("RefLevelOF " + iterStr + " smoothness").c_str(), start_smooth);

auto start_data = now();
// compute_data(a11, a12, a22, b1, b2, mask, wx, wy, du, dv, uu, vv, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz, vr.tmp_half_delta_over3, vr.tmp_half_beta, vr.tmp_half_gamma_over3);
cu::dataTerm(a11, a12, a22, b1, b2, mask, wx, wy, du, dv, uu, vv, Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz, vr.tmp_half_delta_over3, vr.tmp_half_beta, vr.tmp_half_gamma_over3);
cu::dataTerm(a11, a12, a22, b1, b2,
mask, wx, wy, du, dv, uu, vv,
Ix, Iy, Iz, Ixx, Ixy, Iyy, Ixz, Iyz,
vr.tmp_half_delta_over3, vr.tmp_half_beta, vr.tmp_half_gamma_over3);
calc_print_elapsed(("RefLevelOF " + iterStr + " data").c_str(), start_data);

auto start_lapalcian = now();
sub_laplacian(b1, wx, smooth_horiz, smooth_vert);
sub_laplacian(b2, wy, smooth_horiz, smooth_vert);
cu::subLaplacian(b1, wx, smooth_horiz, smooth_vert);
cu::subLaplacian(b2, wy, smooth_horiz, smooth_vert);
calc_print_elapsed(("RefLevelOF " + iterStr + " laplacian").c_str(), start_lapalcian);

// solve system
Expand Down
1 change: 0 additions & 1 deletion src/refine_variational.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define VARREF_HEADER

#include "FDF1.0.1/image.h"
#include "FDF1.0.1/opticalflow_aux.h"

#include "oflow.h"

Expand Down

0 comments on commit 76d45ed

Please sign in to comment.