Automating Scrolling using Python-Opencv by Color Detection
It is possible to perform actions without actually giving any input through touchpad or mouse. This article discusses how this can be done using opencv module. Here we will use color detection to scroll screen. When a certain color is detected by the program during execution the screen starts to scroll on its own.
- Import module
- Use cv2 to capture video, here to use default webcam use 0, and for any other cam use 1.
- Read the captured video and store the video frame in a variable
- Get every color of the frame.
- Create a mask of the color required to take as input to scroll using their acceptable color ranges. Here it is taken as green.
- Get contours and hierarchy from mask
- Pass contours using for loop and calculate the area.
- Add scroll mechanism when required color is detected(Green here).
- Show the frame using cv2.imshow()and pass the frame name and the frame variable to show every captured frame, put the frame capture process in a while loop. To come out of the process use a wait key and break statement.
- Then stop the window of webcam.
Below is the implementation.