Вот мой текущий код:
Код: Выделить всё
# required libraries
import cv2
import numpy as np
# main function
def main():
# returns vid from camera -- cameras are indexed(0 is the front camera, 1 is rear)
cap = cv2.VideoCapture(0)
# cap is opened if pc is receiving cam data
if cap.isOpened():
ret, frame = cap.read()
else:
ret = False
while ret:
ret, frame = cap.read()
# setting color range
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# BLUE color range
blue_low = np.array([100, 50, 50])
blue_high = np.array([140, 255, 255])
# GREEN color range
green_low = np.array([40, 40, 40])
green_high = np.array(([80, 255, 255]))
# creating masks
blue_mask = cv2.inRange(hsv, blue_low, blue_high)
green_mask = cv2.inRange(hsv, green_low, green_high)
# combination of masks
blue_green_mask = cv2.bitwise_xor(blue_mask, green_mask)
blue_green_mask_colored = cv2.bitwise_and(blue_mask, green_mask, mask=blue_green_mask)
# create the masked version (shows the background black and the specified color the color coming through cam)
output = cv2.bitwise_and(frame, frame, mask=blue_green_mask)
# create/open windows
cv2.imshow("image mask", blue_green_mask)
cv2.imshow("orig webcam feed", frame)
cv2.imshow("color tracking", output)
# if q is pressed the project breaks
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# once broken the program will run remaining instructions (closing windows and stopping cam)
cv2.destroyAllWindows()
cap.release
if __name__ == "__main__":
main()
РЕДАКТИРОВАТЬ:
Для дальнейшего пояснения:
Я использую 2 черных маркера (один с синим колпачком и один с зеленая кепка).
Что касается следа, я имею в виду что-то похожее на это:..
уточнение следа
Этот парень хорошо справился с объяснением это, но я все еще был очень смущен, поэтому пришел за помощью к переполнению стека.
со следами; Я бы хотел, чтобы они были «полупрозрачными», а не сплошными, как на картинке выше. поэтому, если объект снова пересечет свой путь, этот участок пути станет немного темнее.
надеюсь, это помогло
Подробнее здесь: https://stackoverflow.com/questions/650 ... ing-humans