Motive There are different types of modules in python which not everyone knows so we thought of introducing them to you guys. Let's start! Note: This is not a tutorial of how to use these but is to show that these modules also exist and if you want to know more you can visit there own page and if you want us to explain leave a comment below. Links to there page are also given below. Hope you found something useful. 1.Wikipedia Yes, there is a module called Wikipedia in python, you can easily install Wikipedia by pip install wikipedia . We cannot rely on this module for advanced use. It was designed for ease of use and simplicity. Learn More Here . Here is a simple example: import wikipedia wikiPython = wikipedia.summary("Python", sentences=2) print(wikiPython) One big disadvantage is that it works only if the interne...
Motive
Machine Learning is not that easy to lean in python and YouTube tutorials cannot rely heavily so I taught of making a model and explain to you guys how machine learning works. We will not be making the rules for the model instead we will take a pre-trained model for our use. Training a model takes time and we need a lot of data so we will take the easier path for now.
The Project
The only library that we need is OpenCV, if you have not installed it then pip install it in your terminal, pip install opencv-python. You can learn more here.
Now open your preferred ide and import opencv, while coding we use cv2 for opencv:
Now as I told above we will use a pre-trained model for this use so download it from here. Now let's mention it in the code and ensure that the XML file is in the same directory.
We will be using the webcam to detect the faces so let's mention that also with the help of open cv it is easy to take frames from a video and use it for detection.
If you want to use a file instead of the use the file name in inverted commas instead of the 0. Like this cv2.VideoCapture('filename.mp4').
Since it is a video we have to take its frames for detection for that we need a while loop, In which we take frames from the video and then convert it into grayscale.
Here we take the frames for the video in the variable image and the cover the image to greyscale that greyscale image is stored in the variable called grayscale.
Now let's detect the faces:
The three variables are, grayscale which is the image,1.2 which is the scale factor and 4 is the minimum neighbours. If any issues change these values.
Now, let's draw a black rectangle for the face:
Now show the image.
Now if see key is pressed it loop will break and the code ends.
And that's it and run the code and test it your self.
The Full Code
If you have any doubts or errors in the program feel free to comment down below and I will respond as early as possible. And if I have made any mistake please correct me in the comment box below. Don't forget to follow us for such python related content.
Comments
Post a Comment