我试图创建一个简单的程序来捕获屏幕截图(使用 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)
有人能告诉我哪里出错了吗?它每次都返回以下错误:
ValueError: Cannot feed value of shape (1, 608, 608, 4) for Tensor 'input:0', which has shape '(?, 608, 608, 3)'
请给出代码示例。提前致谢。