22from django .http import JsonResponse
33from .models import Video
44
5+
6+ from skimage .measure import structural_similarity as ssim
7+ import matplotlib .pyplot as plt
58import cv2
69import math
710import numpy as np
@@ -66,8 +69,8 @@ def VidProc(videoPath):
6669 success , image = vidcap .read ()
6770 count = 0
6871 while success :
69- if (count == 300 ):
70- break
72+ # if(count == 300):
73+ # break
7174 success , image = vidcap .read ()
7275 frameId = vidcap .get (1 ) # current frame number
7376
@@ -78,7 +81,14 @@ def VidProc(videoPath):
7881
7982 # Write frame in frames folder
8083 cv2 .imwrite (src_path + "frame%d.jpg" % count , image ) # save frame as JPEG file
81-
84+ if (count > 0 ):
85+ img1 = cv2 .imread (src_path + "frame" + str (count - 1 ) + ".jpg" , 0 )
86+ img2 = cv2 .imread (src_path + "frame" + str (count ) + ".jpg" , 0 )
87+ SSIM = ssim (img1 , img2 )
88+ print ("ssim: " ,count , " " , SSIM )
89+ if (SSIM > .90 ):
90+ print ("inside here" )
91+ continue
8292 # Convert Frame Into Text
8393 # print ("\n\nImage Into String :", get_string("/home/arjun/Desktop/majorProject/frames/frame{0}.jpg".format(count)))
8494 get_string (src_path + "frame{0}.jpg" .format (count ))
@@ -98,7 +108,6 @@ def index(request):
98108def searchView (request ):
99109 toSearch = request .GET .get ("toSearch" )
100110 print (toSearch )
101- print ("here" )
102111 videos = Video .objects .all ()
103112 return render (request , "list.html" , {
104113 "toSearch" : toSearch ,
@@ -109,13 +118,18 @@ def searchView(request):
109118def videoProc (request ):
110119 print ("here in videoProc" )
111120 videos = Video .objects .all ()
121+ videosProcessed = 0
112122 for video in videos :
123+ if (video .data != None ):
124+ continue
125+ print ("Video Title" , video .title )
113126 VidProc ("/home/arjun/Desktop/majorProjectDjango/ContentBasedVideoExtraction/media-files/" + str (video .videoFile ))
114- print ("/home/arjun/Desktop/majorProjectDjango/ContentBasedVideoExtraction/media-files/" + str (video .videoFile ))
127+ # print("/home/arjun/Desktop/majorProjectDjango/ContentBasedVideoExtraction/media-files/" + str(video.videoFile))
115128 print ("\n \n dictOfWords:\n " )
116129 for k , v in dictOfWords .items ():
117130 print (k , " => " , v )
118131 video .data = dictOfWords
119132 video .save ()
120- dictOfWords = {}
121- return JsonResponse ({"name" : "videoProc" })
133+ dictOfWords .clear ()
134+ videosProcessed += 1
135+ return JsonResponse ({"videosProcessed" : videosProcessed })
0 commit comments