Do you know where was i For a few Days....
I was Grounded home with no internet so i made something that i was not able to find on internet... but first lets start from beginning to explain everything .look at this thing
I saw this short in my Short feed and tried to create it but the one thing required was a lightest hand detection model, but none ai could make it and i wasn't able to find any on internet , then i took everything in my own hands and made this code that detects fingers smoothly, but dont move your face in box, only hands are allowed in the green box
here is the code that i made roasting my 1.3 megapixel camera of 17 years old laptop that i use for daily study..
to use this you must have these liblaries in python --->
cv2 , numpy , math
I did add comments so its easy to understand and variables are good too
import cv2
import numpy as np
import math
# This function does literally nothing, like my productivity on a Friday
def hole_in_the_space_time_continuum(x): pass
# Waking up the 1.3MP beast
eye_of_sauron = cv2.VideoCapture(0)
cv2.namedWindow("The_Lag_Machine")
# Trackbars for when the lighting in your room changes by 1%
cv2.createTrackbar("Magic_Slider", "The_Lag_Machine", 203, 255, hole_in_the_space_time_continuum)
cv2.createTrackbar("Jitter_Control", "The_Lag_Machine", 15, 50, hole_in_the_space_time_continuum)
while True:
# Trying to grab a frame before the laptop overheats
is_it_alive, blurry_mess = eye_of_sauron.read()
if not is_it_alive: break
# 1. Flip it because reality is disappointing
blurry_mess = cv2.flip(blurry_mess, 0)
the_forbidden_zone = blurry_mess[50:450, 50:450]
cv2.rectangle(blurry_mess, (50, 50), (450, 450), (0, 255, 0), 2)
# 2. Add filters to hide the 2009 sensor quality
depression_mode = cv2.cvtColor(the_forbidden_zone, cv2.COLOR_BGR2GRAY)
smudge_tool = cv2.GaussianBlur(depression_mode, (15, 15), 0)
current_mood = cv2.getTrackbarPos("Magic_Slider", "The_Lag_Machine")
_, crunchy_pixels = cv2.threshold(smudge_tool, current_mood, 255, cv2.THRESH_BINARY_INV)
# Trying to glue the pixels back together
duct_tape = np.ones((5,5), np.uint8)
crunchy_pixels = cv2.morphologyEx(crunchy_pixels, cv2.MORPH_CLOSE, duct_tape)
wiggly_lines, _ = cv2.findContours(crunchy_pixels, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
chicken_nuggets = []
lies_on_screen = "Looking for signs of life..."
if wiggly_lines:
the_big_blob = max(wiggly_lines, key=cv2.contourArea)
if cv2.contourArea(the_big_blob) > 2500:
# Finding the center of the mess
secret_map = cv2.distanceTransform(crunchy_pixels, cv2.DIST_L2, 5)
_, max_stress, _, the_pixel_god = cv2.minMaxLoc(secret_map)
holy_x, holy_y = int(the_pixel_god[0]), int(the_pixel_god[1])
# Checking if it's a hand or just a ghost
protective_shell = cv2.convexHull(the_big_blob)
how_chunky = float(cv2.contourArea(the_big_blob)) / cv2.contourArea(protective_shell)
if how_chunky < 0.88:
chaos_factor = cv2.getTrackbarPos("Jitter_Control", "The_Lag_Machine")
math_points = the_big_blob.reshape(-1, 2)
point_count = len(math_points)
for i in range(0, point_count, 2):
# Geometry is harder than my life choices
a, b, c = math_points[(i-chaos_factor)%point_count], math_points[i], math_points[(i+chaos_factor)%point_count]
vector_1, vector_2 = a - b, c - b
len_1, len_2 = np.linalg.norm(vector_1), np.linalg.norm(vector_2)
if len_1 > 0 and len_2 > 0:
confusing_angle = math.degrees(math.acos(np.clip(np.dot(vector_1,vector_2)/(len_1*len_2), -1.0, 1.0)))
# Is it a finger? Or just a glitch in the Matrix?
dist_to_shell = abs(cv2.pointPolygonTest(protective_shell, (float(b[0]), float(b[1])), True))
dist_to_ego = np.linalg.norm(b - np.array([holy_x, holy_y]))
if 10 < confusing_angle < 45 and b[1] < (holy_y + 50) and dist_to_shell < 8:
if dist_to_ego > (max_stress * 1.4):
if not any(np.linalg.norm(b - np.array(prev)) < 30 for prev in chicken_nuggets):
chicken_nuggets.append(tuple(b))
lies_on_screen = f"FINGERS OR NUGGETS: {len(chicken_nuggets)}"
else:
lies_on_screen = "ANGRY FIST"
# Draw green circles so we feel like hackers
cv2.circle(the_forbidden_zone, (holy_x, holy_y), int(max_stress), (0, 255, 0), 1)
for nugget in chicken_nuggets:
cv2.circle(the_forbidden_zone, nugget, 10, (255, 0, 0), -1)
cv2.line(the_forbidden_zone, (holy_x, holy_y), nugget, (0, 255, 255), 1)
cv2.putText(blurry_mess, lies_on_screen, (60, 40), 1, 2, (0, 255, 0), 2)
cv2.imshow("The_Lag_Machine", blurry_mess)
cv2.imshow("What_The_Computer_Sees", crunchy_pixels)
# Press 'q' to escape this nightmare
if cv2.waitKey(1) & 0xFF == ord('q'): break
eye_of_sauron.release()
cv2.destroyAllWindows()