python调用摄像头拍摄数据集
作者:天上飞下一毛雪 时间:2021-08-12 10:25:22
之前需要做一些目标检测的训练,需要自己采集一些数据集,写了一个小demo来实现图片的采集
使用方法:
指定name的名称,name为分类的标签
按n键拍摄图片
程序会在当前目录下生成一个pictures的文件夹,图片存放在其中
print("正在初始化摄像头...")
import cv2
import os
import datetime
cap = cv2.VideoCapture(0)
print("初始化成功!")
# name='play_phone'
# name='haqian'
# name='spleeing'
# name='zhengchang'
# name="zhedang"
name="waitou"
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("按N键拍摄图片")
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 = '/'+name+ '_' + str(i) + '_{0}' '.jpg'.format(now)
if cv2.waitKey(1) & 0xFF == ord('n'): #按N拍摄
i += 1
cv2.imwrite(savedpath + savedname, frame)
cv2.namedWindow("Image")
cv2.imshow("Image", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
cap.release()
cv2.destroyAllWindows()
来源:https://blog.csdn.net/qq_39622065/article/details/88594271
标签:python,拍摄,数据集
0
投稿
猜你喜欢
深入了解Golang中Slice切片的使用
2023-09-25 08:59:08
在ASP编程中nothing代表什么意思?
2011-04-15 10:47:00
在MySQL中使用XML数据—数据格式化
2009-12-29 10:26:00
Python hashlib常见摘要算法详解
2023-07-29 20:04:09
ADSI+ASP添加IP到IIS禁止访问列表中
2011-04-02 10:42:00
基于Python实现经典植物大战僵尸游戏
2021-01-28 11:17:20
Javascript: 为<input>设置readOnly属性问题,希望大家以后要小心
2009-07-23 20:24:00
python字符串排序方法
2023-11-16 10:44:18
分析运行中的 Python 进程详细解析
2021-09-19 14:47:30
python基于phantomjs实现导入图片
2023-07-18 23:39:42
Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用
2008-05-29 13:44:00
php查询whois信息的方法
2023-09-05 10:47:00
Python OpenCV实现视频分帧
2023-06-06 02:38:18
关于DOM元素定位属性的深入学习
2008-04-02 11:46:00
python进阶_浅谈面向对象进阶
2022-01-22 17:02:06
Python yield的使用详解
2021-07-17 22:23:29
Python的索引与切片原来该这样理解
2023-11-21 16:17:51
Python实现视频下载功能
2022-04-06 13:42:14
JavaScript实现带自动提示的文本框效果代码
2011-02-05 11:13:00
Python input函数使用实例解析
2022-01-05 21:00:34