我试图学习一些有关计算机视觉的知识,这里的知识并不多,所以我提前道歉...
最终,我试图创建某种布尔值语句,用于从以RGB格式捕获的内容中提取颜色。 IE,(RGB,如果捕获到255,0,0或概率(?),则布尔值点/触发器将变为true)下面的代码将截屏我的桌面上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文件。最终,可以为一定范围的蓝色或一定范围的红色和白色创建布尔触发器吗???谢谢...
答案 0 :(得分:0)
非常简单,此博客文章对此进行了解释: 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()))