import os import sys import cv2 from cv2 import calcOpticalFlowFarneback as sw_farneback_optical_flow import numpy as np from butterflow.motion import ocl_farneback_optical_flow, \ ocl_interpolate_flow, set_cache_path, time_steps_for_int_frames # importing settings will make temp directories if they don't exist from butterflow.settings import default as settings # but not the clb_dir, make it and set it for testing clb_dir = settings['clb_dir'] if not os.path.exists(clb_dir): os.makedirs(clb_dir) set_cache_path(clb_dir + os.sep) def mk_sample_image(dst_path, w, h, ch): # make a random 24-bit image w/ 8-bits per ch if os.path.exists(dst_path): return dat = np.random.rand(h, w, ch) * 255 # 0,1.0 scaled to 0,255.0 img = np.array(dat, dtype=np.uint8) # float64 to uint8 cv2.imwrite(dst_path, img) class OpticalFlowTestCase(unittest.TestCase): def setUp(self): img_1 = os.path.join(settings['tmp_dir'], '~test_optical_flow_test_case_1.jpg')
import unittest import os import sys import cv2 from cv2 import calcOpticalFlowFarneback as sw_farneback_optical_flow import numpy as np from butterflow.motion import ocl_farneback_optical_flow, \ ocl_interpolate_flow, set_cache_path, time_steps_for_int_frames from butterflow.settings import default as settings # will mk temp dirs # but not the clb_dir, make it and set it for testing clb_dir = settings['clbdir'] if not os.path.exists(clb_dir): os.makedirs(clb_dir) set_cache_path(clb_dir + os.sep) def mk_sample_image(dst, w, h, ch): # make a random 24-bit image w/ 8-bits per ch if os.path.exists(dst): return dat = np.random.rand(h, w, ch) * 255 # 0,1.0 scaled to 0,255.0 img = np.array(dat, dtype=np.uint8) # float64 to uint8 cv2.imwrite(dst, img) class OpticalFlowTestCase(unittest.TestCase): def setUp(self): img_1 = os.path.join(settings['tempdir'], '~test_optical_flow_test_case_1.jpg')
# define interpolation and flow functions default['flow_function'] = lambda x, y: \ motion.ocl_farneback_optical_flow( x, y, default['pyr_scale'], default['levels'], default['winsize'], default['iters'], default['poly_n'], default['poly_s'], default['fast_pyr'], 0) default['interpolate_function'] = motion.ocl_interpolate_flow # override default settings with development settings # ignore errors when `dev_settings.py` does not exist # ignore errors when `default` variable is not defined in the file try: from butterflow import dev_settings for k, v in dev_settings.default.items(): default[k] = v except ImportError: pass except AttributeError: pass # make temporary directories for x in [default['clb_dir'], default['tmp_dir']]: if not os.path.exists(x): os.makedirs(x) # set the location of the clb cache motion.set_cache_path(default['clb_dir'] + os.sep)
default["iters"], default["poly_n"], default["poly_s"], default["fast_pyr"], 0, ) default["interpolate_function"] = motion.ocl_interpolate_flow # override default settings with development settings # ignore errors when `dev_settings.py` does not exist # ignore errors when `default` variable is not defined in the file try: from butterflow import dev_settings for k, v in dev_settings.default.items(): default[k] = v except ImportError: pass except AttributeError: pass # make temporary directories for x in [default["clb_dir"], default["tmp_dir"]]: if not os.path.exists(x): os.makedirs(x) # set the location of the clb cache motion.set_cache_path(default["clb_dir"] + os.sep)