|
|
|
@ -2,6 +2,12 @@ import cv2
|
|
|
|
|
import numpy as np
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def variance_of_laplacian(image):
|
|
|
|
|
return cv2.Laplacian(image, cv2.CV_64F).var()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"]="rtsp_transport;tcp"
|
|
|
|
|
|
|
|
|
|
gstreamerstr = "tcpclientsrc host=192.168.0.144 port=5000 ! jpegdec ! videoconvert ! appsink"
|
|
|
|
@ -9,16 +15,46 @@ gstreamerstr = "tcpclientsrc host=192.168.0.144 port=5000 ! jpegdec ! videoconve
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if not capture.isOpened() : print("CANNOT OPEN STREAM")
|
|
|
|
|
|
|
|
|
|
capture = cv2.VideoCapture("vid.mp4")
|
|
|
|
|
keypressNo = 1
|
|
|
|
|
while(True):
|
|
|
|
|
capture = cv2.VideoCapture(gstreamerstr,cv2.CAP_GSTREAMER)
|
|
|
|
|
#capture = cv2.VideoCapture(gstreamerstr,cv2.CAP_GSTREAMER)
|
|
|
|
|
|
|
|
|
|
ret, frame = capture.read()
|
|
|
|
|
if not ret:
|
|
|
|
|
print('fail')
|
|
|
|
|
break
|
|
|
|
|
cv2.imshow('frame',frame)
|
|
|
|
|
cv2.waitKey(1)
|
|
|
|
|
|
|
|
|
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
|
|
|
|
variance = variance_of_laplacian(frame)
|
|
|
|
|
|
|
|
|
|
cv2.putText(frame, "{}: {:.2f}".format("Variance:", variance), (10, 30),
|
|
|
|
|
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
|
|
|
|
|
cv2.imshow('frame',frame)
|
|
|
|
|
#cv2.waitKey(0)
|
|
|
|
|
|
|
|
|
|
if cv2.waitKey(70) == ord('v'):
|
|
|
|
|
frames=[]
|
|
|
|
|
maxVarIdx = 0
|
|
|
|
|
maxVar = 0
|
|
|
|
|
for i in range(5):
|
|
|
|
|
ret, frame = capture.read()
|
|
|
|
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
|
|
|
|
frames.append(frame)
|
|
|
|
|
var = variance_of_laplacian(frame)
|
|
|
|
|
if var > maxVar:
|
|
|
|
|
maxVar = var
|
|
|
|
|
maxVarIdx = i
|
|
|
|
|
cv2.waitKey(20)
|
|
|
|
|
#test to see if the image with the highest variance gets picked
|
|
|
|
|
#cv2.putText(frame, "{}: {:.2f}".format("Variance:", var), (10, 30),
|
|
|
|
|
#cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
|
|
|
|
|
#writeString="imgtest"+str(keypressNo)+str(i)+".jpg"
|
|
|
|
|
#cv2.imwrite(writeString, frames[i])
|
|
|
|
|
writeString="img"+str(keypressNo)+".jpg"
|
|
|
|
|
cv2.imwrite(writeString, frames[maxVarIdx])
|
|
|
|
|
keypressNo=keypressNo+1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
capture.release()
|
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
|