无法让darkflow处理RealIM中的屏幕截图

2024-05-15 23:35:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图创建一个简单的程序来捕捉屏幕截图(使用mss)并获取tensorflow来预测/检测图像中的元素,但它不起作用。以下是部分代码:

import cv2
import mss
import numpy as np
from PIL import Image

#Import TFNet
from darkflow.net.build import TFNet
import matplotlib.pyplot as plt

#Specify the dictonary.
options = {
    'model':'cfg/yolo.cfg',
    'load':'bin/yolov2.weights',
    'threshold': 0.3
}
tfnet = TFNet(options)

#Creates an endless loop for high-speed image acquisition...
while (True):
    with mss.mss() as sct:

    #Get raw pixels from the screen
    sct_img = sct.grab(sct.monitors[1])

    #Convert image to a numpy array
    img = np.array(sct_img)
    result = tfnet.return_predict(img)

    print(result)

有人能告诉我哪里出错了吗?它每次都返回以下错误:

^{pr2}$

请给出代码示例。提前谢谢。在


Tags: the代码fromimageimportnumpyimgas
1条回答
网友
1楼 · 发布于 2024-05-15 23:35:32

您的输入数据的形状似乎与预期的不同:

 (1, 608, 608, 4) 

而不是

^{pr2}$

你好像在谈论图像。通常彩色图像编码在RGB中,因此有3个通道。您可能需要从数据中删除alpha/transparency通道

相关问题 更多 >