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

2024-04-29 05:23:25 发布

您现在位置: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