python - Python OpenCV错误:输入参数的大小不匹配

标签 python opencv

我正在创建一个使用OpenCV和其他Python库来捕获某人屏幕区域并将其与模板图像进行比较的应用程序。该代码在“dst”行之前一直有效。那时我收到错误

141 825 3 141 825 3 OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array')



通常我会认为此错误是由于图像大小不同而引起的。但是它们是完全一样的。我通过打印它们的高度,宽度和深度来确认这一点。如您在上面看到的,它们是相同的。
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)

有任何想法吗?

最佳答案

您的imgplayer图像大小似乎不同。

关于python - Python OpenCV错误:输入参数的大小不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22097513/

相关文章:

python - 将一组 NumPy 数组传递给 C 函数以进行输入和输出

opencv - 如何将图像拉伸(stretch)/修改为给定模板?

opencv - 在距离计算中考虑相机拖影/运动模糊

python - 两个看似相同的 unicode 字符串在使用 repr() 时结果是不同的,但我该如何解决这个问题?

python - 覆盆子PI B +上的python 2.7 cvtColor错误215

android - 适用于Android的OpenCV示例

c++ - 从opencv矩阵框架将数据从矩阵转换为数组

python - 二分查找小错误Python 3.5

python - 如何将Python Scrapy扩展中的数据插入到MySql数据库表中?

python - Keras 中的 Segnet : total size of new array must be unchanged error