车道线数据集采集
做车道线识别需要采集数据集,写一个脚本记录一下
代码很简单,自己设置分辨率,保存路径,按下S拍摄
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 17 15:08:59 2019
@author: 123456
"""
print("正在初始化摄像头...")
import cv2
import os
#import datetime
cap = cv2.VideoCapture(1)
print("初始化成功!")
cap.set(3,1280) #设置分辨率
cap.set(4,720)
# name='play_phone'
# name='haqian'
# name='spleeing'
# name='zhengchang'
# name="zhedang"
name="1"
savedpath =r'./pictures/'+name
isExists = os.path.exists(savedpath)
if not isExists:
os.makedirs(savedpath)
print('path of %s is build' % (savedpath))
else:
print('path of %s already exist and rebuild' % (savedpath))
# =============================================================================
# print("按s键拍摄图片")
# =============================================================================
i=0
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, 1)
cv2.imshow('test',frame)
#now = datetime.datetime.now()
#now = now.strftime('%m-%d-%H-%M-%S')
savedname = '/'+ str(i) + '.png'
if cv2.waitKey(1) & 0xFF == ord('s'): #按s拍摄
i += 1
cv2.imwrite(savedpath + savedname, frame)
cv2.namedWindow("Image")
cv2.imshow("Image", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
cap.release()
cv2.destroyAllWindows()