用Python自动生成CSV文件
1.进入OpenCV的扩展模块中的face模块D:\opencv\opencv_contrib-3.1.0\modules\face\samples\etc2.利用Python脚本自动生成“训练数据集绝对路径”+“;”+“标签”#!/usr/bin/env pythonimport sysimport os.path# This is a tiny script to help you creat
1.进入OpenCV的扩展模块中的face模块
D:\opencv\opencv_contrib-3.1.0\modules\face\samples\etc
2.利用Python脚本自动生成“训练数据集绝对路径”+“;”+“标签”
#!/usr/bin/env python
import sys
import os.path
# This is a tiny script to help you creating a CSV file from a face
# database with a similar hierarchie:
#
# philipp@mango:~/facerec/data/at$ tree
# .
# |-- README
# |-- s1
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
# |-- s2
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
# ...
# |-- s40
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
#
if __name__ == "__main__":
if len(sys.argv) != 2:
print "usage: create_csv <base_path>"
sys.exit(1)
BASE_PATH=sys.argv[1]
SEPARATOR=";"
label = 0
for dirname, dirnames, filenames in os.walk(BASE_PATH):
for subdirname in dirnames:
subject_path = os.path.join(dirname, subdirname)
for filename in os.listdir(subject_path):
abs_path = "%s/%s" % (subject_path, filename)
print "%s%s%d" % (abs_path, SEPARATOR, label)
label = label + 1
3.用Anaconda安装Python
3.1进入官网下载对应操作系统的安装包,一直下一步傻瓜式安装。
https://www.anaconda.com/distribution/#download-section
4.使用用cmd进行运行
4.1建立一个py27虚拟环境
4.2使用 conda activate Python27 (激活虚拟环境)
使用命令:python create_csv.py “对应数据集文件目录的绝对路径”
python create_csv.py D:\pic\facerecog
5.将cmd窗口的输出流数据进行复制,新建一个.txt文件进行保存,就是我们的CSV文件;
D:\pic\facerecog\s1/1.pgm;0
D:\pic\facerecog\s1/10.pgm;0
D:\pic\facerecog\s1/2.pgm;0
D:\pic\facerecog\s1/3.pgm;0
D:\pic\facerecog\s1/4.pgm;0
D:\pic\facerecog\s1/5.pgm;0
D:\pic\facerecog\s1/6.pgm;0
D:\pic\facerecog\s1/7.pgm;0
D:\pic\facerecog\s1/8.pgm;0
D:\pic\facerecog\s1/9.pgm;0
D:\pic\facerecog\s10/1.pgm;1
…很多
红框内是打错的直接跳过
更多推荐
所有评论(0)