Commit c30e6723 authored by Gihan Jayatilaka's avatar Gihan Jayatilaka

sd8

parent 32500dde
......@@ -51,6 +51,10 @@ def readFrame(vid):
def mainFunc():
H=299
W=299
global frame,vidIn,vidOut,clicksXY
inputFile=sys.argv[1]#"./video/real00.avi"
outputFile="./tempOut.mp4"#sys.argv[2]
......@@ -60,7 +64,7 @@ def mainFunc():
vidIn=cv2.VideoCapture(inputFile)
vidOut=cv2.VideoWriter(outputFile,cv2.VideoWriter_fourcc('M','J','P','G'),60,(299,299))
vidOut=cv2.VideoWriter(outputFile,cv2.VideoWriter_fourcc('M','J','P','G'),10,(H,W))
......@@ -100,9 +104,6 @@ def mainFunc():
cv2.line(frame,(clicksXY[i][0],clicksXY[i][1]),(clicksXY[(i+1)%len(clicksXY)][0],clicksXY[(i+1)%len(clicksXY)][1]),[255,255,255],thickness=1)
cv2.imshow("Original frame",frame)
cv2.waitKey(1)
cv2.destroyAllWindows()
vidIn.release()
vidOut.release()
......
......@@ -10,7 +10,7 @@ import sklearn
import numpy as np
FAST=False
clicksXY=[]
finishGettingInput=False
vidIn = None
......@@ -118,13 +118,15 @@ def mainFuncVideo():
if not ret:
break
destFrame = cv2.warpPerspective(frame, h, (299,299))
cv2.imshow("Oriented frame",destFrame)
if not FAST: cv2.imshow("Oriented frame",destFrame)
vidOut.write(destFrame)
for i in range(len(clicksXY)):
cv2.circle(frame,(clicksXY[i][0],clicksXY[i][1]),4,[255,255,255],thickness=1)
cv2.line(frame,(clicksXY[i][0],clicksXY[i][1]),(clicksXY[(i+1)%len(clicksXY)][0],clicksXY[(i+1)%len(clicksXY)][1]),[255,255,255],thickness=1)
cv2.imshow("Original frame",frame)
cv2.waitKey(1)
if not FAST:
for i in range(len(clicksXY)):
cv2.circle(frame,(clicksXY[i][0],clicksXY[i][1]),4,[255,255,255],thickness=1)
cv2.line(frame,(clicksXY[i][0],clicksXY[i][1]),(clicksXY[(i+1)%len(clicksXY)][0],clicksXY[(i+1)%len(clicksXY)][1]),[255,255,255],thickness=1)
cv2.imshow("Original frame",frame)
cv2.waitKey(1)
......@@ -163,37 +165,40 @@ def mainFuncNpz():
print("Source points shape = {}, dest = {}".format(sourcePoints.shape,destPoints.shape))
h=cv2.getPerspectiveTransform(sourcePoints,destPoints)
print("Perspective transform",h)
cv2.destroyWindow("frame")
while True:
if not matIdx < X.shape[0]:
break
XX[matIdx]= cv2.warpPerspective(X[matIdx], h, (299,299))
cv2.imshow("Oriented frame",XX[matIdx])
for i in range(len(clicksXY)):
cv2.circle(X[matIdx],(clicksXY[i][0],clicksXY[i][1]),4,[255,255,255],thickness=1)
cv2.line(X[matIdx],(clicksXY[i][0],clicksXY[i][1]),(clicksXY[(i+1)%len(clicksXY)][0],clicksXY[(i+1)%len(clicksXY)][1]),[255,255,255],thickness=1)
cv2.imshow("Original frame",X[matIdx])
cv2.waitKey(1)
if not FAST:
cv2.imshow("Oriented frame",XX[matIdx])
for i in range(len(clicksXY)):
cv2.circle(X[matIdx],(clicksXY[i][0],clicksXY[i][1]),4,[255,255,255],thickness=1)
cv2.line(X[matIdx],(clicksXY[i][0],clicksXY[i][1]),(clicksXY[(i+1)%len(clicksXY)][0],clicksXY[(i+1)%len(clicksXY)][1]),[255,255,255],thickness=1)
cv2.imshow("Original frame",X[matIdx])
cv2.waitKey(1)
matIdx+=1
np.save(outputFile,X=XX,Y=Y)
np.savez(outputFile,X=XX,Y=Y)
cv2.destroyAllWindows()
if __name__ == '__main__':
if sys.argv[1].strip().split(".")[-1]=="npz":
mainFuncNpz()
else: mainFuncVideo()
try:
for x in range(len(sys.argv)):
if sys.argv[x].lower()=='fast':
FAST=True
if sys.argv[1].strip().split(".")[-1]=="npz":
mainFuncNpz()
else: mainFuncVideo()
print("Finished processing and writing to file")
except:
print("USAGE:")
print("python screen-detection-3.py videoCodeXYfile.npz croppedFile.npz")
print("python screen-detection-3.py video.mp4 croppedVideo.mp4")
......@@ -5,12 +5,32 @@ This is the python port of Hilight screen detector
#point np.zeros(shape=(2),dtype=np.float32)
#ling np.zeros(shape=(2,1),dtype=np.float32)
'''Tunable Parameters>>>>>>>>>>>>>>>>>>'''
houghRHO=1
houghTHETA=3.14/180
houghTHRESHOLD=150
houghMINLEN=100
houghMINGAP=30
cannyTHRES_1=250
cannyTHRES_2=250
'''<<<<<<<<<<<<<<Tunable Parameters over'''
EPS=0.00000000001
DEBUG=True
RESIZE_RATIO=0.5
FRAME_DELAY=100
import numpy as np
import cv2
import sys
from shapely.geometry import Polygon
vidIn=None
......@@ -86,11 +106,11 @@ def intersectionLines(line1,line2):
# intersection.x = (b2 - b1) / (a1 - a2);
# intersection.y = a1 * intersection.x + b1;
if l1p1[X]!=l1p2[X] and l2p1[X]!=l2p2[X]:
a1=(l1p1[Y]-l1p2[Y])/(l1p1[X]-l1p2[X])
a1=(l1p1[Y]-l1p2[Y])/(EPS+l1p1[X]-l1p2[X])
b1=l1p1[Y] - a1*l1p1[X]
a2=(l2p1[Y]-l2p2[Y])/(l2p1[X]-l2p2[X])
a2=(l2p1[Y]-l2p2[Y])/(EPS+l2p1[X]-l2p2[X])
b2=l2p1[Y] - a2*l2p1[X]
inter[X]=(b2-b1)/(a1-a2)
inter[X]=(b2-b1)/(EPS+a1-a2)
inter[Y]=a1*inter[X]+b1
......@@ -103,7 +123,7 @@ def intersectionLines(line1,line2):
# intersection.y = a2 * intersection.x + b2;
elif l1p1[X]==l1p2[X]:
inter[X]=l1p1[X]
a2=(l2p1[Y]-l2p2[Y])/(l2p1[X]-l2p2[X])
a2=(l2p1[Y]-l2p2[Y])/(EPS+l2p1[X]-l2p2[X])
b2=l2p1[Y]- a2*l2p1[X]
inter[Y]=a2*inter[X]+b2
......@@ -118,7 +138,7 @@ def intersectionLines(line1,line2):
# intersection.y = a1 * intersection.x + b1;
elif l2p1[X]==l2p2[X]:
inter[X]=l2p1[X]
a1=(l1p1[Y]-l1p2[Y])/(l1p1[X]-l1p2[X])
a1=(l1p1[Y]-l1p2[Y])/(EPS+l1p1[X]-l1p2[X])
b1=l1p1[Y] - a1*l1p1[X]
inter[Y]=a1*inter[X] + b1
......@@ -204,14 +224,19 @@ def processFrameUtil(inputFrame,topLeft,topRight,bottomLeft,bottomRight):
linesRight1=np.array([100000.0,0.0])
# if (m_algorithmName == "Canny")
# {
edges=cv2.Canny(grayFrame,250,250)
edges=cv2.Canny(grayFrame,cannyTHRES_1,cannyTHRES_2)
# //edge detection
# cv::Canny(grayImage, edges, m_cannyLoThreshold, m_cannyHiThreshold);
#
lines=cv2.HoughLinesP(edges,1,3.14/180.0,30,minLineLength=100,maxLineGap=100)
lines=cv2.HoughLinesP(edges,houghRHO,houghTHETA,houghTHRESHOLD,minLineLength=houghMINLEN,maxLineGap=houghMINGAP)
# //line detection
# cv::HoughLinesP(edges, hougnLines, m_rho, m_theta, m_threshold, m_minLineLength, m_maxLineGap);
#
......@@ -503,30 +528,82 @@ def processFrameUtil(inputFrame,topLeft,topRight,bottomLeft,bottomRight):
cv2.imshow("Lines",resizedFrame(lineFrame))
cv2.waitKey(FRAME_DELAY)
return np.array([topLeft,topRight,bottomRight,bottomLeft])
if __name__ == '__main__':
# try:
videoFileName=sys.argv[1]
print("FILE NAME = {}".format(videoFileName))
if videoFileName.strip().split(".")[-1]=='mp4':
if videoFileName=='0': vidIn=cv2.VideoCapture(0)
else: vidIn=cv2.VideoCapture(videoFileName)
while(vidIn.isOpened()):
ret,frame=vidIn.read()
if ret:
try:
p=processFrame(frame)
print("Vertex points ",p)
except:
print("Error in frame")
# except:
if videoFileName=='0': vidIn=cv2.VideoCapture(0)
else: vidIn=cv2.VideoCapture(videoFileName)
elif videoFileName.strip().split(".")[-1]=='npz':
data=np.load(videoFileName)
X=data['X']
Y=data['Y']
data=None
errorFrames=0
iou=np.zeros((X.shape[0]),np.float)
for i in range(len(X)):
tempFrame=cv2.resize(X[i],dsize=(1920,1080),interpolation=cv2.INTER_LINEAR)
if DEBUG: print("Frame size {}".format(tempFrame.shape))
while(vidIn.isOpened()):
ret,frame=vidIn.read()
if ret:
try:
p=processFrame(frame)
print("Vertex points ",p)
yPred=processFrame(tempFrame)
except:
print("Error in frame")
# except:
# print("USAGE")
# print("python screen-detection-4-hough.py ./video/video.mp4")
errorFrames+=1
print("Error in frame {}".format(i))
continue
correct = Polygon([(Y[i,0,0],Y[i,0,1]),(Y[i,1,0],Y[i,1,1]),(Y[i,2,0],Y[i,2,1]),(Y[i,3,0],Y[i,3,1])])
pred = Polygon([(yPred[0,0],yPred[0,1]),(yPred[1,0],yPred[1,1]),(yPred[2,0],yPred[2,1]),(yPred[3,0],yPred[3,1])])
print("Correct {}. Pred {}".format(correct,pred))
try:
inter=correct.intersection(pred)
uni=pred.union(pred)
iou[i]=inter.area/(EPS+uni.area)
except:
errorFrames+=1
print("IoU of frame {} is {}".format(i,iou[i]))
meanIoU=np.mean(iou)
meanIoU=meanIoU*(X.shape[0]/(X.shape[0]-errorFrames))
print("Average IoU of correct frames= {}".format(meanIoU))
print("Correct frames={}. Wrong frames={}".format(X.shape[0]-errorFrames,errorFrames))
else:
print("USAGE")
print("python screen-detection-4-hough.py ./video/video.mp4")
cv2.destroyAllWindows()
......@@ -11,6 +11,7 @@ import sys
import os
from keras import layers
from keras.models import load_model
from shapely.geometry import Polygon
from keras.layers import *
from keras import Model, Sequential
......@@ -81,7 +82,6 @@ def getModel(xShape,yShape):
y = layers.AveragePooling2D(name='avg_pool')(y)
y = Flatten()(y)
y = Dropout(0.5)(y)
#y = Dense(32, activation='relu', name='extra-dense')(y)
y = Dense(8, activation='linear', name='predictions')(y)
......@@ -112,6 +112,7 @@ def inverseTransformY(Y,params):
Y=Y.reshape((Y.shape[0],4,2))
Y[:,:,0]=Y[:,:,0]*299.0
Y[:,:,1]=Y[:,:,1]*299.0
# Y=np.maximum(Y,np.full(Y.shape,0))
return Y.astype(np.int32)
......@@ -139,8 +140,8 @@ def inverseTransformX(X):
return ((X+1.0)*128.0).astype(np.uint8)
if __name__ == '__main__':
print("python screen-detetcion-5-nn.py {test|train} model.h5 {train.npz|test.npz|test.mp4} 0 100")
print("args[0] args[1] args[2] args[3] [4][5]")
print("python screen-detetcion-5-nn.py {test|train} model.h5 {train.npz|test.npz|test.mp4} 0 100 {fast|slow}")
print("args[0] args[1] args[2] args[3] [4][5] [6]")
OPERATION=sys.argv[1]
MODEL_FILE_LOCATION=sys.argv[2]
......@@ -149,6 +150,11 @@ if __name__ == '__main__':
TEST_VIDEO=sys.argv[3]
CUDA_DEV=sys.argv[4]
FAST=None
try:
FAST=bool(sys.argv[6])
except:
FAST=False
os.environ["CUDA_VISIBLE_DEVICES"]="{}".format(CUDA_DEV)
......@@ -169,7 +175,7 @@ if __name__ == '__main__':
mod=getModel(X.shape[1:],Y.shape[1:])
mod.fit(x=X,y=Y,batch_size=4,epochs=EPOCHS,validation_split=0.0,shuffle=True)
mod.fit(x=X,y=Y,batch_size=4,epochs=EPOCHS,validation_split=0.3,shuffle=True)
mod.save(MODEL_FILE_LOCATION)
print("DEBUG: FINISHED SAVING MODEL as {}".format(MODEL_FILE_LOCATION))
......@@ -178,8 +184,8 @@ if __name__ == '__main__':
mod = load_model(MODEL_FILE_LOCATION)
if TEST_VIDEO.split(".")[-1]=='npz':
X,Y=load(TEST_VIDEO)
X=X[:250]
Y=Y[:250]
X=X[int(len(X)*0.8):]
Y=Y[int(len(Y)*0.8):]
if DEBUG: print("Non-normalized X=[{},{}] Y=[{},{}]".format(np.min(X),np.max(X),np.min(Y),np.max(Y)))
......@@ -188,28 +194,60 @@ if __name__ == '__main__':
if DEBUG: print("Normalized X=[{},{}] Y=[{},{}]".format(np.min(X),np.max(X),np.min(Y),np.max(Y)))
yPred=mod.predict(X)
if DEBUG: print("Y shape ={} and yPred shape={}".format(Y.shape,yPred.shape))
# yPred=Y
Y=inverseTransformY(Y,[1080.0,1920.0])
yPred=inverseTransformY(yPred,[1080.0,1920.0])
X=inverseTransformX(X)
iou=np.zeros((yPred.shape[0]),np.float)
for i in range(yPred.shape[0]):
frame=X[i]
for j in range(yPred.shape[1]):
#Predicted
cv2.circle(frame,center=(yPred[i,j,0],yPred[i,j,1]),radius=3,color=[255,0,0],thickness=3)
cv2.line(frame,pt1=(yPred[i,j,0],yPred[i,j,1]),pt2=(yPred[i,(j+1)%4,0],yPred[i,(j+1)%4,1]),color=[255,0,0],thickness=1)
correct = Polygon([(Y[i,0,0],Y[i,0,1]),(Y[i,1,0],Y[i,1,1]),(Y[i,2,0],Y[i,2,1]),(Y[i,3,0],Y[i,3,1])])
pred = Polygon([(yPred[i,0,0],yPred[i,0,1]),(yPred[i,1,0],yPred[i,1,1]),(yPred[i,2,0],yPred[i,2,1]),(yPred[i,3,0],yPred[i,3,1])])
#True
cv2.circle(frame,center=(Y[i,j,0],Y[i,j,1]),radius=3,color=[255,255,255],thickness=2)
cv2.line(frame,pt1=(Y[i,j,0],Y[i,j,1]),pt2=(Y[i,(j+1)%4,0],Y[i,(j+1)%4,1]),color=[255,255,255],thickness=1)
# if DEBUG:
# print("yPred = {} and {}".format(yPred[i],pred))
# if DEBUG:
# print("Y = {} and {}".format(Y[i],correct))
cv2.imshow("frame",frame)
cv2.waitKey(100)
inter=correct.intersection(pred)
uni=pred.union(pred)
thisIou=inter.area/uni.area
iou[i]=thisIou
if not FAST:
if DEBUG: print("frame {} IoU= {}".format(i+1,thisIou))
frame=X[i]
for j in range(yPred.shape[1]):
#Predicted
cv2.circle(frame,center=(yPred[i,j,0],yPred[i,j,1]),radius=3,color=[255,0,0],thickness=3)
cv2.line(frame,pt1=(yPred[i,j,0],yPred[i,j,1]),pt2=(yPred[i,(j+1)%4,0],yPred[i,(j+1)%4,1]),color=[255,0,0],thickness=1)
#True
cv2.circle(frame,center=(Y[i,j,0],Y[i,j,1]),radius=3,color=[255,255,255],thickness=2)
cv2.line(frame,pt1=(Y[i,j,0],Y[i,j,1]),pt2=(Y[i,(j+1)%4,0],Y[i,(j+1)%4,1]),color=[255,255,255],thickness=1)
cv2.imshow("frame",frame)
cv2.waitKey(100)
else:
if i%100==0:
print("IoU calculated for {} of {} frames".format(i,yPred.shape[0]))
print("Average IoU = {}".format(np.mean(iou)))
print("StdDev IoU = {}".format(np.std(iou)))
elif TEST_VIDEO.split(".")[-1]=='mp4':
vidIn=cv2.VideoCapture(TEST_VIDEO)
while True:
ret,frame=vidIn.read()
if not ret: break
......
......@@ -22,7 +22,7 @@ SAVE_FILE_NAME= sys.argv[2]
COLOR=sys.argv[3]
FAST=False
MAX_FRAMES=999999
MAX_FRAMES=5000
try:
FAST=(sys.argv[4]=='fast')
MAX_FRAMES=int(sys.argv[5])
......@@ -132,6 +132,7 @@ ret,frame=video.read()
ret,frame=video.read()
for i in range(len(corners)-1):
ret,frame=video.read()
if isGreen[i] and isVideo[i+1]:
X.append(cv2.resize(frame, (299, 299),interpolation=cv2.INTER_LINEAR))
......
......@@ -3,7 +3,7 @@ import cv2
import sys
vidIn=None
ALPHA=0.3
ALPHA=1.0
THRESHOLD=0.1
def getCornersYX(f):
......@@ -16,16 +16,39 @@ def imshow(frame, frameName="frame", delay=10):
if __name__ == '__main__':
print("python screen-detection-7-gmm.py screenVideo.mp4 0.5")
print("python args[0] args[1] [2]")
print("python screen-detection-7-gmm.py screenVideo.mp4 0.5 3.0 0.2")
print("python args[0] args[1] [2] [3] [4]")
VIDEO_FILE=sys.argv[1]
THRESHOLD=float(sys.argv[2])
SATURATION_PARAM=float(sys.argv[3])
ALPHA=float(sys.argv[4])
vidIn=cv2.VideoCapture(VIDEO_FILE)
IS_NPZ=VIDEO_FILE.split(".")[-1]=='npz'
frame=None
vidIn=None
Y=None
if not IS_NPZ:
vidIn=cv2.VideoCapture(VIDEO_FILE)
ret,frame=vidIn.read()
else:
data=np.load(VIDEO_FILE)
vidIn=data['X']
Y=data['Y']
data=None
frame=vidIn[0]
Y=Y.astype(np.float32)
Y[:,:,0]*=(600.0/1920.0)
Y[:,:,1]*=(400.0/1080.0)
ret,frame=vidIn.read()
frame=cv2.resize(frame,(400,600))
print("Probing into Y")
print(Y.shape)
print(np.min(Y),np.max(Y))
frame=cv2.resize(frame,(400,600))
midX=int(frame.shape[1]/2)
midY=int(frame.shape[0]/2)
......@@ -35,24 +58,105 @@ if __name__ == '__main__':
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:
if not IS_NPZ:
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)*SATURATION_PARAM
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)
cv2.circle(frame,(cornersYX[i,1],cornersYX[i,0]),5,[255,0,0],5)
cv2.line(frame,(cornersYX[i,1],cornersYX[i,0]),(cornersYX[(i+1)%4,1],cornersYX[(i+1)%4,0]),[255,0,0],2)
imshow(meanVar)
imshow(frame,frameName="Ori")
if IS_NPZ:
for f in range(vidIn.shape[0]):
frame=cv2.resize(vidIn[f],(400,600))
var=var*(1-ALPHA)+np.square(frame-mean)*ALPHA
mean=mean*(1-ALPHA)+ frame*ALPHA
meanVar=np.mean(var,axis=2)*2.5
meanVar=np.mean(var,axis=2)*SATURATION_PARAM
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 cornersYX[0,0]>0:
if meanVar[cornersYX[0,0]-1,cornersYX[0,1]]>THRESHOLD:
cornersYX[0,0]-=1
else:
......@@ -94,12 +198,9 @@ if __name__ == '__main__':
if meanVar[cornersYX[3,0],cornersYX[3,1]-1]>THRESHOLD:
cornersYX[3,1]-=1
else:
cornersYX[3,1]+=1#np.random.randint(-1,1)'''
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)
......@@ -110,13 +211,8 @@ if __name__ == '__main__':
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)
cv2.circle(frame,(cornersYX[i,1],cornersYX[i,0]),5,[255,0,0],5)
cv2.line(frame,(cornersYX[i,1],cornersYX[i,0]),(cornersYX[(i+1)%4,1],cornersYX[(i+1)%4,0]),[255,0,0],2)
imshow(meanVar)
imshow(frame,frameName="Ori")
This diff is collapsed.
......@@ -18,6 +18,7 @@ def plot_confusion_matrix(y_true, y_pred, classes,
normalize=False,
title=None,
cmap=plt.cm.Blues, param1=0,param2=0):
"""
This function prints and plots the confusion matrix.
Normalization can be applied by setting `normalize=True`.
......@@ -77,7 +78,27 @@ def plot_confusion_matrix(y_true, y_pred, classes,
# Rotate the tick labels and set their alignment.
plt.setp(ax.get_xticklabels(), rotation=0, ha="right",
rotation_mode="anchor")
# double dist = sqrt(pow(y_2-y_1, 2)+pow(x_2-x_1, 2));
# double tan_value = (y_2-y_1)/(x_2-x_1);
# double atan_value = atan(tan_value);
# double slope = std::abs(atan_value);
# if (check){
# if (slope < slope_veritical && dist > threshold_x){
# if (y_1 < screen_width * top_threshold){
# if (lines_top_1.y < y_1){
# lines_top_dist = std::abs(y_1-screen_width * top_threshold);
# lines_top_1 = Point(x_1, y_1);
# lines_top_2 = Point(x_2, y_2);
# }
# }
# if (y_1 > screen_width*botto_threshold){
# if (lines_bottom_1.y > y_1){
# lines_bottom_dist = std::abs(y_1 - screen_width*botto_threshold);