Skip to content

Instantly share code, notes, and snippets.

@mrakitin
Created February 6, 2018 04:05
Show Gist options
  • Save mrakitin/4ad9631a3446ac2809aafabe0d1c7918 to your computer and use it in GitHub Desktop.
Save mrakitin/4ad9631a3446ac2809aafabe0d1c7918 to your computer and use it in GitHub Desktop.
Trigger laptop camera
import cv2
import matplotlib.pyplot as plt
class LaptopCamera:
def __init__(self, cam_id=0):
self.cam_id = cam_id
# There must be some "lazy" way to initialize it
self.cap = cv2.VideoCapture(cam_id)
self.cap.release()
self.image = None
def stage(self):
...
def trigger(self):
self.cap.open(self.cam_id)
self.image = self.cap.read()[1]
self.cap.release()
def unstage(self):
...
def show(self):
plt.imshow(self.image)
plt.show()
if __name__ == '__main__':
lc = LaptopCamera()
lc.trigger()
lc.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment