From 4c89f06b3cc20affaa95e89e16d8db6637f1c86b Mon Sep 17 00:00:00 2001 From: Dan Zhu Date: Tue, 23 Jul 2019 10:03:15 -0700 Subject: [PATCH] Change the child classes methods names to align with parent's Add comments to explain the coordinate system Change-Id: Ib87ae479e08b4e3c3e7d9a3d1b4ab30718b42cfd --- tools/3D-Reconstruction/MotionEST/Exhaust.py | 15 ++++++++------- tools/3D-Reconstruction/MotionEST/HornSchunck.py | 7 +++---- tools/3D-Reconstruction/MotionEST/Util.py | 2 ++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/3D-Reconstruction/MotionEST/Exhaust.py b/tools/3D-Reconstruction/MotionEST/Exhaust.py index 3c03468..83ca157 100644 --- a/tools/3D-Reconstruction/MotionEST/Exhaust.py +++ b/tools/3D-Reconstruction/MotionEST/Exhaust.py @@ -30,7 +30,7 @@ class Exhaust(MotionEST): """ def search(self, cur_r, cur_c): - min_loss = self.dist(cur_r, cur_c, [0, 0], self.metric) + min_loss = self.block_dist(cur_r, cur_c, [0, 0], self.metric) cur_x = cur_c * self.blk_sz cur_y = cur_r * self.blk_sz ref_x = cur_x @@ -39,14 +39,15 @@ class Exhaust(MotionEST): for y in xrange(cur_y - self.wnd_sz, cur_y + self.wnd_sz): for x in xrange(cur_x - self.wnd_sz, cur_x + self.wnd_sz): if 0 <= x < self.width - self.blk_sz and 0 <= y < self.height - self.blk_sz: - loss = self.dist(cur_r, cur_c, [y - cur_y, x - cur_x], self.metric) + loss = self.block_dist(cur_r, cur_c, [y - cur_y, x - cur_x], + self.metric) if loss < min_loss: min_loss = loss ref_x = x ref_y = y return ref_x, ref_y - def est(self): + def motion_field_estimation(self): for i in xrange(self.num_row): for j in xrange(self.num_col): ref_x, ref_y = self.search(i, j) @@ -101,7 +102,7 @@ class ExhaustNeighbor(MotionEST): """ def search(self, cur_r, cur_c): - dist_loss = self.dist(cur_r, cur_c, [0, 0], self.metric) + dist_loss = self.block_dist(cur_r, cur_c, [0, 0], self.metric) nb_loss = self.neighborLoss(cur_r, cur_c, np.array([0, 0])) min_loss = dist_loss + self.beta * nb_loss cur_x = cur_c * self.blk_sz @@ -113,8 +114,8 @@ class ExhaustNeighbor(MotionEST): for y in xrange(cur_y - self.wnd_sz, cur_y + self.wnd_sz): for x in xrange(cur_x - self.wnd_sz, cur_x + self.wnd_sz): if 0 <= x < self.width - self.blk_sz and 0 <= y < self.height - self.blk_sz: - dist_loss = self.dist(cur_r, cur_c, [y - cur_y, x - cur_x], - self.metric) + dist_loss = self.block_dist(cur_r, cur_c, [y - cur_y, x - cur_x], + self.metric) nb_loss = self.neighborLoss(cur_r, cur_c, [y - cur_y, x - cur_x]) loss = dist_loss + self.beta * nb_loss if loss < min_loss: @@ -123,7 +124,7 @@ class ExhaustNeighbor(MotionEST): ref_y = y return ref_x, ref_y - def est(self): + def motion_field_estimation(self): for i in xrange(self.num_row): for j in xrange(self.num_col): ref_x, ref_y = self.search(i, j) diff --git a/tools/3D-Reconstruction/MotionEST/HornSchunck.py b/tools/3D-Reconstruction/MotionEST/HornSchunck.py index 0bf431c..38fcae1 100644 --- a/tools/3D-Reconstruction/MotionEST/HornSchunck.py +++ b/tools/3D-Reconstruction/MotionEST/HornSchunck.py @@ -120,7 +120,7 @@ class HornSchunck(MotionEST): avg[i, j] += self.mf[i + r, j + c] / 12.0 return avg - def est(self): + def motion_field_estimation(self): count = 0 """ u_{n+1} = ~u_n - Ix(Ix.~u_n+Iy.~v+It)/(IxIx+IyIy+alpha^2) @@ -136,7 +136,7 @@ class HornSchunck(MotionEST): count += 1 self.mf *= self.blk_sz - def est_mat(self): + def motion_field_estimation_mat(self): row_idx = [] col_idx = [] data = [] @@ -145,8 +145,7 @@ class HornSchunck(MotionEST): b = np.zeros((N, 1)) for i in xrange(self.num_row): for j in xrange(self.num_col): - """(IxIx+alpha^2)u+IxIy.v-alpha^2~u IxIy.u+(IyIy+alpha^2)v-alpha^2~v - """ + """(IxIx+alpha^2)u+IxIy.v-alpha^2~u IxIy.u+(IyIy+alpha^2)v-alpha^2~v""" u_idx = i * 2 * self.num_col + 2 * j v_idx = u_idx + 1 b[u_idx, 0] = -self.Ix[i, j] * self.It[i, j] diff --git a/tools/3D-Reconstruction/MotionEST/Util.py b/tools/3D-Reconstruction/MotionEST/Util.py index f1a0cd4..d52e8a5 100644 --- a/tools/3D-Reconstruction/MotionEST/Util.py +++ b/tools/3D-Reconstruction/MotionEST/Util.py @@ -32,6 +32,8 @@ def drawMF(img, blk_sz, mf): for i in xrange(num_row): for j in xrange(num_col): center = (j * blk_sz + 0.5 * blk_sz, i * blk_sz + 0.5 * blk_sz) + """mf[i,j][0] is the row shift and mf[i,j][1] is the column shift In PIL coordinates, head[0] is x (column shift) and head[1] is y (row shift). + """ head = (center[0] + mf[i, j][1], center[1] + mf[i, j][0]) draw.line([center, head], fill=(255, 0, 0, 255)) return Image.alpha_composite(img_rgba, mf_layer) -- 2.7.4