Ask Your Question

J4G's profile - activity

2020-10-29 17:44:07 -0600 received badge  Notable Question (source)
2020-08-16 23:03:43 -0600 received badge  Popular Question (source)
2019-03-06 20:29:00 -0600 received badge  Popular Question (source)
2014-02-27 21:24:56 -0600 commented question OpenCV Python Error: Sizes of input arguments do not match

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

2014-02-27 21:23:29 -0600 asked a question OpenCV Python Error: Sizes of input arguments do not match

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?

2014-02-08 21:03:11 -0600 received badge  Editor (source)
2014-02-08 20:11:08 -0600 asked a question Sending webcam stream remotely for use in Python OpenCV

Hey, I'm trying to send a webcam stream to a remote computer for image processing. I would do the processing directly on the webcam computer, but it's ARM and pretty slow. Right now I have mjpg-streamer set up, which allows me to remotely access image files and a network stream. Originally I intended just to get a stream of individual images with an HTTP Request, but I'd like to use background subtraction which if I understand correctly requires a video stream.

Here's what I currently have, but it's pretty crude.

while(1):
    urllib.urlretrieve("http://192.168.2.20:8080/?action=snapshot", "test.jpg")

    im = Image.open('test.jpg')
    im.save('test.jpg')

    frame = cv2.imread('test.jpg')

    fgmask = fgbg.apply(frame)
    fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)

    cv2.imshow('frame',fgmask)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

I have to convert the image to another jpeg or else OpenCV thinks the jpeg data is corrupted.

I'm an OpenCV / Python novice, so any help would be appreciated!