def localize_opencv(): raise Exception('dont do this no more') print('____ Localizing opencv ____') # Where to install tpl_cv2 = tpl_root + '/cv2' ensure_path(tpl_cv2) # Libraries opencv_lib = install_prefix+'/lib' if sys.platform == 'win32': # The opencv libraries are in bin not lib on windows. x.x opencv_lib = install_prefix+'/OpenCV/bin' # Move the MinGW libs too mingw_lib = 'C:/MinGW/bin' copy_all(mingw_lib, tpl_cv2, ['libgcc_s_dw2-1.dll', 'libstdc++-6.dll']) copy_all(opencv_lib, tpl_cv2, 'libopencv*') # Python bindings copy_all(pypackages, tpl_cv2, ['cv2.so','cv2.pyd','libcv2*']) with open(tpl_cv2+'/__init__.py', 'w') as cv2_init: cv2_init.write(textwrap.dedent(''' # autogenerated in build_tpl.py import os, sys from os.path import realpath, dirname tpl_cv2 = realpath(dirname(__file__)) sys.path.insert(0, tpl_cv2) os.environ['PATH'] = tpl_cv2 + os.pathsep + os.environ['PATH'] try: from cv2 import * except Exception as ex: print(repr(ex)) print(os.environ['PATH']) print(sys.path) raise '''))
def localize_opencv(): raise Exception('dont do this no more') print('____ Localizing opencv ____') # Where to install tpl_cv2 = tpl_root + '/cv2' ensure_path(tpl_cv2) # Libraries opencv_lib = install_prefix + '/lib' if sys.platform == 'win32': # The opencv libraries are in bin not lib on windows. x.x opencv_lib = install_prefix + '/OpenCV/bin' # Move the MinGW libs too mingw_lib = 'C:/MinGW/bin' copy_all(mingw_lib, tpl_cv2, ['libgcc_s_dw2-1.dll', 'libstdc++-6.dll']) copy_all(opencv_lib, tpl_cv2, 'libopencv*') # Python bindings copy_all(pypackages, tpl_cv2, ['cv2.so', 'cv2.pyd', 'libcv2*']) with open(tpl_cv2 + '/__init__.py', 'w') as cv2_init: cv2_init.write( textwrap.dedent(''' # autogenerated in build_tpl.py import os, sys from os.path import realpath, dirname tpl_cv2 = realpath(dirname(__file__)) sys.path.insert(0, tpl_cv2) os.environ['PATH'] = tpl_cv2 + os.pathsep + os.environ['PATH'] try: from cv2 import * except Exception as ex: print(repr(ex)) print(os.environ['PATH']) print(sys.path) raise '''))
def localize_hesaff(): print('____ Localizing hessaff ____') hesaff_build = __CODE__ + '/hesaff/build' hesaff_pybnd = __CODE__ + '/hesaff/python_bindings' check_path(hesaff_build) tpl_hesaff = tpl_root + '/hesaff' ensure_path(tpl_hesaff) copy_all(hesaff_build, tpl_hesaff, 'hesaff*') copy_all(hesaff_pybnd, tpl_hesaff, '*.py') os.system('chmod +x ' + tpl_hesaff + '/hesaff*')
def localize_flann(): print('____ Localizing flann ____') # Where to install # Where to install tpl_pyflann = tpl_root+'/pyflann' ensure_path(tpl_pyflann) if sys.platform == 'win32': # Libraries flann_lib = 'C:/Program Files (x86)/flann/lib' copy_all(flann_lib, tpl_pyflann, 'libflann*') # Better do the bin as well (like opencv) # yups flann_bin = 'C:/Program Files (x86)/flann/bin' copy_all(flann_bin, tpl_pyflann, '*.dll') # Python bindings pyflann_dir = pypackages+'/pyflann' copy_all(pyflann_dir, tpl_pyflann, '*.py') else: # Libraries flann_lib = install_prefix+'/lib' copy_all(flann_lib, tpl_pyflann, 'libflann*') # Python bindings pyflann_dir = install_prefix+'/share/flann/python/pyflann' copy_all(pyflann_dir, tpl_pyflann, '*.py')
def localize_flann(): print('____ Localizing flann ____') # Where to install # Where to install tpl_pyflann = tpl_root + '/pyflann' ensure_path(tpl_pyflann) if sys.platform == 'win32': # Libraries flann_lib = 'C:/Program Files (x86)/flann/lib' copy_all(flann_lib, tpl_pyflann, 'libflann*') # Better do the bin as well (like opencv) # yups flann_bin = 'C:/Program Files (x86)/flann/bin' copy_all(flann_bin, tpl_pyflann, '*.dll') # Python bindings pyflann_dir = pypackages + '/pyflann' copy_all(pyflann_dir, tpl_pyflann, '*.py') else: # Libraries flann_lib = install_prefix + '/lib' copy_all(flann_lib, tpl_pyflann, 'libflann*') # Python bindings pyflann_dir = install_prefix + '/share/flann/python/pyflann' copy_all(pyflann_dir, tpl_pyflann, '*.py')
def __build(pkg_name, branchname='hotspotter_branch', cmake_flags={}, noinstall=False, rm_build=False, nomake=False): ''' Generic build function for hotspotter third party libraries: All libraries should be hosted under github.com:Erotemic/<pkg_name> ''' from hs_setup.git_helpers import git_branch, git_version, git_fetch_url cmd_args = ['raise', 'print'] # ---- INIT ---- # init_str = '_____ Python is building: '+ pkg_name +' _____' print('\n\n'+'='*len(init_str)) print(init_str) code_src = __CODE__+'/'+pkg_name code_build = code_src+'/build' # ---- CHECK SOURCE ---- # print('\n --- Checking code source dir: '+code_src+'\n') if not check_path(code_src): if not check_path(__CODE__): raise Exception('We have problems') cd(__CODE__) __cmd('git clone [email protected]:Erotemic/'+pkg_name+'.git', *cmd_args) cd(code_src) # ---- CHECK GIT ---- # print('\n --- Checking git info') current_branch = git_branch() fetch_url = git_fetch_url() version = git_version() print(' * fetch_url='+str(fetch_url)) print(' * branch='+str(current_branch)) #print(' * version='+str(version)) if current_branch != branchname: __cmd('git checkout '+branchname, *cmd_args) # ---- CHECK BUILD ---- # if rm_build: print('\n --- Forcing rm build dir: ' + code_build + '\n') if check_path(code_build): __cmd('rm -rf '+code_build) print('\n --- Creating build dir: ' + code_build + '\n') ensure_path(code_build) cd(code_build) # ---- CMAKE ---- # print('\n --- Running cmake\n') if not 'CMAKE_INSTALL_PREFIX' in cmake_flags: _cm_install_prefix = install_prefix if sys.platform == 'win32': _cm_install_prefix += '/' + pkg_name cmake_flags['CMAKE_INSTALL_PREFIX'] = _cm_install_prefix _cmake_args = cmake_flags2str(cmake_flags).replace('\n',' ') __cmd(cmake_cmd + _cmake_args + ' ..', *cmd_args) # ---- MAKE ---- # print('\n --- Running make\n') __cmd(make_cmd, *cmd_args) # ---- INSTALL ---- # if noinstall: print('\n --- Not Installing\n') else: print('\n --- Installing to: '+cmake_flags['CMAKE_INSTALL_PREFIX']+'\n') __sudo_cmd('make install', *cmd_args) # ---- END ---- # cd(hotspotter_root) exit_msg = ' --- Finished building: '+pkg_name print('\n'+exit_msg) print('='*len(exit_msg)+'\n')
from hotspotter.HotSpotterAPI import HotSpotterAPI from hotspotter.helpers import ensure_path, assert_path, copy_all, copy, img_ext_set, copy_task from fnmatch import fnmatch from os import walk from os.path import join, relpath, splitext from PIL import Image input_dir = '/media/Store/data/work/zebra_with_mothers' output_dir = '/media/Store/data/work/HSDB_zebra_with_mothers' output_img_dir = '/media/Store/data/work/HSDB_zebra_with_mothers/images' convert_fmt = 'zebra_with_mothers' assert_path(input_dir) ensure_path(output_dir) ensure_path(output_img_dir) # Parses the zebra_with_mothers format # into a hotspotter image directory # which is logically named cp_list = [] name_list = [] for root, dirs, files in walk(input_dir): foal_name = relpath(root, input_dir) for fname in files: chip_id, ext = splitext(fname) if not ext.lower() in img_ext_set: continue if chip_id.find('mother') > -1: chip_id = chip_id.replace('mother ', 'mom-') mom_name = chip_id.replace('mom-','')
def __build(pkg_name, branchname='hotspotter_branch', cmake_flags={}, noinstall=False, rm_build=False, nomake=False): ''' Generic build function for hotspotter third party libraries: All libraries should be hosted under github.com:Erotemic/<pkg_name> ''' from hs_setup.git_helpers import git_branch, git_version, git_fetch_url cmd_args = ['raise', 'print'] # ---- INIT ---- # init_str = '_____ Python is building: ' + pkg_name + ' _____' print('\n\n' + '=' * len(init_str)) print(init_str) code_src = __CODE__ + '/' + pkg_name code_build = code_src + '/build' # ---- CHECK SOURCE ---- # print('\n --- Checking code source dir: ' + code_src + '\n') if not check_path(code_src): if not check_path(__CODE__): raise Exception('We have problems') cd(__CODE__) __cmd('git clone [email protected]:Erotemic/' + pkg_name + '.git', *cmd_args) cd(code_src) # ---- CHECK GIT ---- # print('\n --- Checking git info') current_branch = git_branch() fetch_url = git_fetch_url() version = git_version() print(' * fetch_url=' + str(fetch_url)) print(' * branch=' + str(current_branch)) #print(' * version='+str(version)) if current_branch != branchname: __cmd('git checkout ' + branchname, *cmd_args) # ---- CHECK BUILD ---- # if rm_build: print('\n --- Forcing rm build dir: ' + code_build + '\n') if check_path(code_build): __cmd('rm -rf ' + code_build) print('\n --- Creating build dir: ' + code_build + '\n') ensure_path(code_build) cd(code_build) # ---- CMAKE ---- # print('\n --- Running cmake\n') if not 'CMAKE_INSTALL_PREFIX' in cmake_flags: _cm_install_prefix = install_prefix if sys.platform == 'win32': _cm_install_prefix += '/' + pkg_name cmake_flags['CMAKE_INSTALL_PREFIX'] = _cm_install_prefix _cmake_args = cmake_flags2str(cmake_flags).replace('\n', ' ') __cmd(cmake_cmd + _cmake_args + ' ..', *cmd_args) # ---- MAKE ---- # print('\n --- Running make\n') __cmd(make_cmd, *cmd_args) # ---- INSTALL ---- # if noinstall: print('\n --- Not Installing\n') else: print('\n --- Installing to: ' + cmake_flags['CMAKE_INSTALL_PREFIX'] + '\n') __sudo_cmd('make install', *cmd_args) # ---- END ---- # cd(hotspotter_root) exit_msg = ' --- Finished building: ' + pkg_name print('\n' + exit_msg) print('=' * len(exit_msg) + '\n')
from hotspotter.HotSpotterAPI import HotSpotterAPI from hotspotter.helpers import ensure_path, assert_path, copy_all, copy, img_ext_set, copy_task from fnmatch import fnmatch from os import walk from os.path import join, relpath, splitext from PIL import Image input_dir = '/media/Store/data/work/zebra_with_mothers' output_dir = '/media/Store/data/work/HSDB_zebra_with_mothers' output_img_dir = '/media/Store/data/work/HSDB_zebra_with_mothers/images' convert_fmt = 'zebra_with_mothers' assert_path(input_dir) ensure_path(output_dir) ensure_path(output_img_dir) # Parses the zebra_with_mothers format # into a hotspotter image directory # which is logically named cp_list = [] name_list = [] for root, dirs, files in walk(input_dir): foal_name = relpath(root, input_dir) for fname in files: chip_id, ext = splitext(fname) if not ext.lower() in img_ext_set: continue if chip_id.find('mother') > -1: chip_id = chip_id.replace('mother ', 'mom-') mom_name = chip_id.replace('mom-', '')