I'm trying to do background subtraction using OpenCV trying to subtract two images from each other. One of the images is the background image and is fed to the program statically while the second image is taken from the webcam connected to the Raspberry Pi (the same webcam is used to capture the background image and both images have the same resolution). However I get the error:
error: /build/opencv-VF5Hiu/opencv-2.4.9.1+dfsg/modules/core/src/arithm.cpp:1287: error: (-209) 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' in function arithm_op
my code is the following:
import cv2
Original2 = cv2.imread("Original.png")
Original2 = cv2.resize(Original2, (960, 720))
cap = cv2.VideoCapture(0)
cap.set(3, 960)
cap.set(4, 720)
ret,tespi=cap.read()
cap.release()
cv2.imwrite('tespi.png',tespi)
Edited2= cv2.imread('tespi.png')
diffadd = cv2.subtract(Edited2, Original2)
diffsub = cv2.subtract(Original2, Edited2)
I tried resizing both pictures before subtracting them, tried enforcing the desired resolution, almost tried anything I could think of which is not that so many things since I'm just starting to learn programming in python.
Can you please help me fix this issue ?