diff --git a/Application/Config.py b/Application/Config.py index 4aebf2a..ec214a5 100644 --- a/Application/Config.py +++ b/Application/Config.py @@ -13,8 +13,7 @@ class Config: "maxLength": None, "ttolerance": 60, "videoBufferLength": 500, - "noiseThreashold": 0.25, - "noiseSensitivity": 3/4, + "noiseThreashold": 0.4, "LayersPerContour": 20, "avgNum":10 } diff --git a/Application/ContourExctractor.py b/Application/ContourExctractor.py index a5f682d..5e57eb5 100644 --- a/Application/ContourExctractor.py +++ b/Application/ContourExctractor.py @@ -74,7 +74,7 @@ class ContourExtractor: firstFrame = self.averages.pop(frameCount, None) if frameCount % (60*30) == 0: - print(f"{frameCount/(60*30)} Minutes processed in {round((time.time() - self.start), 2)} each") + print(f" \r {frameCount/(60*30)} Minutes processed in {round((time.time() - self.start), 2)} each", end='\r') self.start = time.time() gray = self.prepareFrame(frame) diff --git a/Application/Exporter.py b/Application/Exporter.py index 21af56e..ee83032 100644 --- a/Application/Exporter.py +++ b/Application/Exporter.py @@ -41,10 +41,12 @@ class Exporter: start = time.time() for i, layer in enumerate(layers): - print(f"\r {i}/{len(layers)} {round(i/len(layers)*100,2)}% {round((time.time() - start)/(i+1), 2)}", end='\r') + print(f"\r {i}/{len(layers)} {round(i/len(layers)*100,2)}% {round((time.time() - start), 2)}s", end='\r') if len(layer.bounds[0]) == 0: continue + if layer.stats["dev"] < 5: + continue listOfFrames = self.makeListOfFrames([layer]) @@ -75,6 +77,7 @@ class Exporter: writer.append_data(frame2) videoReader.thread.join() + videoReader.vc.release() writer.close() @@ -93,7 +96,7 @@ class Exporter: while not videoReader.videoEnded(): frameCount, frame = videoReader.pop() if frameCount % (60*self.fps) == 0: - print("Minutes processed: ", frameCount/(60*self.fps)) + print("Minutes processed: ", frameCount/(60*self.fps), end="\r") if frame is None: print("ContourExtractor: frame was None") continue @@ -117,6 +120,7 @@ class Exporter: cv2.putText(frames[frameCount - layer.startFrame], str(int(frameCount/self.fps)), (int(x+w/2), int(y+h/2)), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255), 2) videoReader.thread.join() + videoReader.vc.release() self.fps = videoReader.getFPS() fps = self.fps diff --git a/Application/Layer.py b/Application/Layer.py index 7c8c4d4..c2c3882 100644 --- a/Application/Layer.py +++ b/Application/Layer.py @@ -38,7 +38,7 @@ class Layer: #print("Layer constructed") def add(self, frameNumber, bound): - '''Adds a bound''' + '''Adds a bound to the Layer at the layer index which corresponds to the given framenumber''' if self.startFrame + len(self.bounds) - 1 > frameNumber: if len(self.bounds[frameNumber - self.startFrame]) >= 1: self.bounds[frameNumber - self.startFrame].append(bound) @@ -56,25 +56,20 @@ class Layer: y = (bound[1] + bound[3]/2) middles.append([x,y]) - avgx = 0 - avgy = 0 + avg = 0 for i in range(1, len(middles), 2): - avgx += float(middles[i][0]-middles[i-1][0])/len(middles) - avgy += float(middles[i][1]-middles[i-1][1])/len(middles) + avg += (((float(middles[i][0]-middles[i-1][0])/len(middles))**2 + float(middles[i][1]-middles[i-1][1])/len(middles))**2)**(1/2) self.stats = dict() - self.stats["avg"] = round((avgx**2 + avgy**2)**(1/2),2) + self.stats["avg"] = round(avg,2) x=0 - y=0 - for i in range(0, len(middles)): - x += (float(middles[i][0]) - avgx)**2 - y += (float(middles[i][1]) - avgy)**2 + for i in range(1, len(middles), 2): + x += (((((float(middles[i][0]-middles[i-1][0])/len(middles))**2 + float(middles[i][1]-middles[i-1][1])/len(middles))**2)**(1/2)) - avg)**2 x /= (len(middles)-1) - y /= (len(middles)-1) - self.stats["var"] = round((x**2 + y**2)**(1/2),2) - self.stats["dev"] = round((x + y)**(1/2), 2) + self.stats["var"] = round(x,2) + self.stats["dev"] = round((x)**(1/2), 2) def getLength(self): @@ -92,7 +87,6 @@ class Layer: mapped = [] mapping = [] clusterCount = 1 - noiseSensitivity = self.config["noiseSensitivity"] noiseThreashold = self.config["noiseThreashold"] # calculates the middle of each contour in the 2d bounds[] and saves it in 1d list diff --git a/Application/LayerFactory.py b/Application/LayerFactory.py index 16d8c35..d02161c 100644 --- a/Application/LayerFactory.py +++ b/Application/LayerFactory.py @@ -43,7 +43,7 @@ class LayerFactory: for frameNumber in sorted(data.keys()): contours = data[frameNumber] if frameNumber%5000 == 0: - print("\r" + f" {int(round(frameNumber/max(data.keys()), 2)*100)}% done with Layer extraction", end='\r') + print(f" {int(round(frameNumber/max(data.keys()), 2)*100)}% done with Layer extraction", end='\r') tmp = [[frameNumber, contour] for contour in contours] #pool.map(self.getLayers, tmp) @@ -71,12 +71,12 @@ class LayerFactory: self.oldLayerIDs.append(i) continue - lastXframes = 3 + lastXframes = 5 if len(self.layers[i].bounds) < lastXframes: lastXframes = len(self.layers[i].bounds) lastBounds = [bound for bounds in self.layers[i].bounds[-lastXframes:] for bound in bounds] - for bounds in lastBounds: + for j, bounds in enumerate(lastBounds): if bounds is None: break (x2,y2,w2,h2) = bounds diff --git a/main.py b/main.py index 47aa2ab..61fa214 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ def main(): start = time.time() config = Config() - fileName = "3.mp4" + fileName = "x23.mp4" outputPath = os.path.join(os.path.dirname(__file__), "output") dirName = os.path.join(os.path.dirname(__file__), "generate test footage") @@ -42,7 +42,7 @@ def main(): layers = layerManager.layers exporter = Exporter(config) print(f"Exporting {len(contours)} Contours and {len(layers)} Layers") - exporter.export(layers, contours, raw=True, overlayed=False) + exporter.export(layers, contours, raw=True, overlayed=True) print("Total time: ", time.time() - start) exit(0) diff --git a/ueberblick.drawio.png b/ueberblick.drawio.png index 14d15a0..60ace41 100644 Binary files a/ueberblick.drawio.png and b/ueberblick.drawio.png differ