如何解决如何捕获图像并将其保存到python中的特定文件夹中
我试图制作一个 python 代码,它是一个循环来创建一个新文件夹,并将从网络摄像头捕获的一系列图像保存到新文件夹中
我能够编写代码来捕获图像序列:
#imports openCV for usage
import cv2
import time
#creates an object called camera,of type openCV video capture,using the
# first camera in the list of cameras connected to the computer.
camera = cv2.VideoCapture(1)#0-front,1-rear
#loop the following indented code 5 times
for i in range(5):
# ret- boolean regarding whether or not there was a return at all
# image-each frame that is returned.
ret,image = camera.read()
cv2.imshow("image",image)
#use the openCV method imwrite (that writes an image to a disk) and write an
# image using the data in the temporary data variable
cv2.imwrite('image_'+str(i)+'.png',image)
time.sleep(3) #pause every 3 second
print("Image_" + str(i))
# deletes the camrea object,we no longer needs it.
del(camera)
print ("Picture taken. ")
import os #os-function to interact w/ operating system modules
inPath = 'C:\\Users\\person\\Desktop\\ Project\\python\\Image Saving Test'
os.chdir(inPath)# method in Python used to change the current working directory to specified path.
# It takes only a single argument as new directory path.
#<<<<<<<<<<<<<<<<<<<<<<<<<<***************>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#Create a new subfolder named 'set_#' for each sequence of image and put
#the subfolder in Image Saving Test folder
for i in range (1,4):
Newfolder='Set ' + str(i)
outPath = os.makedirs(Newfolder)# method used to create a directory recursively.
# That means while making leaf directory if any intermediate-Lv
# directory is missing,os.makedirs() method will create the
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。