We just need to add a transparent layout function and replace the draw() function with transparent_layout() function. If you need the keyboard layout to be more customized, we can make the keyboard layout transparent. From that list, we find button position and button size and then we plot it on the frame according to a well-defined manner. Once we get the position then we loop through the entire position list. Here we can find the distance between the top point of our index finger and middle finger, if the distance between the two is less than a certain threshold, then we can type the letter on which we are indicating. Then in that image, we need to find the position and bounding box information of that detected hand. Then we pass that image to the detector.findHands() in order to find the hand in the frame. Inside the while loop the main function takes place, first we read the real-time input frames and store it in a variable called img. L, _, _ = detector.findDistance(8,12, img, draw=False) If x < lmList< lmList < y+h:Ĭv2.rectangle(img, button.pos, (x + w, y + h), Img = draw(img, buttonList) # change the draw funtion to transparent_layout for transparent keys LmList, bboxInfo = detector.findPosition(img) Main Program for Virtual Keyboard Using OpenCV Later we can pass this list to draw function to draw on top of our real-time frame. The above loop will loop through the keyboard keys and Button objects where we give position and text as inputs are appended in a list called button list. buttonList = įor x, key in enumerate(keyboard_keys):Ä«uttonList.append(Button(, key)) Then we define a class called Button() and we give position, text and size as the inputs so that we can arrange the keyboard keys in a well-defined order. class Button():Äef _init_(self, pos, text, size=): You can also try changing different colours. It will look something like the below images. It is in order to make our keyboard layout look better. Here Inside the draw() function, we are using cvzoneâs cornerRect function to draw rectangle edges at the corner of each keys. Initialize the keyboard controller, and define a function with name draw() and it takes two arguments that is an image and the buttonList and return the image. Defining Draw Function keyboard = Controller() def draw(img, buttonList):ĬrnerRect(img, (button.pos, button.pos,Ä«utton.size,button.size), 20 ,rt=0)Ĭv2.rectangle(img, button.pos, (int(x + w), int(y + h)), (255, 144, 30), cv2.FILLED)Ĭv2.putText(img, button.text, (x + 20, y + 65), Then we create an array of lists according to the layout of our keyboard and define an empty string to store the typed keys. We initialize HandDetector with detection confidence of 0.8 and assign it to the detector. Now letâs take real-time input from cv2.Videocapture detector = HandDetector(detectionCon=0.8) Here we are importing the HandDetector module from cvzone.HandTrackingModule and then in order to make the virtual keyboard work we need to import Controller from pynput.keyboard. Now letâs import the required modules import cv2įrom cvzone.HandTrackingModule import HandDetector > pip install pynput Import Libraries for Virtual Keyboard Using OpenCV Implementation of Virtual Keyboard Using OpenCVįirst, let us install the required modules. using which real-time computer vision applications are developed.ĬVzone is a computer vision package, where it uses OpenCV and Media Pipe libraries as its core that makes us easy to run like hand tracking, face detection, facial landmark detection, pose estimation, etc., and also image processing and other computer vision-related applications. OpenCV is the most popular library for the task of computer vision, it is a cross-platform open-source library for machine learning, image processing, etc. This article was published as a part of the Data Science Blogathon Introduction
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |