python pygame.camera.init() NO vidcapture

主宰稳场 提交于 2019-12-19 03:13:09

问题


I am trying to initialize the camera module in pygame and display video from a usb webcam. This is my code:

import pygame
import pygame.camera
from pygame.camera import *
from pygame.locals import *

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

cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
image = cam.get_image()

Yet i get this error:

Traceback (most recent call last):
  File "C:/Users/Freddie/Desktop/CAMERA/Test1.py", line 7, in <module>
    pygame.camera.init()
  File "C:\Python27\lib\site-packages\pygame\camera.py", line 67, in init
    _camera_vidcapture.init()
  File "C:\Python27\lib\site-packages\pygame\_camera_vidcapture.py", line 21, in init
    import vidcap as vc
ImportError: No module named vidcap

PLS HELP!!! Im on Windows


回答1:


I met the same problem. The error info of "ImportError: No module named vidcap" indicates that python interpreter didn't find the vidcap module on you machine.

so you'd better follow these steps.

  1. Download the vidcap from http://videocapture.sourceforge.net/

2.Then copy the corresponding version of dll (which named "vidcap.pyd" in VideoCapture-0.9-5\VideoCapture-0.9-5\Python27\DLLs) to "your python path"\DLLs\ .

3.restart you script.

Done!.




回答2:


The camera module can only be used on linux




回答3:


I met the same problem but I found out that its not included on windows ONLY LINUX




回答4:


Try this:

import pygame

import pygame.camera

import time, string


from VideoCapture import Device

from pygame.locals import *

pygame.camera.init()

cam = pygame.camera.Camera(0,(640,480),"RGB")

cam.start()

img = pygame.Surface((640,480))

cam.get_image(img)

pygame.image.save(img, "img2.jpg")

cam.stop()


来源:https://stackoverflow.com/questions/16266244/python-pygame-camera-init-no-vidcapture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!