element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Artificial Intelligence and Machine Learning
  • Technologies
  • More
Artificial Intelligence and Machine Learning
Forum I made a Lightweight Fingers Detection model That dosent uses any Training Data or any AI and is almost accurate
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Artificial Intelligence and Machine Learning to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 86 subscribers
  • Views 335 views
  • Users 0 members are here
  • no AI
  • python 3.7
Related

I made a Lightweight Fingers Detection model That dosent uses any Training Data or any AI and is almost accurate

Aniket_kumar_raj
Aniket_kumar_raj 14 days ago

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

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

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()

  • Sign in to reply
  • Cancel
  • robogary
    robogary 14 days ago

    Nice. Your comments and variable names are hilarious !  You had too much fun  :-) 

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • battlecoder
    battlecoder 14 days ago

    OpenCV is such a fun framework to work with. Love your code and comments btw. Wish more people were this whimsical when they write code.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • dang74
    dang74 14 days ago in reply to robogary

    Indeed not to mention a variable called duct_tape.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • Aniket_kumar_raj
    Aniket_kumar_raj 14 days ago in reply to dang74

    The duct_tape is there to keep the hole_in_the_space_time_continuum from expanding. It’s a safety feature. Without it, the chicken_nuggets start manifesting in physical reality, and my GPU can't handle that kind of rendering.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • Aniket_kumar_raj
    Aniket_kumar_raj 14 days ago in reply to dang74

    i heard 90% of the internet is held together by duct_tape and hope_and_prayers. I’m just following industry standards.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • dougw
    dougw 14 days ago

    Here are some fingers...

    image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • dang74
    dang74 14 days ago in reply to Aniket_kumar_raj
    Aniket_kumar_raj said:
    It’s a safety feature. Without it, the chicken_nuggets start manifesting in physical reality

    'Manifested Reality' I think that was one of the original dipping sauces available at McDonald's.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB 13 days ago

    Very nice post.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Christopher678
    Christopher678 10 days ago

    Great post

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube