1

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.

2
  • Why you don't want to use libraries? Anyway, you can search inside pygame or cv2 libraries to study the raw code and build your custom functions. github.com/skvark/opencv-python github.com/pygame Commented May 4, 2020 at 8:26
  • you can't capture image using only raw python. You need external modules like cv2 or PyGame. I'm not sure but maybe ffmpeg can also read web_cam. And if you have problem with speed then you should first check if you have the same problem with other tools - maybe problem is camera, not Python. Commented May 4, 2020 at 8:36

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

okay alright! , can i open webcam silently?(without turning on light)
0

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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.