Face Detection Using OpenCV with CUDA GPU Acceleration | Images, Videos

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we are going to perform face detection using opencv and python in the first half of this video i am going to explain how you can use opencv to detect faces in videos and images using cpu and in second half i will explain how you can get a speed up using cuda gpu acceleration let's get started i have two empty files here detector dot pi will be used to implement our detector class and in main we will be writing the code to detect faces in images and videos i have this pre-trained face detection model here i will share the link to this model in the description then i have another folder with some input images and videos which later will be used for face detection demo let's start coding our detector first import numpy cv2 and fps module from imutils so that we can compare performances of phase detection on cpu and gpu next define init function which is executed as soon as the class is instantiated so we will load our model in this function then i am going to define process image function which will take path to the image as input read that image and place it in a variable called self.ing which will be accessible anywhere within the class we also need height and width of the image which we will use later now the fun part detecting faces and drawing a bounding box around them for that i am defining another function called process frame we need to convert the input image to a blob that opencv underscore dnn module understands we need to resize the image to 300 cross 300 and subtract these mean values these parameters are mentioned in the original boast of dnn module we do not need to perform any channel swapping or cropping now we provide this blob as input to our model and perform a forward pass this will give us phase predictions and we need to make a bounding box around all of the detected faces so we need a loop for each detected phase and if the detection confidence is greater than 0.5 we plot the bounding box on the original image using red color and giving a thickness value of 2. [Music] [Music] now we come back to process image function and we call process frame function which draws bounding box on the image next we need to display the final image on screen the face detection for image is implemented to use it import detector in main and create an object call the process image method and pass the image path as parameter there we have it let's run it okay we have an error in the model path let's fix it and here are the results now let's define a function called process video it takes video path as parameter and reads the video using cv2 dot video capture if video is not opened successfully we print error message and return from the function otherwise we grab a frame from the video and save the height and width of the frame also initialize fps module to calculate frame per second for face detection on video now if the frame is grabbed successfully we call process frame function which draws rectangles around the detected faces we show the final image on screen and also provide functionality to break the face detection loop if the user chooses to press q on the keyboard then we update fps information and try to grab next frame from the video when all the frames are processed the fps information is displayed and all opencv windows are destroyed now our program is ready for face detection on videos as well let's call process video method on the video and there we have it this was using cpu and we achieved fps off 30. now if we have built opencv with cuda support we can use gpu acceleration as well let me show you how to do that first we need to introduce this flag called use underscore cuda and if this flag is set to true we need to change backend and target of our model to use cuda that's it now we can pass this parameter to our class and opencv will use gpu acceleration now we have achieved 62 fps which is double then cpu version hit that like button if you have learned something of value today and i will see you in the next one [Music] [Music] you
Info
Channel: TheCodingBug
Views: 16,454
Rating: undefined out of 5
Keywords: face detection using opencv python, face detection python, face detection opencv, detect faces using opencv, detect faces in video python, face detection in python, face detection python windows, computer vision, pencv, opencv python, face detection, facedetection, detect face python, python face detection, python cuda, python windows, python windows face detection, how to detect face using python, detect face using python, face detection with opencv, opencv face detection
Id: GXcy7Di1oys
Channel Id: undefined
Length: 7min 4sec (424 seconds)
Published: Mon Jan 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.