def search_static_objects(): global search_ptz_p global search_ptz_t global ptz_set_count print(os.path.basename(__file__), utils.get_function_name()) while flag_pause is not True: #if count_birds_from_panoramic() > 0: #return [], None module_camera.set_ptz(search_ptz_p, search_ptz_t, default_ptz_z) # search_ptz_p, search_ptz_t, zoom ptz_set_count += 1 search_ptz_p += ptz_p_delta if search_ptz_p > ptz_p_max: search_ptz_t += ptz_t_delta search_ptz_p = ptz_p_min if search_ptz_t > ptz_t_max: break time_stamp = time.time() ret, img = module_camera.get_image(ptz_channel, flip=False) if ret: rois = module_panoramic.get_split_bbox(img, dst_rows_min=1000, dst_cols_min=1000) objs = module_panoramic.detect_objs_in_rois(img, rois) if show_flag == 'yes' or show_flag == 'true': module_result.show_image(win_name, img, objs) dx, dy = calc_objs_shift(objs, img, limit=0.8) if dx is not None and dy is not None: return objs, img search_ptz_p, search_ptz_t = ptz_p_min, ptz_t_min # reset ptz state to default print('ptz_set_count = %d' % ptz_set_count) ptz_set_count = 0 return [], None
def proc_panoramic_moving(name, param_delay): global static_images print(os.path.basename(__file__), utils.get_function_name()) for k in [1, 2]: while static_images_old[k] is None: print('waiting for static image ready') time.sleep(param_delay) while True: while flag_pause is True: time.sleep(param_delay) for k in [1, 2]: time_stamp = time.time() with lock: img_static = static_images[k].copy() img_static_old = static_images_old[k].copy() objs_static = static_objects[k].copy() ret, img = module_camera.get_image(k) if ret: objs_moving = detect_moving_objects( [img_static_old, img_static, img], time_stamp=time_stamp, channel=k) objs_moving_confirmed = confirm_moving_objects( img, objs_moving) objs_moving_confirmed = filter_moving_objects( img, objs_moving_confirmed) objs_final = merge_objects(objs_static, objs_moving, objs_moving_confirmed) objs_final = filter_moving_objects(img, objs_final) with lock: moving_images[k] = img.copy() moving_objects[k] = objs_moving_confirmed.copy() final_objects[k] = objs_final.copy() with module_result.lock: module_result.result['panoramic'] = objs_final.copy() if show_flag == 'yes' or show_flag == 'true': win_name = 'module_panoramic channel-%d' % k module_result.show_image(win_name, img, objs_final)
def proc_panoramic_static(name, param_delay): global static_images print(os.path.basename(__file__), utils.get_function_name()) while True: while flag_pause is True: time.sleep(param_delay) for channel in [1, 2]: ret, img = module_camera.get_image(channel) if ret: objs = detect_static_objects(img, channel) with lock: static_images_old[channel] = static_images[channel] static_images[channel] = img.copy() static_objects[channel] = objs.copy() #show the static result of panoramic with module_result.lock: module_result.result['panoramic'] = objs.copy if show_flag == 'yes' or show_flag == 'true': win_name = 'module_panoramic channel-%d' % channel module_result.show_image(win_name, img, objs) time.sleep(0.1)
list_delta_pan = [] list_delta_tilt = [] for zoom in range(1,129,1): print('-'*80) print('zoom =', zoom) ptz_p0 = 10 ptz_t0 = 8.5 ptz_dp = 0.5 ptz_dt = 0.5 module_camera.set_ptz(ptz_p0, ptz_t0, zoom) time.sleep(1) r0, p0, t0, z0 = module_camera.get_ptz() print('p0, t0, z0 =', p0, t0, z0) r0, img0 = module_camera.get_image(flip=False) module_camera.set_ptz(ptz_p0+ptz_dp, ptz_t0+ptz_dt, zoom) time.sleep(1) r1, p1, t1, z1 = module_camera.get_ptz() print('p1, t1, z1 =', p1, t1, z1) r1, img1 = module_camera.get_image(flip=False) try: shift_x, shift_y = calc_shift(img0, img1) except: print('calc shift failed!!!') shift_x, shift_y = 0, 0 print('shift x,y = ', shift_x, shift_y) list_zoom.append((z0+z1)/2)
def track_moving_birds(objs, img): if objs is None: return if len(objs) <= 0: return print(os.path.basename(__file__), utils.get_function_name()) ptz_ret, ptz_p, ptz_t, ptz_z = module_camera.get_ptz() err_p, err_t = calc_rotate_angle(objs, img, ptz_p, ptz_t, ptz_z) ptz_p = ptz_p + err_p ptz_t = ptz_t + err_t module_camera.set_ptz(ptz_p, ptz_t, default_ptz_z, block=True, err_p_max=1.0, err_t_max=1.0) err_p = [0, 0] err_t = [0, 0] time_stamp = [time.time()] * 2 no_obj_count = 0 while flag_pause is not True and ptz_ret == 0: ret, img = module_camera.get_image(ptz_channel, flip=False) if ret: rows = img.shape[0] cols = img.shape[1] rois = module_panoramic.get_split_bbox(img, dst_rows_min=rows, dst_cols_min=cols) objs = module_panoramic.detect_objs_in_rois(img, rois) if len(objs) == 0: no_obj_count += 1 if no_obj_count > 5: print('no object detect, tracking over.') return else: no_obj_count = 0 err_p[1] = err_p[0] err_t[1] = err_t[0] err_p[0], err_t[0] = calc_rotate_angle(objs, img, ptz_p, ptz_t, ptz_z) time_stamp[1] = time_stamp[0] time_stamp[0] = time.time() time_span = time_stamp[0] - time_stamp[1] if time_span > 1.0: time_span = 1.0 print('time_span: ', time_span) # ptz_p = ptz_p + time_span*(pid_i*err_p[0] + pid_p*(err_p[0]-err_p[1])) # ptz_t = ptz_t + time_span*(pid_i*err_t[0] + pid_p*(err_t[0]-err_t[1])) # module_camera.set_ptz(ptz_p, ptz_t, default_ptz_z, block=False) ptz_p = ptz_p + err_p[0] ptz_t = ptz_t + err_t[0] module_camera.set_ptz(ptz_p, ptz_t, default_ptz_z, block=True, err_p_max=0.2, err_t_max=0.2) time.sleep(0.05) if show_flag == 'yes' or show_flag == 'true': module_result.show_image(win_name, img, objs) if flag_pause: print('module_ptz is paused.') return