简体   繁体   English

有没有办法用 OpenCV 拍照,不使用相机

[英]Is there a way to take a photo with OpenCV, not using a camera

I am using OpenCV to capture an image from a camera.我正在使用 OpenCV 从相机捕获图像。 The camera I'm using a camera that captures static images in 4k, but video in 1080p.我使用的相机可以拍摄 4k 的 static 图像,但可以拍摄 1080p 的视频。 Is there a way to take a photo in OpenCV without using videoCapture()?有没有办法在不使用 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

I do not think so.我不这么认为。 other than opencv, you can capture the image using pygame library.除了 opencv 之外,您可以使用 pygame 库捕获图像。

https://www.geeksforgeeks.org/how-to-capture-a-image-from-webcam-in-python/ 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM