Commit 94e6695b authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

sd7

parent a15dec7b
import numpy as np
import cv2
import sys
vidIn=None
ALPHA=0.3
THRESHOLD=0.1
def getCornersYX(f):
return np.array([[50,10],[50,1000],[50,1000],[1000,50]])
def imshow(frame, frameName="frame", delay=10):
cv2.imshow(frameName,cv2.resize(frame,dsize=(500,500)))
cv2.waitKey(delay)
if __name__ == '__main__':
print("python screen-detection-7-gmm.py screenVideo.mp4 0.5")
print("python args[0] args[1] [2]")
VIDEO_FILE=sys.argv[1]
THRESHOLD=float(sys.argv[2])
vidIn=cv2.VideoCapture(VIDEO_FILE)
ret,frame=vidIn.read()
frame=cv2.resize(frame,(400,600))
midX=int(frame.shape[1]/2)
midY=int(frame.shape[0]/2)
mean=np.zeros(shape=frame.shape,dtype=np.float)
var=np.zeros(shape=frame.shape,dtype=np.float)
meanVar=np.zeros(shape=(frame.shape[0],frame.shape[1]),dtype=np.float)
cornersYX=np.array([[midY,midX],[midY,midX],[midY,midX],[midY,midX]])
while vidIn.isOpened():
ret,frame=vidIn.read()
frame=cv2.resize(frame,(400,600))
if not ret:
print("End of video")
else:
var=var*(1-ALPHA)+np.square(frame-mean)*ALPHA
mean=mean*(1-ALPHA)+ frame*ALPHA
meanVar=np.mean(var,axis=2)*2.5
print("Var",meanVar[cornersYX[0,0],cornersYX[0,1]],meanVar[cornersYX[1,0],cornersYX[1,1]],meanVar[cornersYX[2,0],cornersYX[2,1]],meanVar[cornersYX[3,0],cornersYX[3,1]])
'''if cornersYX[0,0]>0:
if meanVar[cornersYX[0,0]-1,cornersYX[0,1]]>THRESHOLD:
cornersYX[0,0]-=1
else:
cornersYX[0,0]+=1#np.random.randint(-1,1)
if cornersYX[0,1]>0:
if meanVar[cornersYX[0,0],cornersYX[0,1]-1]>THRESHOLD:
cornersYX[0,1]-=1
else:
cornersYX[0,1]+=1#np.random.randint(-1,1)
if cornersYX[1,0]>0:
if meanVar[cornersYX[1,0]-1,cornersYX[1,1]]>THRESHOLD:
cornersYX[1,0]-=1
else:
cornersYX[1,0]+=1#np.random.randint(-1,1)
if cornersYX[1,1]<frame.shape[1]-1:
if meanVar[cornersYX[1,0],cornersYX[1,1]+1]>THRESHOLD:
cornersYX[1,1]+=1
else:
cornersYX[1,1]+=(-1)#np.random.randint(-1,1)
if cornersYX[2,0]<frame.shape[0]-1:
if meanVar[cornersYX[2,0]+1,cornersYX[2,1]]>THRESHOLD:
cornersYX[2,0]+=1
else:
cornersYX[2,0]+=(-1)#np.random.randint(-1,1)
if cornersYX[2,1]<frame.shape[1]-1:
if meanVar[cornersYX[2,0],cornersYX[2,1]+1]>THRESHOLD:
cornersYX[2,1]+=1
else:
cornersYX[2,1]+=(-1)#np.random.randint(-1,1)
if cornersYX[3,0]<frame.shape[0]-1:
if meanVar[cornersYX[3,0]+1,cornersYX[3,1]]>THRESHOLD:
cornersYX[3,0]+=1
else:
cornersYX[3,0]+=(-1)#np.random.randint(-1,1)
if cornersYX[3,1]>0:
if meanVar[cornersYX[3,0],cornersYX[3,1]-1]>THRESHOLD:
cornersYX[3,1]-=1
else:
cornersYX[3,1]+=1#np.random.randint(-1,1)'''
# temp=meanVar.flatten()
# temp= (temp-np.mean(temp))/np.std(temp) * 255.0*1.5
# meanVar=np.reshape(temp,newshape=(frame.shape[0],frame.shape[1]))
meanVar=np.minimum(meanVar,np.full((frame.shape[0],frame.shape[1]),255))
meanVar=meanVar.astype(np.uint8)
meanVar=cv2.cvtColor(meanVar,cv2.COLOR_GRAY2RGB)
print(meanVar.shape)
for i in range(4):
cv2.circle(meanVar,(cornersYX[i,1],cornersYX[i,0]),5,[255,0,0],5)
cv2.line(meanVar,(cornersYX[i,1],cornersYX[i,0]),(cornersYX[(i+1)%4,1],cornersYX[(i+1)%4,0]),[255,0,0],2)
imshow(meanVar)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment