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...
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...
The following code shows the accuracy level of the trained face and test face. If the value is small, then the accuracy is high. Packages to install : pip install openCV. pip install Face Recognition. pip install numpy. Images used : Trained Face Test Face Program : # Detecting accuracy level of the trained image and test image import cv2 import face_recognition import numpy as np # known image imgElon = face_recognition.load_image_file( "images/Elon Musk.jpg" ) # imgElon=cv2.imread("images/Elon Musk.jpg") imgElon = cv2.cvtColor(imgElon , cv2.COLOR_BGR2RGB) # Test image imgElonTest = face_recognition.load_image_file( "images/Elon Musk Test.jpg" ) # imgElon=cv2.imread("test images/Elon Musk Test.jpg") imgElonTest = cv2.cvtColor(imgElonTest , cv2.COLOR_BGR2RGB) # known image location & encodings faceLoc = ...