forked from tzutalin/dlib-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
envsetup
executable file
·127 lines (98 loc) · 3.54 KB
/
envsetup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python
import os
import sys
import argparse
import shutil
from subprocess import call
import zipfile
import subprocess
if sys.version_info >= (3,):
import urllib.request as urllib2
import urllib.parse as urlparse
else:
import urllib2
import urlparse
ROOT = os.path.dirname(os.path.abspath(__file__))
def unzipFile(filename):
zfile = zipfile.ZipFile(filename)
for name in zfile.namelist():
(dirname, filename) = os.path.split(name)
print "Decompressing " + filename + " on " + dirname
zfile.extract(name)
def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
# setup opencv
def download_file(url, desc=None):
u = urllib2.urlopen(url)
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
filename = os.path.basename(path)
if not filename:
filename = 'downloaded.file'
if desc:
filename = os.path.join(desc, filename)
with open(filename, 'wb') as f:
meta = u.info()
meta_func = meta.getheaders if hasattr(
meta, 'getheaders') else meta.get_all
meta_length = meta_func("Content-Length")
file_size = None
if meta_length:
file_size = int(meta_length[0])
print("Downloading: {0} Bytes: {1}".format(url, file_size))
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = "{0:16}".format(file_size_dl)
if file_size:
status += " [{0:6.2f}%]".format(
file_size_dl * 100 / file_size)
status += chr(13)
return filename
def downloadPrebuiltOpencv(prefix='.', out_prefix='.', version='3.1.0'):
OPENCV_PREBUILT_URL = 'http://netix.dl.sourceforge.net/project/opencvlibrary/opencv-android/{0}/OpenCV-{0}-android-sdk.zip'.format(
version)
OPENCV_ARCHIVE = 'OpenCV-{0}-android-sdk.zip'.format(version)
OPENCV_UNZIP_DIR = 'OpenCV-android-sdk'
OPENCV_OUT_PATH = 'opencv'
OPENCV_UNZIP_DIR = os.path.join(prefix, OPENCV_UNZIP_DIR)
OPENCV_OUT_PATH = os.path.join(out_prefix, OPENCV_OUT_PATH)
OPENCV_UNZIP_SDK_DIR = os.path.join(OPENCV_UNZIP_DIR, 'sdk', 'native')
if not os.path.isdir(OPENCV_UNZIP_DIR):
currDir = os.getcwd()
os.chdir(prefix)
if not os.path.exists(OPENCV_ARCHIVE):
download_file(OPENCV_PREBUILT_URL)
unzipFile(OPENCV_ARCHIVE)
os.chdir(currDir)
if not os.path.exists(OPENCV_OUT_PATH):
os.makedirs(OPENCV_OUT_PATH)
# Remove it if it exist
shutil.rmtree(OPENCV_OUT_PATH)
copytree(OPENCV_UNZIP_SDK_DIR, OPENCV_OUT_PATH)
def sync_submodules():
print '---------------- Start syncing submodules ----------------'
# Fetch submodules
global ROOT
os.chdir(ROOT)
call(['git', 'submodule', 'update', '--init', '--recursive'])
print 'download prebuilt opencv for android'
prebuilt_path = os.path.join(ROOT, 'third_party')
prebuilt_opencv_out = prebuilt_path
downloadPrebuiltOpencv(
prefix=prebuilt_path, out_prefix=prebuilt_opencv_out)
print '---------------- End syncing submodules ----------------'
def main(argv):
sync_submodules()
if __name__ == '__main__':
main(sys.argv[1:])