6

I want to be able to take a photo from a webcam in python 3 and Windows. Are there any modules that support it? I have tried pygame, but it is only linux and python 2, and VideoCapture is only python 2.

wcb98
  • 172
  • 1
  • 1
  • 10

3 Answers3

7

I've been looking for the same thing and so far I have come up with a blank. This is what I have so far:

             2.7  3.2  3.3  3.4  LINUX  WIN32
-------------------------------------------------------
OpenCV       YES   -    -    -   YES    YES
PyGame       YES  YES  YES  YES  YES    YES
SimpleCV     YES   -    -    -   YES    YES
VideoCapture YES   -    -    -    -     YES

Resources

  • opencv.org/downloads.html
  • pygame.info/downloads/
  • simplecv.org/download
  • videocapture.sourceforge.net/
jfs
  • 399,953
  • 195
  • 994
  • 1,670
5

07/08/14

Pygame 3.4 Ver. is released

http://www.youtube.com/watch?v=SqmSpJfN7OE
http://www.lfd.uci.edu/~gohlke/pythonlibs/

You can download "pygame‑1.9.2a0.win32‑py3.4.exe"

take a photo from a webcam in python 3.4 (testing on window 7) code [1]

import pygame
import pygame.camera

pygame.camera.init()
cam = pygame.camera.Camera(0,(640,480))
cam.start()
img = cam.get_image()
pygame.image.save(img,"filename.jpg")




refer to [1] Capturing a single image from my webcam in Java or Python

Community
  • 1
  • 1
user3815048
  • 66
  • 1
  • 2
  • 2
    When I tried, I got an ImportError: cannot import name '_camera' –  May 20 '18 at 16:49
  • if "SystemError: ioctl(VIDIOC_S_FMT) failure: no supported formats ...." happens, try to include: cam.stop() after the last line. This should solve the problem when you are trying to take more than one photo. – Arthur Zennig Jul 22 '18 at 09:24
0
import cv2

# Open the device at the ID 0 
cap = cv2.VideoCapture(0)

 #Check whether user selected camera is opened successfully.

if not (cap.isOpened()):

    print("Could not open video device")

#To set the resolution 
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 640)

    cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 480)

while(True): 
# Capture frame-by-frame

    ret, frame = cap.read()

# Display the resulting frame

    cv2.imshow('preview',frame)

#Waits for a user input to quit the application

if cv2.waitKey(1) & 0xFF == ord('q'):
     #break

# When everything done, release the capture 
    cap.release()

    cv2.destroyAllWindows() 
  • Welcome to Stack Overflow. Code is a lot more helpful when it is accompanied by an explanation. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please [edit] your question and explain how it answers the specific question being asked. This is especially important when answering old questions (this one is 8 years old) with existing answers. See [answer]. – ChrisGPT was on strike Apr 20 '22 at 21:42