In this post, we are going to see how to detect and track movements(simply motion detection and tracking) using the OpenCV module. At first, you need to install the OpenCV-python module, to install the module just open your command prompt and type, pip install OpenCV-python Then hit enter, it will install the module automatically. After installing the module, just import the module and write the basic code to read the video. # import the opencv module import cv2 # capturing video capture = cv2.VideoCapture( "videos/input.mp4" ) After that, we have to get the two frames from the video or webcam and find the difference between the two frames, which is nothing but if there is a movement that occurs between the frames there might be a difference. So, here we are trying to get the difference using the cv2.absdiff() function in the OpenCV module and this method takes two parameters which are the two frames. # find difference between two frames diff = cv2.absdiff(img_1 , img_2) T...
Basically, the hand tracking is based on the 21 landmarks in 3D with multi-hand support, based on high-performance palm detection and hand landmark model. The 21 hand landmarks will be like, And, The output will be like this, Packages to install : pip install opencv-python. pip install mediapipe. Program : # Hand Tracking with python import cv2 import mediapipe as mp import time # Capturing video from the web cam video = cv2.VideoCapture( 0 ) # Creating objects for hands mpHands = mp.solutions.hands hands = mpHands.Hands() previousTime = 0 currentTime = 0 while True : success , img = video.read() # Converting BGR image to RGB image RGBimg = cv2.cvtColor(img , cv2.COLOR_BGR2RGB) # Getting landmark points and storing in multiHandLandmarks variable result = hands.process(RGBimg) multiHandLandmarks = result.multi_hand_landmarks # This 'if' block will run when it's having the handlandmark points if multiHandLandmarks...
In this post, we are going to see how the colors are detected by the OpenCV module. The first step to get into this is just install the modules as I mentioned below and import the modules, then read the input image and convert the BGR (Blue, Green, Red) image to HSV (Hue, Saturation, Variance) image then find the lower and higher HSV value of the color which you want to detect from the HSV color map (Shown below), Then, we have to generate the mask of the color which we chose. So, we will use the cv2.inRange() function to generate the mask. Just pass the input image, lower HSV value higher HSV Value. This will generate a masked image of the input image and assign the masked image to the variable (mask). To detect the color we have to use the cv2.bitwise_and() function and pass the input image as the first and second argument and the third argument will be the mask and store this in the variable (detected_image). detected_image will be the final output of our progra...