diff --git a/backend/src/NPMean.py b/backend/src/NPMean.py index c8da7b37..15584c2f 100644 --- a/backend/src/NPMean.py +++ b/backend/src/NPMean.py @@ -6,20 +6,31 @@ class NPMeanSequential: def __init__(self): self.i0 = None self.i1 = None - def forward(self, img1): #forward method calculates out mean of new img, and saves current img as old + def sceneDetect(self, img1): if self.i0 is None: self.i0 = img1 self.image0mean = np.mean(self.i0) return self.i1 = img1 - self.img1mean = np.mean(self.i1) - - def isSceneChange(self): - if self.image0mean > self.img1mean + 20 or self.image0mean < self.img1mean - 20: - self.image0mean = self.img1mean + img1mean = np.mean(self.i1) + if self.image0mean > img1mean + 20 or self.image0mean < img1mean - 20: + self.image0mean = img1mean return True - self.image0mean = self.img1mean + self.image0mean = img1mean return False - def isMeanEqual(self): - return self.image0mean == self.img1mean \ No newline at end of file + def isEqualImages(self,img1): + if self.i0 is None: + self.i0 = img1 + self.image0mean = np.mean(self.i0) + return + self.i1 = img1 + img1mean = np.mean(self.i1) + if (self.i0==self.i1).all(): + self.image0mean = img1mean + self.i0 = self.i1 + return True + self.i0 = self.i1 + self.image0mean = img1mean + return False + diff --git a/backend/src/SceneDetect.py b/backend/src/SceneDetect.py index 43891e89..04b302b8 100644 --- a/backend/src/SceneDetect.py +++ b/backend/src/SceneDetect.py @@ -97,8 +97,7 @@ def getMeanTransitions(self): detector = NPMeanSequential() for frame_num in tqdm(range(self.totalInputFrames - 1)): frame = bytesTo100x100img(self.readQueue.get()) - detector.forward(frame) - if detector.isSceneChange(): + if detector.sceneDetect(frame): sceneChangeQueue.put(frame_num-1) return sceneChangeQueue