Created
February 6, 2018 04:05
-
-
Save mrakitin/4ad9631a3446ac2809aafabe0d1c7918 to your computer and use it in GitHub Desktop.
Trigger laptop camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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