Advertisement
dan-masek

Untitled

Dec 18th, 2019
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. def test(cap):
  5.     if not cap.isOpened():
  6.         exit(1)
  7.  
  8.     while(True):
  9.         ret, frame = cap.read()
  10.         if not ret:
  11.             break
  12.  
  13.         gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  14.         cv2.imshow('frame', gray)
  15.         if cv2.waitKey(1) & 0xFF == ord('q'):
  16.             break
  17.  
  18.     cap.release()
  19.     cv2.destroyAllWindows()
  20.    
  21. class StaticImageSource(object):
  22.     def __init__(self, image=None):
  23.         self.image = image
  24.        
  25.     def isOpened(self):
  26.         return self.image is not None
  27.    
  28.     def read(self, image=None):
  29.         if self.image is None:
  30.             return False, None
  31.         if not image:
  32.             return True, self.image.copy()
  33.         np.copyto(image, self.image)
  34.         return True, image
  35.    
  36.     def release(self):
  37.         self.image = None
  38.  
  39. #cap = cv2.VideoCapture(0)
  40. cap = StaticImageSource(cv2.imread('chocolate.png'))
  41. test(cap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement