def detect(Camera): while True: frame = Camera.get_roi() detect.color = colorpicker.color() yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
import cv2 import numpy as np import colorpicker import math import imutils cap = cv2.VideoCapture(1) colorobj1 = colorpicker.color() colorobj2 = colorpicker.color() while True: _, frame = cap.read() framecvt = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) obj1 = cv2.inRange(framecvt, colorobj1[0], colorobj1[1]) obj2 = cv2.inRange(framecvt, colorobj2[0], colorobj2[1]) cnts1 = cv2.findContours(obj1.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts1 = imutils.grab_contours(cnts1) cnts1 = sorted(cnts1, key=cv2.contourArea, reverse=True)[:10] cnts2 = cv2.findContours(obj2.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts2 = imutils.grab_contours(cnts2) cnts2 = sorted(cnts2, key=cv2.contourArea, reverse=True)[:10] mask1 = cv2.bitwise_and(frame, frame, mask=obj1) mask2 = cv2.bitwise_and(frame, frame, mask=obj2)
import cv2 import numpy as np import colorpicker import imutils import frameratechecker color = colorpicker.color() dt = 1 / frameratechecker.fps() cap = cv2.VideoCapture(1) cXprev = 0 cYprev = 0 epsilon = 20 flag = False centerX = 320 centerY = 290 veloballX = 0 veloballY = 0 cX = 0 cY = 0 while (True): _, frame = cap.read() framecvt = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) blue = cv2.inRange(framecvt, color[0], color[1]) cnts = cv2.findContours(blue.copy(), cv2.RETR_EXTERNAL,