old_contents: # -*- coding: utf-8-*-
  import cv2
  from imutils.video.pivideostream import PiVideoStream
  import imutils
  import time
  import numpy as np
  
  class VideoCamera(object):
      def __init__(self, flip = False):
          self.vs = PiVideoStream().start()
          self.stop_status = False
          self.flip = flip
          #time.sleep(2.0)
  
      def __del__(self):
          if self.stop_status is False:
              self.stop()
  
      def stop(self):
          if self.stop_status is False:
              self.vs.stop()
              self.stop_status = True
  
      def flip_if_needed(self, frame):
          if self.flip:
              return np.flip(frame, 0)
          return frame
  
      def get_frame(self):
          frame = self.flip_if_needed(self.vs.read())
          ret, jpeg = cv2.imencode('.jpg', frame)
          return jpeg.tobytes()
  
      def get_object(self, classifier):
          found_objects = False
          frame = self.flip_if_needed(self.vs.read()).copy() 
          gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  
          #参数调整
          objects = classifier.detectMultiScale(
              gray,
              scaleFactor=1.1,
              minNeighbors=5,
              minSize=(30, 30),
              flags=cv2.CASCADE_SCALE_IMAGE
          )
  
          if len(objects) > 0:
              found_objects = True
  
          # Draw a rectangle around the objects
          for (x, y, w, h) in objects:
              cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
  
          ret, jpeg = cv2.imencode('.jpg', frame)
          return (jpeg.tobytes(), found_objects)
  
  
  
  
new_contents: # -*- coding: utf-8-*-
  import cv2
  from imutils.video.pivideostream import PiVideoStream
  import imutils
  import time
  import numpy as np
  
  class VideoCamera(object):
      def __init__(self, flip = False):
          self.vs = PiVideoStream().start()
          self.stop_status = False
          self.flip = flip
          #启动视频调制正常显示状态需要一些时间
          time.sleep(2.0)
  
      def __del__(self):
          if self.stop_status is False:
              self.stop()
  
      def stop(self):
          if self.stop_status is False:
              self.vs.stop()
              self.stop_status = True
  
      def flip_if_needed(self, frame):
          if self.flip:
              return np.flip(frame, 0)
          return frame
  
      def get_frame(self):
          frame = self.flip_if_needed(self.vs.read())
          ret, jpeg = cv2.imencode('.jpg', frame)
          return jpeg.tobytes()
  
      def get_object(self, classifier):
          found_objects = False
          frame = self.flip_if_needed(self.vs.read()).copy() 
          gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  
          #参数调整
          objects = classifier.detectMultiScale(
              gray,
              scaleFactor=1.1,
              minNeighbors=5,
              minSize=(30, 30),
              flags=cv2.CASCADE_SCALE_IMAGE
          )
  
          if len(objects) > 0:
              found_objects = True
  
          # Draw a rectangle around the objects
          for (x, y, w, h) in objects:
              cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
  
          ret, jpeg = cv2.imencode('.jpg', frame)
          return (jpeg.tobytes(), found_objects)
  
  
  
  
subject: add sm monitor word