我正在尝试学习一些关于计算机视觉的知识,而且这里没有太多的智慧,所以我在…之前道歉。
最后,我试图创建一种布尔语句,从RGB格式中提取颜色。(RGB,如果捕获250,0,0或概率(?)下面的代码将对我的桌面上的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格式。
我在Windows10笔记本电脑上使用空闲3.6进行这个实验,并通过Windows执行.py文件。最终,是否有可能创建一个布尔触发器范围的蓝军或范围的红色和白色?谢谢..。



发布于 2018-10-30 13:18:14
非常简单,这篇博文解释了这一切: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()))https://stackoverflow.com/questions/53010782
复制相似问题