1 Star 0 Fork 1.7K

wanyuan/EasyPR

forked from liuruoze/EasyPR 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
configure.py 4.71 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
# --------------------------------------------------------------------
# EasyPR auto configure script
# --------------------------------------------------------------------
#
# This script configures OpenCV3.0 for Visual Studio
# on Windows.
#
# You are required to have Python3.* installed, and python.exe must
# be added to your PATH (C:\Python34 for example).
#
# You can use it by executing:
#
# C:\> cd path\to\EasyPR
# C:\> python configure.py
#
# Note: compatible with python3, haven't been tested on python2.
#
# --------------------------------------------------------------------
import os
import re
kProjectDir = "vcprojs"
kProjects = ["libeasypr.vcxproj", "demo.vcxproj"]
kProjectTemplates = ["libeasypr.vcxproj.template", "demo.vcxproj.template"]
kOpenCVConfig = "OpenCVConfig-version.cmake"
kConfig = {
"build": "",
"include": "",
"library": "",
"link": ["opencv_world300"],
"bit": "",
"vs": ""
}
kPatterns = {
"include": "(<AdditionalIncludeDirectories>)(.*?)(</AdditionalIncludeDirectories>)",
"library": "(<AdditionalLibraryDirectories>)(.*?)(</AdditionalLibraryDirectories>)",
"link": "(<AdditionalDependencies>)(.*?)(</AdditionalDependencies>)"
}
kReplacements = {
"include": r"\1%s;\2\3",
"library": r'\1%s\3',
"link": r'\1%s;\2\3'
}
def configure():
for i in range(2):
print(">> creating %s" % kProjects[i])
tpath = os.path.join(kProjectDir, kProjectTemplates[i])
fp = open(tpath, encoding="utf-8")
try:
# read from disk
original = fp.read()
nstring = ""
if 0 == i:
nstring = configure_libeasypr(original)
elif 1 == i:
nstring = configure_demo(original)
# write to disk
wpath = os.path.join(kProjectDir, kProjects[i])
writer = open(wpath, mode="wb")
try:
writer.write(nstring.encode())
finally:
writer.close()
finally:
fp.close()
print(">> all done! Open EasyPR.sln and have fun!")
def configure_libeasypr(buffer):
# additional include dir
pattern = re.compile(kPatterns["include"])
return pattern.sub(kReplacements["include"] %
(kConfig["include"][:2] + re.escape(kConfig["include"][2:])),
buffer)
def configure_demo(buffer):
# additional include dir
pattern = re.compile(kPatterns["include"])
nstring = pattern.sub(kReplacements["include"] %
(kConfig["include"][:2] + re.escape(kConfig["include"][2:])),
buffer)
# additional library dir
pattern = re.compile(kPatterns["library"])
nstring = pattern.sub(kReplacements["library"] %
(kConfig["library"][:2] + re.escape(kConfig["library"][2:])),
nstring)
# additional dependencies
#lib_string = ""
#for lib in kConfig["link"]:
# lib_string += (lib + "d.lib")
#pattern = re.compile(kPatterns["link"])
#return pattern.sub(kReplacements["link"] % lib_string, nstring)
return nstring
def check_opencv_version():
file = os.path.join(kConfig["build"], kOpenCVConfig)
print(">> Checking ", file)
fp = open(file)
major_version = 0
try:
fline = fp.readline()
match = re.search(r"OpenCV_VERSION (\d)\.(\d)\.(\d{,2})", fline)
if match is not None:
major_version = match.group(1)
finally:
fp.close()
return major_version
def cli():
while True:
root_ = input(r"Where is your opencv root path? (e.g, C:\path\to\opencv3): ")
if os.path.exists(root_):
kConfig["build"] = os.path.join(root_, "build")
kConfig["include"] = os.path.join(kConfig["build"], "include")
break
else:
print("Invalid path")
if check_opencv_version() != "3":
print("requires opencv 3")
exit()
while True:
xbit = input("Which library version you want to use? (x86 for 32bit, x64 for 64bit): ")
if xbit == "x86" or xbit == "x64":
kConfig["bit"] = xbit
break
else:
print("Please type x86 or x64")
while True:
vc = input("Which Visual Studio you are using? (vs2012 or vs2013): ")
if vc == "vs2012":
kConfig["vs"] = "vc11"
break
elif vc == "vs2013":
kConfig["vs"] = "vc12"
break
else:
print("Please type vs2012 or vs2013")
kConfig["library"] = os.path.normpath("%s/%s/%s/lib/" % (kConfig["build"], kConfig["bit"], kConfig["vs"]))
if __name__ == "__main__":
cli()
configure()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wanyuan/EasyPR.git
git@gitee.com:wanyuan/EasyPR.git
wanyuan
EasyPR
EasyPR
master

搜索帮助