I am using Pyton version 3.* and opencv 3.*. In the below code I want to subtract the whole background on the basis of a corner pixel in order to get the foreground objects
def background_subtract(img,l):
print("Extract the background pixel")
image = cv2.imread(img,cv2.IMREAD_ANYCOLOR)
r,g,b=image[0,0]
t,d,m= image.shape
for i in range(t):
for j in range(d):
r1,g1,b1=image[i,j]
if r1>=r:
r1=0
if g1>=g:
g1=0
if b1>=b:
b1=0
path='C:\\Users\\UST\\Desktop'
if not os.path.exists(path):
os.makedirs(path)
cv2.imwrite(os.path.join(path,'background_subtract%d.jpg' %l),image)
path =os.path.join(path,'%d.jpg' %l)
print(path)
return path
But, instead of obtaining the subtracted background image, I am getting my original image instead. Please help