LavaTime
LavaTime

Reputation: 75

Taking photos using python

I'm trying to take a photo using one of the two cameras (Surface book 2) First of all, I want to take a photo, Then try to mess with taking a photo using front AND back camera I cannot find how to take a picture... Tried using pygame.camera but getting an err

Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\pygame\_camera_vidcapture.py", line 31, in init
    import vidcap as vc
ModuleNotFoundError: No module named 'vidcap'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    pygame.camera.init()
  File "C:\Program Files\Python37\lib\site-packages\pygame\camera.py", line 69, in init
    _camera_vidcapture.init()
  File "C:\Program Files\Python37\lib\site-packages\pygame\_camera_vidcapture.py", line 33, in init
    from VideoCapture import vidcap as vc
ModuleNotFoundError: No module named 'VideoCapture'

Couldn't get how fix that, and if you know how to choose which camera will take the photo it will be amazing :)

(WINDOWS)

Upvotes: 1

Views: 660

Answers (2)

LavaTime
LavaTime

Reputation: 75

should have used the library python-cv2 worked after downloading the library and importing it

Upvotes: 1

Snek
Snek

Reputation: 59

What about trying OpenCV. Something like this?

I have not tested this but it should get you started on extracting a frame from the camera. Also bare in mind that the install is for the package opencv-python.

import cv2
import numpy as np

cap = cv2.VideoCapture(0) # I am using my internal laptop webcam

while(1):
    ret, frame = cap.read()

    # Show frame
    cv2.imshow('MyWindow', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

#Destroy the capture session
cap.release()
cv2.destroyAllWindows()

Upvotes: 2

Related Questions