实时颜色检测及其功能[Python] [OpenCV]

问题描述 投票:0回答:1

我与OpenCV一起工作了一段时间,以在屏幕上弹出颜色。最后,我成功掩盖了不同窗口中的颜色,如下图所示:

https://prnt.sc/qo3cjy

想知道什么是使python检测颜色并使其运行我编写的functions()的最有效和可行的方法。例如,如果检测到绿色,请运行函数hellogreen(),当检测到绿色时将显示绿色。

如果需要以防万一,请提供源代码:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
    _, frame = cap.read()
    hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

      # Red color
    low_red = np.array([161, 155, 84])
    high_red = np.array([179, 255, 255])
    red_mask = cv2.inRange(hsv_frame, low_red, high_red)
    red = cv2.bitwise_and(frame, frame, mask=red_mask)

      # Blue color
    low_blue = np.array([94, 80, 2])
    high_blue = np.array([126, 255, 255])
    blue_mask = cv2.inRange(hsv_frame, low_blue, high_blue)
    blue = cv2.bitwise_and(frame, frame, mask=blue_mask)

    # Green color
    low_green = np.array([25, 52, 72])
    high_green = np.array([83, 255, 255])
    green_mask = cv2.inRange(hsv_frame, low_green, high_green)
    green = cv2.bitwise_and(frame, frame, mask=green_mask)

    # Every color except white
    low = np.array([0, 42, 0])
    high = np.array([179, 255, 255])
    mask = cv2.inRange(hsv_frame, low, high)
    result = cv2.bitwise_and(frame, frame, mask=mask)

    cv2.imshow("Frame", frame)
    cv2.imshow("Red", red)
    cv2.imshow("Blue", blue)
    cv2.imshow("Green", green)

    key = cv2.waitKey(1)
    if key == 27:
        break

我与OpenCV一起工作了一段时间,以在屏幕上弹出颜色。最后,我成功掩盖了不同窗口中的颜色,如下图所示:https://prnt.sc/qo3cjy想知道是什么...

python opencv colors real-time detection
1个回答
0
投票

将这些行放在代码的末尾(helloblue,hellogreen和hellored是假设的函数):

© www.soinside.com 2019 - 2024. All rights reserved.