Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lvl_refs = [ref_img]
- lvl_frames = [frame_img]
- lvl_refs.append(cv2.pyrDown(cv2.blur(lvl_refs[0], ksize=(3, 3))))
- lvl_frames.append(cv2.pyrDown(cv2.blur(lvl_frames[0], ksize=(3, 3))))
- lvl_refs.append(cv2.pyrDown(cv2.blur(lvl_refs[1], ksize=(3, 3))))
- lvl_frames.append(cv2.pyrDown(cv2.blur(lvl_frames[1], ksize=(3, 3))))
- d_min = math.inf
- d_min_i = d_min_j = -1
- p_tmp = round(p/4.0)
- center_x = math.floor(previous_match_x/4.0)
- center_y = math.floor(previous_match_y/4.0)
- for i in range(center_y - p_tmp, center_y + p_tmp + 1):
- for j in range(center_x - p_tmp, center_x + p_tmp + 1):
- I_ = lvl_frames[2].shape[0]
- J_ = lvl_frames[2].shape[1]
- M_ = lvl_refs[2].shape[0]
- N_ = lvl_refs[2].shape[1]
- if i < 0 or j < 0 or i >= I_ - M_ or j >= J_ - N_:
- continue
- d = distance(lvl_refs[2], lvl_frames[2], lvl_refs[2].shape[0], lvl_refs[2].shape[1], i, j)
- if d < d_min:
- d_min = d
- d_min_i = i
- d_min_j = j
- y1 = d_min_i
- x1 = d_min_j
- d_min = math.inf
- p_tmp = 1
- center_x = math.floor(previous_match_x/2.0 + 2*x1)
- center_y = math.floor(previous_match_y/2.0 + 2*y1)
- for i in range(center_y - p_tmp, center_y + p_tmp + 1):
- for j in range(center_x - p_tmp, center_x + p_tmp + 1):
- I_ = lvl_frames[1].shape[0]
- J_ = lvl_frames[1].shape[1]
- M_ = lvl_refs[1].shape[0]
- N_ = lvl_refs[1].shape[1]
- if i < 0 or j < 0 or i >= I_ - M_ or j >= J_ - N_:
- continue
- d = distance(lvl_refs[1], lvl_frames[1], lvl_refs[1].shape[0], lvl_refs[1].shape[1], i, j)
- if d < d_min:
- d_min = d
- d_min_i = i
- d_min_j = j
- y2 = d_min_i
- x2 = d_min_j
- d_min = math.inf
- p_tmp = 1
- center_x = math.floor(previous_match_x + 2 * x2)
- center_y = math.floor(previous_match_y + 2 * y2)
- for i in range(center_y - p_tmp, center_y + p_tmp + 1):
- for j in range(center_x - p_tmp, center_x + p_tmp + 1):
- I_ = lvl_frames[0].shape[0]
- J_ = lvl_frames[0].shape[1]
- M_ = lvl_refs[0].shape[0]
- N_ = lvl_refs[0].shape[1]
- if i < 0 or j < 0 or i >= I_ - M_ or j >= J_ - N_:
- continue
- d = distance(lvl_refs[0], lvl_frames[0], lvl_refs[0].shape[0], lvl_refs[0].shape[1], i, j)
- if d < d_min:
- d_min = d
- d_min_i = i
- d_min_j = j
- previous_match_y = d_min_i
- previous_match_x = d_min_j
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement