OpenCV Python Error: Sizes of input arguments do not match

asked 2014-02-27 21:23:29 -0600

J4G gravatar image

updated 2014-02-28 00:33:47 -0600

berak gravatar image

I'm creating an application that uses OpenCV and other Python libraries to grab a region of someone's screen, and compare it to a template image. This code works perfectly until the "dst" line. At that point I recieve the error

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')

Normally I would think this error arose because of different image sizes. But they are the exact same. I confirmed this by printing their heights, widths, and depths. As you can see above, they are identical.

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)

Any ideas?

edit retag flag offensive close merge delete

Comments

On another, unrelated note, how can I subtract the two images?

J4G gravatar imageJ4G ( 2014-02-27 21:24:56 -0600 )edit