首页 > 解决方案 > 使用 Logitech Brio 网络摄像头和 python 中的“pygame”以 4k 分辨率拍照的问题

问题描述

我在 python 中使用“pygame”(下面的代码)使用 Logitech Brio 网络摄像头拍摄 4k 分辨率的图像。

# take picture using pygame
import time
import cv2 
import pygame
import pygame.camera
from pygame.locals import *

start_time = time.time()

pygame.init()
pygame.camera.init()

cam = pygame.camera.Camera(0,(4096, 2160))
cam.start()
image = cam.get_image()
path = 'C:/Users/aatefi2/Downloads/robot_images/'
imageName = str(time.strftime("%Y_%m_%d_%H_%M_%S")) + '.jpg'
pygame.image.save(image, str(path) + imageName)

elapsed_time = time.time() - start_time
print (elapsed_time)

cam.stop()

但是,运行代码后,我收到此错误:

runfile('C:/Users/aatefi2/Downloads/robotic arm/kortex-master/kortex-master/api_python/examples/Webcam_take_picture.py', wdir='C:/Users/aatefi2/Downloads/robotic arm/kortex-master/kortex-master/api_python/examples')
Traceback (most recent call last):

  File "<ipython-input-16-0e9a77e64eb6>", line 1, in <module>
    runfile('C:/Users/aatefi2/Downloads/robotic arm/kortex-master/kortex-master/api_python/examples/Webcam_take_picture.py', wdir='C:/Users/aatefi2/Downloads/robotic arm/kortex-master/kortex-master/api_python/examples')

  File "C:\Users\aatefi2\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\aatefi2\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/aatefi2/Downloads/robotic arm/kortex-master/kortex-master/api_python/examples/Webcam_take_picture.py", line 51, in <module>
    cam = pygame.camera.Camera(0,(4096, 2160))

  File "C:\Users\aatefi2\AppData\Local\Continuum\anaconda3\lib\site-packages\pygame\_camera_vidcapture.py", line 60, in __init__
    self.dev.setresolution(width, height)

Error: Cannot set capture resolution.

我该如何解决这个问题?

我提前感谢任何帮助。

谢谢,

阿巴斯

标签: pythonpygamewebcambrio

解决方案


推荐阅读