kennedy saine Banda
Published © Apache-2.0

Hand-i-Shine

Imagine controlling light as naturally as flicking a switch, but without the switch. Introducing Hand-i-Shine, hand controlled light builb.

IntermediateProtip5 hours284
Hand-i-Shine

Things used in this project

Story

Read more

Code

Hand Controlled Builb

Python
These are the codes for the project
from cvzone.HandTrackingModule import HandDetector
import cv2
import serial
import cvzone
import time

# Define the serial port and baud rate
serial_port = 'COM4'  # Update with your Arduino's serial port
baud_rate = 9600

# Open a serial connection
ser = serial.Serial(serial_port, baud_rate)



# Initialize the webcam to capture video
# The '2' indicates the third camera connected to your computer; '0' would usually refer to the built-in camera
cap = cv2.VideoCapture(0)

# Initialize the HandDetector class with the given parameters
detector = HandDetector(staticMode=False, 
                        maxHands=1, 
                        modelComplexity=1, 
                        detectionCon=0.7,
                          minTrackCon=0.7)

# Continuously get frames from the webcam
while True:
    # Capture each frame from the webcam
    # 'success' will be True if the frame is successfully captured, 'img' will contain the frame
    success, img = cap.read()

    # Find hands in the current frame
    # The 'draw' parameter draws landmarks and hand outlines on the image if set to True
    # The 'flipType' parameter flips the image, making it easier for some detections
    hands, img = detector.findHands(img, draw=True, flipType=True)

    # Check if any hands are detected
    if hands:
        # Information for the first hand detected
        hand1 = hands[0]  # Get the first hand detected
        lmList1 = hand1["lmList"]  # List of 21 landmarks for the first hand
        bbox1 = hand1["bbox"]  # Bounding box around the first hand (x,y,w,h coordinates)
        center1 = hand1['center']  # Center coordinates of the first hand
        handType1 = hand1["type"]  # Type of the first hand ("Left" or "Right")

        # Count the number of fingers up for the first hand
        fingers1 = detector.fingersUp(hand1)
        if fingers1.count(1) == 5:
            command = "H"
            ser.write(command.encode())
            print(ser.write(command.encode()))
        if fingers1.count(1) == 1:
            command = "L"
            ser.write(command.encode())
            print(ser.write(command.encode()))

    # Display the image in a window
    cv2.imshow("Image", img)

    # Keep the window open and update it for each frame; wait for 1 millisecond between frames
    cv2.waitKey(1)

Arduino Codes

Arduino
These are the codes for the arduino
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
if (Serial.available() > 0 )
{
  int readVal = Serial.parseInt();
  if (readVal == 1)
  {
    digitalWrite(2,HIGH);
  }  
  else
  {
    digitalWrite(2,LOW);
  }
}

}

Credits

kennedy saine Banda
5 projects • 8 followers
Innovator blending AI, ML, and embedded systems to craft smart solutions. Expertise in biomedical engineering, CV, welding & IoT.
Contact
Thanks to Murtaza's Workshop - Robotics and AI.

Comments

Please log in or sign up to comment.