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

2024-04-25 11:58:12 发布

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

我正在创建一个应用程序,它使用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)

有什么想法吗?


Tags: of图像importimgpng错误widtharray