【发布时间】:2014-02-28 14:13:09
【问题描述】:
我正在创建一个应用程序,它使用 OpenCV 和其他 Python 库来抓取某人屏幕的某个区域,并将其与模板图像进行比较。此代码在“dst”行之前完美运行。那时我收到错误
141 825 3 141 825 3 OpenCV 错误: 输入参数的大小不匹配 (操作既不是'array op 数组'(其中数组具有相同的 大小和相同数量的通道), 也不是“数组运算标量”,也不是“标量运算” 数组')
通常我会认为此错误是由于图像尺寸不同而引起的。但它们完全相同。我通过打印它们的高度、宽度和深度来确认这一点。正如您在上面看到的,它们是相同的。
import win32api, win32con, win32gui
import os
import sys
import time
import Image
import ImageGrab
import cv2
import numpy as np
player = cv2.imread('./images/bg_eagle_player.png')
#User Settings:
SaveDirectory=r'C:\Users\something\somethingeelse'
while (1):
img=ImageGrab.grab()
saveas=os.path.join(SaveDirectory,'test.png')
img.save(saveas)
img = cv2.imread('test.png')
player_border = img[436:577, 378:1203]
height, width, depth = player.shape
print height, width, depth
height, width, depth = player_border.shape
print height, width, depth
dst = cv2.addWeighted(player,0.7,img,0.3,0)
cv2.imshow('image',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
time.sleep(0.1)
有什么想法吗?
【问题讨论】: