我正在尝试学习一些有关计算机视觉的知识,但这里没有太多智慧,所以我提前道歉......
最终,我尝试创建某种 bool 语句,从以 RGB 格式捕获的内容中提取颜色。 IE,(RGB,如果捕获了 255,0,0 或概率(?) bool 点/触发器将变为真)下面的代码将截取桌面上 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 颜色代码,或者它只是对象的像素表示?或者对象的颜色和像素表示?
“框架”窗口是我在 imshow
openCV2 中创建的窗口,它几乎出现在通过 pyautogui 捕获的每个彩色屏幕截图中,我可以在控制台输出的矩阵格式的左下角看到它蓝色、红色和白色的 RGB 格式。
我在 Windows 10 笔记本电脑上使用 IDLE 3.6 进行此实验,并通过 Windows CMD 执行 .py 文件。最终是否可以为一系列蓝色或一系列红色和白色创建 bool 触发器???谢谢...
最佳答案
非常简单,这篇博文解释了一切: 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()))
关于python - 计算机视觉 openCV2 pyautogui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53010782/