Skip to content

Instantly share code, notes, and snippets.

@ola0x
Last active March 12, 2022 14:30
Show Gist options
  • Save ola0x/d04022c5cfec147b1bb448f6ca10e1de to your computer and use it in GitHub Desktop.
Save ola0x/d04022c5cfec147b1bb448f6ca10e1de to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
width_res = 1920
height_res = 1080
def readcam1():
cam1 = cv2.VideoCapture(0)
print("[INFO] stating camera 1")
cam1.set(3,width_res)
cam1.set(4,height_res)
if (cam1.isOpened() == None):
print("Failed to connect to the camera 1")
_,frame = cam1.read()
cam1.release()
if frame is None:
print("Camera1 ==> Failed to capture an image")
cv2.imwrite('image/c1.jpg', frame)
def readcam2():
cam2 = cv2.VideoCapture(2)
print("[INFO] stating camera 2")
cam2.set(3,width_res)
cam2.set(4,height_res)
if (cam2.isOpened() == None):
print("Failed to connect to camera 2")
_,frame2 = cam2.read()
cam2.release()
if frame2 is None:
print("Camera2 ==> Failed to capture an images")
cv2.imwrite('image/c2.jpg', frame2)
readcam1()
readcam2()
# if cam1.isOpened() & cam2.isOpened():
# _i,frame1 = cam1.read()
# _j,frame2 = cam2.read()
# cam1.release()
# cam2.release()#releasing camera immediately after capturing picture
# if frame1 is not None and frame2 is not None:
# cv2.imwrite('c1.jpg', frame1)
# cv2.imwrite('c2.jpg', frame2)
# cap = cv2.VideoCapture(0)
# ret, frame = cap.read()
#
# if cap.isOpened():
# cv2.imshow("img1", frame)
# if cv2.waitKey(1) & 0xFF == ord('y'):
# cv2.imwrite('/home/pi/c1.jpg', frame)
# cv2.destroyAllWindows()
#
#
# cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment