How calculate the distance between top and bottom lips to detect if speaker or non speaker

Viewed 13

i want to ask how I can detect if someone speaking or non in a video after face detection and tracking , i tried to apply that by using yawn code with littel modified but it doesn't work. unless he is quiet or smile.

below is part of my code please help me to do that

 # Put fps at which we are processing camera feed on frame
                        cv2.putText(frame, "{0:.2f}-fps".format(fps_processing),
                                        (50, height-50), cv2.FONT_HERSHEY_COMPLEX,
                                        1, (0, 0, 255), 2)
                        
                        #-------Detecting/Marking the lower and upper lip--------#
                        lip = shape[48:60]
                        cv2.drawContours(frame,[lip],-1,(0, 165, 255),thickness=3)
  
                        #-------Calculating the lip distance-----#
                        lip_dist = cal_yawn(shape)
                        print(lip_dist)
                        if lip_dist > yawn_thresh : 
                            cv2.putText(frame, f'User speaking!',(frame.shape[1]//2 - 170 
                                                             ,frame.shape[0]//2),cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,200),2)
                            yawn_thresh = lip_dist
                            #count_lip += 1 
                            
                        elif lip_dist < yawn_thresh and yawn_thresh != 0:
                            cv2.putText(frame, f'User speaking low!',(frame.shape[1]//2 - 170 
                                                             ,frame.shape[0]//2),cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,200),2)
                            yawn_thresh = lip_dist
                            #count_lip += 1 
                            
                        else:
                            count_lip +=1
                            if count_lip > 3:
                                cv2.putText(frame, f'User not speaking !',(frame.shape[1]//2 - 170 
                                                           ,frame.shape[0]//2),cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,200),2)
                                valid_video = False
                                break

also the function of calculating the distance between top and bottom lip

def cal_yawn(shape): 
    #top_lip = shape[50:53]
    top_lip = shape[61:64]
    #top_lip = np.concatenate((top_lip, shape[61:64]))
  
    #low_lip = shape[56:59]
    low_lip = shape[65:68]
    #low_lip = np.concatenate((low_lip, shape[65:68]))
  
    top_mean = np.mean(top_lip, axis=0)
    low_mean = np.mean(low_lip, axis=0)
  
    distance = dist.euclidean(top_mean,low_mean)
    #distance = dist.euclidean(top_lip,low_lip)
    return distance    
 

0 Answers
Related