计算机视觉 openCV2 pyautogui

computer vision openCV2 pyautogui

我正在尝试学习一些关于计算机视觉的知识,但这里没有很多智慧,所以我提前道歉......

最终,我试图创建某种关于从以 RGB 格式捕获的内容中提取颜色的布尔语句。 IE,(RGB,如果捕获到 255,0,0 或概率(?)布尔值 point/trigger 会变为真)下面的代码将截取我桌面上 pyautogui 发生的情况的屏幕截图,并打印出什么在循环执行时继续 print(frame)..

from imutils.video import VideoStream
from imutils.video import FPS
import numpy as np
import imutils
import time
import cv2
import pyautogui

fps = FPS().start()

while True:
    # grab the frame from the threaded video stream and resize it
    # to have a maximum width of 400 pixels
    frame = np.array(pyautogui.screenshot(region = (0,200, 800,400)))
    frame = cv2.cvtColor((frame), cv2.COLOR_RGB2BGR)
    frame = imutils.resize(frame, width=400)
    print(frame)


    # show the output frame
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break

    # update the FPS counter
    fps.update()

# stop the timer and display FPS information
fps.stop()
print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))

我可以在控制台中看到循环执行矩阵格式的数字数组。是否可以从此处提取 RGB 颜色代码,或者它只是对象的像素表示?或者对象的颜色和像素表示?

"Frame" window 是我在 imshow openCV2 中创建的,它几乎出现在通过 pyautogui 捕获的每个颜色屏幕截图中,我可以在矩阵的左下角看到它控制台输出的格式 蓝红白的 RGB 格式。

我在 Windows 10 笔记本电脑上使用 IDLE 3.6 进行此实验,并通过 windows CMD 执行 .py 文件。最终是否有可能为一系列蓝色或一系列红色和白色创建布尔触发器???谢谢...

很简单,这篇博文post解释了一切: https://www.pyimagesearch.com/2014/03/03/charizard-explains-describe-quantify-image-using-feature-vectors/

需要注意的一件事是颜色按 BGR 顺序而不是 RGB... 将此添加到循环中:

means = cv2.mean(frame)
means = means[:3]
print(means)

最终产品将按 BGR 顺序打印出哪些颜色:

from imutils.video import VideoStream
from imutils.video import FPS
import numpy as np
import imutils
import time
import cv2
import pyautogui

fps = FPS().start()

while True:
    # grab the frame from the threaded video stream and resize it
    # to have a maximum width of 400 pixels
    frame = np.array(pyautogui.screenshot(region = (0,200, 800,400)))
    frame = cv2.cvtColor((frame), cv2.COLOR_RGB2BGR)
    frame = imutils.resize(frame, width=400)

    #grab color in BGR order, blue value comes first, then the green, and finally the red
    means = cv2.mean(frame)
    #disregard 4th value
    means = means[:3]
    print(means)


    # show the output frame
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break

    # update the FPS counter
    fps.update()

# stop the timer and display FPS information
fps.stop()
print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))