diff --git a/cli/test.py b/cli/test.py index 4c36188..191ce66 100644 --- a/cli/test.py +++ b/cli/test.py @@ -77,16 +77,12 @@ try: height, width = frame.shape[:2] # Create a histogram of the image with 8 values - hist = cv2.calcHist([frame],[0],None,[8],[0,256]) - # Fill with the total values combined for percentage calulation - hist_total = 0 + hist = cv2.calcHist([frame], [0], None, [8], [0, 256]) + # All values combined for percentage calculation + hist_total = int(sum(hist)[0]) # Fill with the overal containing percentage hist_perc = [] - # Loop though all values to add them to the total - for value in hist: - hist_total += value[0] - # Loop though all values to calculate a pensentage and add it to the overlay for index, value in enumerate(hist): value_perc = float(value[0]) / hist_total * 100 diff --git a/compare.py b/compare.py index fdf5ebb..85b9b75 100644 --- a/compare.py +++ b/compare.py @@ -37,6 +37,8 @@ models = [] encodings = [] # Amount of frames already matched tries = 0 +# Amount of ingnored dark frames +dark_tries = 0 # Try to load the face model from the models folder try: @@ -73,6 +75,16 @@ while True: # Don't remove ret, it doesn't work without it ret, frame = video_capture.read() + # Create a histogram of the image with 8 values + hist = cv2.calcHist([frame], [0], None, [8], [0, 256]) + # All values combined for percentage calculation + hist_total = int(sum(hist)[0]) + + # Scrip the frame if it exceeds the threshold + if float(hist[0]) / hist_total * 100 > float(config.get("video", "dark_threshold")): + dark_tries += 1 + continue + # Get the height and with of the image height, width = frame.shape[:2] @@ -123,6 +135,7 @@ while True: print(" Used: " + str(scale_height) + "x" + str(scale_width)) print("\nFrames searched: " + str(frames) + " (" + str(round(float(frames) / (timings[4] - timings[2]), 2)) + " fps)") + print("Dark frames ignored: " + str(dark_tries)) print("Certainty of winning frame: " + str(round(match * 10, 3))) # Catch older 3-encoding models diff --git a/config.ini b/config.ini index a019e35..8e92636 100644 --- a/config.ini +++ b/config.ini @@ -22,6 +22,12 @@ device_id = 1 # Speeds up face recognition but can make it less precise max_height = 320 +# Because of flashing IR emitters, some frames can be completely unlit +# Skip the frame if the lowest 1/8 of the histogram is above this percentage +# of the total +# The lower this setting is, the more dark frames are ignored +dark_threshold = 50 + [debug] # Show a short but detailed diagnostic report in console end_report = false