Using Machine learning and python tools to detect palm lines. Detecting palm lines is a use case of image recognition.
Open-cv library overview
open-cv is mainly used for computer vision, machine learning, and image processing and stuff like that. It also support other programming languages like C++, java with some changes in syntax. It have pre-build code and functions to process images and videos to figure out objects, faces and many other image related things that are difficuilt to do other wise like hand writing recognition.
It is integrated with other libraries like numpy(library for numerical calculations) to make our program efficient and optimized.
Palm lines detection can be done using few lines of code in python. But understanding the working is bit complex as it requires to have the knowledge of open-cv methods.
doubt - difference between methods and functions, its simple, function in classes(oops) are referred as methods.
Open-cv Methods used in Palm lines detection
first step is to install open-cv module using pip(on windows) before using it. And them importing it on current working python file.
# type this command on terminal to install open-cv - pip install opencv-python # then create a python file a import open-cv import cv2
cv2.imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix.
cv2.imshow() method is used to display an image in a window. The window automatically fits to the image size.
But if you simply write cv2.imshow() you will see nothing on your screen. To see the image you need to ask it to wait waitKey() method
waitkey() method of Python OpenCV allows users to display a window for given milliseconds or until any key is pressed
Now we need to convert this colorful image to black and white. So using cv2.cvtColor() method we can achieve that.
Errors that occur while creating a open cv project – Errors while Creating open cv – Python Project
cv2.cvtColor() method is used to convert an image from one color space to another. There are more than 150 color-space conversion methods available in OpenCV.
Gray scale is one such conversion which convert image to black and white.
After using cvtColor() method you can see converted image imshow() method and stop it using waitKey().
Canny() Function in OpenCV is used to detect the edges in an image.
advanced parameters (beginnners may ignore) Syntax: cv2.Canny(image, T_lower, T_upper, aperture_size, L2Gradient) Where: Image: Input image to which Canny filter will be applied T_lower: Lower threshold value in Hysteresis Thresholding T_upper: Upper threshold value in Hysteresis Thresholding aperture_size: Aperture size of the Sobel filter. L2Gradient: Boolean parameter used for more precision in calculating Edge Gradient.
it inverted the value of array element. If you know that images is array of numbers 0 – black and 1 or 255 for white. So this function reverse the order. In simple words it convert white area to black.
cv2.imwrite() method is used to save an image to any storage device. Here we will save it in our relative path.
this method is used to add and blend images. in this case we will blend palmlines.jpg and palm.jpg which are stored on palmlines and image.
You can also use this technique in many other places like cartoonifying your image.
So these were 8 methods that you required to know for every open cv project. This was a very basic and easy one. I say you must try it once and play around it. BTW I’m not promoting any political party with this hand 🙂
I got inspiration of this project explanation from a instagram page python.hub You can go and follow them for python tips and tricks. I try to just explain and showcase their mini projects. If you want to share your projects or want to learn these concepts contact me @ firstname.lastname@example.org and comment down below.