def mask(self, frame, lowHue, lowSat, lowVal, highHue, highSat, highVal): #this is the limit threshold the lowest from the average value and the highest from the average value try: kernelDilation = np.ones((3, 3), np.uint8) #kernel for dilation kernelErosion = np.ones((2, 2), np.uint8) #kernel for erosion #get mask for each chanel separately lower_blue = np.array([lowHue, lowSat - 255, lowVal - 255]) upper_blue = np.array([highHue, highSat + 255, highVal + 255]) mask1 = cv2.inRange(frame, lower_blue, upper_blue) mask1 = cv2.erode(mask1, kernelErosion, iterations=1) mask1 = cv2.dilate(mask1, kernelDilation, iterations=2) lower_blue = np.array([lowHue - 255, lowSat, lowVal - 255]) upper_blue = np.array([highHue + 255, highSat, highVal + 255]) mask2 = cv2.inRange(frame, lower_blue, upper_blue) lower_blue = np.array([lowHue - 255, lowSat - 255, lowVal - 25]) upper_blue = np.array([highHue + 255, highSat + 255, highVal + 25]) mask3 = cv2.inRange(frame, lower_blue, upper_blue) mask3 = cv2.dilate(mask3, kernelDilation, iterations=2) # get intersection of hue and value channels masks = cv2.bitwise_and(mask1, mask3) masks = cv2.erode(masks, kernelErosion, iterations=1) masks = cv2.dilate(masks, kernelDilation, iterations=2) from main import isShow interface = UI() if isShow[3]: interface.showWindow('hue', mask1) elif interface.isOpen('hue'): interface.closeWindow('hue') if isShow[4]: interface.showWindow('sat', mask2) elif interface.isOpen('sat'): interface.closeWindow('sat') if isShow[5]: interface.showWindow('val', mask3) elif interface.isOpen('val'): interface.closeWindow('val') except Exception as e: print(e) return frame return masks