# import the necessary packages from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 import numpy as np # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() camera.resolution = (640, 480) camera.framerate = 32 rawCapture = PiRGBArray(camera, size=(640, 480)) camera.awb_mode='fluorescent' camera.exposure_mode='fixedfps' # allow the camera to warmup time.sleep(0.1) # capture frames from the camera for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): # grab the raw NumPy array representing the image, then initialize the timestamp # and occupied/unoccupied text image = frame.array # Convert BGR to HSV hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # define range of blue color in HSV ## lower_blue = np.array([110,50,50]) ## upper_blue = np.array([130,255,255]) # define range of blue color in HSV lower_blue = np.array([80,50,60]) upper_blue = np.array([255,255,255]) # Threshold the HSV image to get only blue colors mask = cv2.inRange(hsv, lower_blue, upper_blue) # Bitwise-AND mask and original image res = cv2.bitwise_and(image,image, mask= mask) #Croping the mask image around a ROI crop_mask=mask[50:600, 50:600] #close the image tho clean the mask kernel=np.ones((3,3), np.uint8) close_crop_mask=cv2.morphologyEx(crop_mask, cv2.MORPH_CLOSE, kernel) cv2.imshow('frame',image) cv2.imshow('mask',mask) cv2.imshow('close_crop_mask',close_crop_mask) cv2.imshow('res',res) k = cv2.waitKey(5) & 0xFF # clear the stream in preparation for the next frame rawCapture.truncate(0) if k == 2: break