Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- def test(cap):
- if not cap.isOpened():
- exit(1)
- while(True):
- ret, frame = cap.read()
- if not ret:
- break
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- cv2.imshow('frame', gray)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- cap.release()
- cv2.destroyAllWindows()
- class StaticImageSource(object):
- def __init__(self, image=None):
- self.image = image
- def isOpened(self):
- return self.image is not None
- def read(self, image=None):
- if self.image is None:
- return False, None
- if not image:
- return True, self.image.copy()
- np.copyto(image, self.image)
- return True, image
- def release(self):
- self.image = None
- #cap = cv2.VideoCapture(0)
- cap = StaticImageSource(cv2.imread('chocolate.png'))
- test(cap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement