您的位置:首页 > 编程语言 > Python开发

利用Python获取OpenCV中lib文件的文件名

2013-04-03 11:20 459 查看
以前做项目用到OpenCV的库时,习惯把OpenCV目录下lib文件夹中所有的lib文件都添加到工程的依赖库中,当时很傻很天真,一个一个把lib名字复制粘贴过去。现在,OpenCV的库越来越多,老这样做不仅麻烦,而且显得不专业,效率不高。去年年底接触Python之后,赶脚用起来非常方便,但一直还停留在书本上,没用在实际项目中,于是先弄两个小脚本提高下做项目的效率。

[b]1、提取Debug版本的OpenCV库文件。[/b]

import sys
import glob
import os
if len(sys.argv) < 3 :
print 'usage: filenmae.py dir suffix'
exit()
dir = sys.argv[1]
suffix = sys.argv[2]
f = glob.glob(dir + '\\*d.' + suffix)
fileout = open(dir + '\\' + 'debug_'+ suffix + '.txt','wt')
for file in f :
filename = os.path.basename(file)
fileout.write(filename)
fileout.write('\n')
fileout.close()


运行结果:



输出文本:debug_lib.txt



非常帅气!有木有~

[b]1、提取Release版本的OpenCV库文件。[/b]

对上面程序进行一下小的修改,即可实现提取release版本的OpenCV库文件。

import sys
import glob
import os
if len(sys.argv) < 3 :
print 'usage: filenmae.py dir suffix'
exit()
dir = sys.argv[1]
suffix = sys.argv[2]
f = glob.glob(dir + '\\*.' + suffix)
fileout = open(dir + '\\' + 'release_' + suffix + '.txt','wt')
for file in f :
#filename = dir + os.path.basename(file)
#print filename
filename = os.path.basename(file)
if filename.find('d.lib') != -1:
continue
else:
fileout.write(filename)
fileout.write('\n')
fileout.close()


运行结果:



输出结果:release_lib.txt



参考资料:

http://blog.csdn.net/fromhj/article/details/7925060

转载或分享时请注明出处~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: