Reputation: 89
how to capture web_cam
image using python(raw python)
without using
any library like cv2
or pygame.
it would be great if anybody know the trick how to capture image using only
raw python
. advance thank you so much.
I tried using the VideoCapture
extension, but that didn't work very well for me. But the problem is that it's a bit slow with resolutions 320x230
, and sometimes it returns None for no apparent reason.
Upvotes: 1
Views: 237
Reputation: 1064
you also need this:
pip install opencv-python
To Save image press space
Try This:
import cv2
cam = cv2.VideoCapture(0)
cv2.namedWindow("test")
img_counter = 0
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
# SPACE pressed
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
Upvotes: 1
Reputation: 1
by use Pygame 3.4
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"
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")
Upvotes: 0