8000 can we use cvzone to detect hand and face in same time · Issue #76 · cvzone/cvzone · GitHub
[go: up one dir, main page]

Skip to content

can we use cvzone to detect hand and face in same time  #76

@gekadev

Description

@gekadev

dear all,
I have an issue when I use cvzone library to detect face and hand together. same time, and make a condition that if i found two hands
screen must be white but actually when i raise only one hand and try to print i found that it is some times to be two hand and screen go to be white then normal , any advice heare

below is my code

import cvzone
from cvzone.HandTrackingModule import HandDetector
from cvzone.FaceDetectionModule import FaceDetector
from cvzone.ClassificationModule import Classifier
from cvzone.PoseModule import PoseDetector
import pyautogui
import cv2
import numpy as np
import time
import mediapipe 
from cvzone.FPS import FPS
import os
import math
import csv
import time
############# our Variables ################################################################################################
#wCam, hCam = 640, 480
wCam, hCam = 1280, 720
cap = cv2.VideoCapture(0)
cap.set(3,wCam)
cap.set(4,hCam)
imageNumber=0
#define the size of  of camerimage that will be over layed on main screen
hs, ws = int(120 * 1), int(150 * 1) 
#show presnter image Mode
presnterImageMode = True
#variable to show white screen in applicatio in case morethan 2 faces detected
faceWhiteImageMode=False
#variable to show white screen in applicatio in case morethan 2 hands detected
handWiteImageMode =False
# handtype used from request to devine which hand will ussed in presntion
handType='Left'



#######################################detectors#############################################################################
detector = HandDetector(staticMode=False,maxHands=2,modelComplexity=1,detectionCon=0.5, minTrackCon=0.5)   
face_detector = FaceDetector(minDetectionCon=0.5, modelSelection=0)
############################################################################################################################
#import presentaion images
folderPath = 'presentaion/'
presnetaionPath = sorted(os.listdir(folderPath),key=len)


while True  :
    _,frame = cap.read()
    frame = cv2.flip(frame,1)
    frame = cv2.resize(frame,(wCam,hCam))
    currentImagePath = os.path.join(folderPath,presnetaionPath[imageNumber])
    currentImage = cv2.imread(currentImagePath)
    #start detect face
    frame , bboxs = face_detector.findFaces(frame,draw=False)
    if bboxs :
        if len(bboxs)>1:
            if faceWhiteImageMode is True:
                    frame = np.ones_like(frame)*255
                    currentImage = np.ones_like(currentImage)*255
                    cvzone.putTextRect(currentImage, f' More Than One Face Detected , Application Paused ',\
                                        (0, 100),border=5,scale=2,thickness=2)
        else:   
            faceWhiteImageMode =False
            for bbox in bboxs :
                facecenter = bbox["center"]
                x, y, w, h = bbox['bbox']
            #draw ine in center of center of face for good presention control
            cv2.line(frame,(0,facecenter[1]),(wCam,facecenter[1]),(0,255,0),10)
    
            #start detection hand
    hands , _ = detector.findHands(frame,draw=False,flipType=True)
    if hands :
        #cas we have two hands  
        if len(hands)>1 :
            handWiteImageMode=True
            if handWiteImageMode is True :
                    frame = np.ones_like(frame)*255
                    currentImage = np.ones_like(currentImage)*255
                    cvzone.putTextRect(currentImage, f' More Than One Hands Detected , Application Paused ', \
                                    (0, 100),border=5,scale=2,thickness=2)
            else:
                handWiteImageMode=False

                        
    #cas we have one hands  
        elif len(hands)==1:
            print('ok')

        #cas we have one hands 
        else:
            pass     
                    
        
    print(handWiteImageMode,len(hands))
    imgPNG = cv2.imread("C:/Users/Geka/Desktop/update.png",cv2.IMREAD_UNCHANGED)
    imgOverlay = cvzone.overlayPNG(currentImage, imgPNG, pos=[0, 650])
    cv2.imshow('imagePresntaion ',frame)
    #cv2.imshow('Presntaion X',currentImage)
    # Display the camera feed
    key = cv2.waitKey(10)
    if key == ord('q'):
        break
    
cap.release()
cv2.destroyAllWindows() 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0