有没有一种方法可以用OpenCV拍照,而不用相机



我正在使用OpenCV从相机捕获图像。我使用的相机可以拍摄4k的静态图像,但可以拍摄1080p的视频。有没有一种方法可以在不使用videoCapture((的情况下在OpenCV中拍照?

def takephoto(camNumber):
#This creates two variables, the first one 'date' that records the exact date and time when   the photo was taken and the second one 'imagePath' that records where the image should be stored to
date = datetime.now().strftime("%Y_%m_%d-%I-%M-%S_%p")
imagePath = r'path'
#creates a variable called camera and makes it record what the webcam is displaying
camera = cv2.VideoCapture(camNumber)
#Creates a new variable called image and tells it to record what camera has stored in it at that moment
return_value, image = camera.read()
del(camera)

image = NULL
print("Photo Done")
return image, date
我不这么认为。除了opencv,您还可以使用pygame库捕获图像。

https://www.geeksforgeeks.org/how-to-capture-a-image-from-webcam-in-python/

import pygame
import pygame.camera

# initializing  the camera
pygame.camera.init()

# make the list of all available cameras
camlist = pygame.camera.list_cameras()

# if camera is detected or not
if camlist:

# initializing the cam variable with default camera
cam = pygame.camera.Camera(camlist[0], (640, 480))

# opening the camera
cam.start()

# capturing the single image
image = cam.get_image()

# saving the image
pygame.image.save(image, "filename.jpg")

最新更新