this is the last presentation in the OpenCV series. this presentation is about the inculcation of different shapes into the given image. It also includes automated shapes using haarcascades. tasks like face detection, face blocking, eye detection, eye blocking, smile detection, smile blocking and so on are displayed in this presentation. the code along with the output images are displayed in the presentation. Hope this presentation helps!!!.
2. Adding shapes
• It is possible to add shapes in the images using OpenCV.
• The function is based on the shape we want to add in the image.
• It can be a line or circle or rectangle or square.
• All depends on the coordinates of the shapes to be present.
• In some cases, the coordinates can be automated meaning that the machine
decides the coordinates for the shape.
3. Adding a line
• To add a line we have to use the cv2.line() function.
• The first argument is the location of the read image.
• It is nothing but the variable which contains the read image.
• The second argument is the starting point of the line.
• The third argument is the ending point of the line.
• The fourth argument is the color in BGR format.
• The fifth argument is the thickness which is specified as a number.
4. Color codes
DESIRED COLOR VALUE
Blue (255,0,0)
Green (0,255,0)
Red (0,0,255)
Yellow (0,255,255)
Magenta (255,0,255)
Cyan (255,255,0)
White (255,255,255)
Black (0,0,0)
7. Adding a rectangle
• A rectangle is a two dimensional object containing two sides.
• The cv2.square() function is used to add a square to the given image.
• The first argument is the location of the image.
• The second and the third argument refers to the coordinates of the square.
• The fourth argument is the color which is the same as before.
• The last argument is the thickness which is the same as before.
10. Adding a square
• There is no specific function to add a square in an image.
• There is no cv2.square() function in OpenCV.
• We have to bring a square using the cv2.rectangle() function.
• A square is nothing but a rectangle with equal sides.
• The coordinates have to be adjusted in the required fashion.
12. Adding a circle
• It is possible to add a circle to the given image.
• The function is cv2.circle()
• There are two parameters required for a circle, the center and the radius.
• So there are only two changes in the function when compared to previous.
• The second argument is the center point and the third argument is the radius
of the circle.
15. Haar cascades
• In all the cases before, the coordinates of the shapes were given by us.
• But we can make the machine determine the coordinates for the shapes.
• This is something like face detection.
• There are more than face detection available in haar cascades.
• These algorithms return the coordinates for the binding box based on the
command we give.
• The algorithms are present in a xml file (extensive markup language).
16. Xml files
• The type of xml files determine the type of detection to be done in the
image.
• There are xml files for the following:-
• Eye
• Eye with glass
• Frontal face of cat
17. Contd..
• Frontal face of cat extended version
• Front face of human
• Full body
• Left eye
• License plate
19. Procedure
• Convert the image to gray scale.
• Call the haar cascade xml file using the CascadeClassifier.
• Detect the following in the grayscale image using the detectMultiScale
• This will return the x,y coordinates and the height and width values.
• Using a for loop plot a rectangle from the parameters mentioned above.
20. Alternative
• The conventional procedure is to download the xml file and then show the
location in the IDE.
• However this doesn’t work in most of the cases.
• Also the source for the xml files is not clear.
• Instead we can use the cv2.data.haarcascades along with the xml file name to
get the desired xml file.