ref: 39c02a7eb101b9b4a3b7437b96df3b7b5ddaa5a6
parent: 7378c04420fae166a560ec2f46e0123914d7a967
author: Angie Chiang <angiebird@google.com>
date: Tue Sep 11 11:51:54 EDT 2018
Dump ref frame when DUMP_TPL_STATS is on Also add a python script to parse the dumped results. Change-Id: I1abea5a7c04d852ec40ce37d758af21960b6e589
--- /dev/null
+++ b/tools/non_greedy_mv/non_greedy_mv.py
@@ -1,0 +1,149 @@
+import sys
+import matplotlib.pyplot as plt
+from matplotlib.collections import LineCollection
+from matplotlib import colors as mcolors
+import numpy as np
+
+
+def draw_mv_ls(axis, mv_ls, mode=0):
+ colors = np.array([(0., 0., 0., 1.)])
+ segs = np.array([
+ np.array([[ptr[0], ptr[1]], [ptr[0] + ptr[2], ptr[1] + ptr[3]]])
+ for ptr in mv_ls
+ ])
+ line_segments = LineCollection(
+ segs, linewidths=(1.,), colors=colors, linestyle='solid')
+ axis.add_collection(line_segments)
+ if mode == 0:
+ axis.scatter(mv_ls[:, 0], mv_ls[:, 1], s=2, c='b')
+ else:
+ axis.scatter(
+ mv_ls[:, 0] + mv_ls[:, 2], mv_ls[:, 1] + mv_ls[:, 3], s=2, c='b')
+
+
+def draw_pred_block_ls(axis, mv_ls, bs, mode=0):
+ colors = np.array([(0., 0., 0., 1.)])
+ segs = []
+ for ptr in mv_ls:
+ if mode == 0:
+ x = ptr[0]
+ y = ptr[1]
+ else:
+ x = ptr[0] + ptr[2]
+ y = ptr[1] + ptr[3]
+ x_ls = [x, x + bs, x + bs, x, x]
+ y_ls = [y, y, y + bs, y + bs, y]
+
+ segs.append(np.column_stack([x_ls, y_ls]))
+ line_segments = LineCollection(
+ segs, linewidths=(.5,), colors=colors, linestyle='solid')
+ axis.add_collection(line_segments)
+
+
+def read_frame(fp, no_swap=0):
+ plane = [None, None, None]
+ for i in range(3):
+ line = fp.readline()
+ word_ls = line.split()
+ word_ls = [int(item) for item in word_ls]
+ rows = word_ls[0]
+ cols = word_ls[1]
+
+ line = fp.readline()
+ word_ls = line.split()
+ word_ls = [int(item) for item in word_ls]
+
+ plane[i] = np.array(word_ls).reshape(rows, cols)
+ if i > 0:
+ plane[i] = plane[i].repeat(2, axis=0).repeat(2, axis=1)
+ plane = np.array(plane)
+ if no_swap == 0:
+ plane = np.swapaxes(np.swapaxes(plane, 0, 1), 1, 2)
+ return plane
+
+
+def yuv_to_rgb(yuv):
+ #mat = np.array([
+ # [1.164, 0 , 1.596 ],
+ # [1.164, -0.391, -0.813],
+ # [1.164, 2.018 , 0 ] ]
+ # )
+ #c = np.array([[ -16 , -16 , -16 ],
+ # [ 0 , -128, -128 ],
+ # [ -128, -128, 0 ]])
+
+ mat = np.array([[1, 0, 1.4075], [1, -0.3445, -0.7169], [1, 1.7790, 0]])
+ c = np.array([[0, 0, 0], [0, -128, -128], [-128, -128, 0]])
+ mat_c = np.dot(mat, c)
+ v = np.array([mat_c[0, 0], mat_c[1, 1], mat_c[2, 2]])
+ mat = mat.transpose()
+ rgb = np.dot(yuv, mat) + v
+ rgb = rgb.astype(int)
+ rgb = rgb.clip(0, 255)
+ return rgb / 255.
+
+
+def read_frame_dpl_stats(fp):
+ line = fp.readline()
+ word_ls = line.split()
+ frame_idx = int(word_ls[1])
+ mi_rows = int(word_ls[3])
+ mi_cols = int(word_ls[5])
+ mv_ls = []
+ for i in range(mi_rows * mi_cols):
+ line = fp.readline()
+ word_ls = line.split()
+ row = int(word_ls[0]) * 8.
+ col = int(word_ls[1]) * 8.
+ mv_row = int(word_ls[2]) / 8.
+ mv_col = int(word_ls[3]) / 8.
+ mv_ls.append([col, row, mv_col, mv_row])
+ mv_ls = np.array(mv_ls)
+ img = yuv_to_rgb(read_frame(fp))
+ ref = None
+ line = fp.readline()
+ word_ls = line.split()
+ if int(word_ls[1]):
+ ref = yuv_to_rgb(read_frame(fp))
+ return frame_idx, mv_ls, img, ref
+
+
+def read_dpl_stats_file(filename, frame_num=0):
+ fp = open(filename)
+ line = fp.readline()
+ width = 0
+ height = 0
+ data_ls = []
+ while (line):
+ if line[0] == '=':
+ data_ls.append(read_frame_dpl_stats(fp))
+ line = fp.readline()
+ if frame_num > 0 and len(data_ls) == frame_num:
+ break
+ return data_ls
+
+
+if __name__ == '__main__':
+ filename = sys.argv[1]
+ data_ls = read_dpl_stats_file(filename, frame_num=2)
+ bs = 8
+ for frame_idx, mv_ls, img, ref in data_ls:
+ fig, axes = plt.subplots(1, 2)
+
+ axes[0].imshow(img)
+ draw_mv_ls(axes[0], mv_ls)
+ draw_pred_block_ls(axes[0], mv_ls, bs, mode=0)
+ #axes[0].grid(color='k', linestyle='-')
+ axes[0].set_ylim(img.shape[0], 0)
+ axes[0].set_xlim(0, img.shape[1])
+
+ if ref is not None:
+ axes[1].imshow(ref)
+ draw_mv_ls(axes[1], mv_ls, mode=1)
+ draw_pred_block_ls(axes[1], mv_ls, bs, mode=1)
+ #axes[1].grid(color='k', linestyle='-')
+ axes[1].set_ylim(ref.shape[0], 0)
+ axes[1].set_xlim(0, ref.shape[1])
+
+ plt.show()
+ print frame_idx, len(mv_ls)
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -6098,15 +6098,24 @@
printf("\n");
}
-static void dump_tpl_stats(const VP9_COMP *cpi, int tpl_group_frames) {
+static void dump_frame_buf(const YV12_BUFFER_CONFIG *frame_buf) {
+ dump_buf(frame_buf->y_buffer, frame_buf->y_stride, 0, 0, frame_buf->y_height,
+ frame_buf->y_width);
+ dump_buf(frame_buf->u_buffer, frame_buf->uv_stride, 0, 0,
+ frame_buf->uv_height, frame_buf->uv_width);
+ dump_buf(frame_buf->v_buffer, frame_buf->uv_stride, 0, 0,
+ frame_buf->uv_height, frame_buf->uv_width);
+}
+
+static void dump_tpl_stats(const VP9_COMP *cpi, int tpl_group_frames,
+ const GF_PICTURE *gf_picture) {
int frame_idx;
const VP9_COMMON *cm = &cpi->common;
- const ThreadData *td = &cpi->td;
- const MACROBLOCK *x = &td->mb;
- const MACROBLOCKD *xd = &x->e_mbd;
- for (frame_idx = 0; frame_idx < tpl_group_frames; ++frame_idx) {
+ for (frame_idx = 1; frame_idx < tpl_group_frames; ++frame_idx) {
const TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx];
+ int idx = 0;
int mi_row, mi_col;
+ int rf_idx;
printf("=\n");
printf("frame_idx %d mi_rows %d mi_cols %d\n", frame_idx, cm->mi_rows,
cm->mi_cols);
@@ -6114,16 +6123,19 @@
for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) {
const TplDepStats *tpl_ptr =
&tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col];
- int_mv mv = tpl_ptr->mv_arr[0];
+ int_mv mv = tpl_ptr->mv_arr[idx];
printf("%d %d %d %d\n", mi_row, mi_col, mv.as_mv.row, mv.as_mv.col);
}
}
- dump_buf(xd->cur_buf->y_buffer, xd->cur_buf->y_stride, 0, 0,
- xd->cur_buf->y_height, xd->cur_buf->y_width);
- dump_buf(xd->cur_buf->u_buffer, xd->cur_buf->uv_stride, 0, 0,
- xd->cur_buf->uv_height, xd->cur_buf->uv_width);
- dump_buf(xd->cur_buf->v_buffer, xd->cur_buf->uv_stride, 0, 0,
- xd->cur_buf->uv_height, xd->cur_buf->uv_width);
+
+ dump_frame_buf(gf_picture[frame_idx].frame);
+
+ rf_idx = gf_picture[frame_idx].ref_frame[idx];
+ printf("has_ref %d\n", rf_idx != -1);
+ if (rf_idx != -1) {
+ YV12_BUFFER_CONFIG *ref_frame_buf = gf_picture[rf_idx].frame;
+ dump_frame_buf(ref_frame_buf);
+ }
}
}
#endif // DUMP_TPL_STATS
@@ -6145,7 +6157,7 @@
}
#if CONFIG_NON_GREEDY_MV
#if DUMP_TPL_STATS
- dump_tpl_stats(cpi, tpl_group_frames);
+ dump_tpl_stats(cpi, tpl_group_frames, gf_picture);
#endif // DUMP_TPL_STATS
#endif // CONFIG_NON_GREEDY_MV
}