【问题标题】:computer vision openCV2 pyautogui计算机视觉 openCV2 pyautogui
【发布时间】:2018-10-26 14:21:38
【问题描述】:

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

最终,我试图创建某种关于从以 RGB 格式捕获的内容中提取颜色的布尔语句。 IE,(RGB,如果 255,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 格式红白相间。

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

【问题讨论】:

    标签: python machine-learning computer-vision opencv3.0 pyautogui


    【解决方案1】:

    很简单,这篇博文就说明了一切: 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()))
    

    【讨论】:

      猜你喜欢
      • 2018-11-07
      • 2011-10-18
      • 2017-08-26
      • 1970-01-01
      • 2010-12-04
      • 2011-07-08
      • 2012-02-01
      • 2022-01-18
      • 2020-09-16
      相关资源
      最近更新 更多