Skip to main content

Posts

How Far You Are From Your Camera? Python | OpenCv

Hello Friends! In this blog, you will learn to find out the distance between you and your webcam. Take a look at the video below.  Let's get started. For this project, we will be using face detection using the Haar Cascade method. Therefore, we need to download the cascade classifier for face detection from Github. You can download and paste the file from this link . Let us first understand what is Haar Cascade?  Haar Cascade  is a machine learning object detection algorithm used to identify objects in an image or video and based on various​​ features.  If you want to read a more detailed version of it, check out this link . Now, we will start by importing the libraries and define a variable to capture video from my webcam. import cv2 import numpy as np cap = cv2.VideoCapture( 0 ) Let us import our classifier file which we downloaded from Github. face = cv2.CascadeClassifier( 'haarcascade_frontalface_alt.xml' ) write a while loop and capture the image frames. Also, w...

Make an object invisible using Python- OpenCV

In this blog, you will learn how to make an object disappear in a video in python using the OpenCV library.  Check out the demo below. So let's get started.  We will start by importing the required libraries  and define a variable to capture the video from my webcam. import cv2 import numpy as np cap = cv2.VideoCapture( 0 ) Now, start capturing the image frames from the camera and save the first frame in a variable called replace_image . But why we did this? Keep Reading. ret , frame = cap.read() frame = cv2.flip(frame , + 1 ) ##Mirror image frame replace_image = frame ##live image to replace with Let's write a while loop to capture the image frames continuously. while ( 1 ): ret , frame = cap.read() ##Read image frame frame = cv2.flip(frame , + 1 ) ##Mirror image frame if not ret: ##If frame is not read then exit break if cv2.waitKey( 1 ) == ord ( 's' ): ##While loo...

Pattern Matching in Python- OpenCV

Hello guys. Today we will learn a pattern matching algorithm in python using the OpenCV library. Check out the video below to get a gist of what we are going to build. I have black and white grid patterns with white as background and black foreground. As usual, we will start by first importing the required libraries and define a variable to capture the video from my webcam. import cv2 import numpy as np cap = cv2.VideoCapture( 0 ) Now, we write a while loop and capture the image frames. Also, we need to mirror the frames so that we can see it right. while 1 : ret , frame = cap.read() ##Read image frame frame = cv2.flip(frame , + 1 ) ##Mirror image frame if not ret: ##If frame is not read then exit break if cv2.waitKey( 1 ) == ord ( 's' ): ##While loop exit condition break In the third part, we have to convert the image frames into a binary image. But why binary images?  You must ask. 1. ...

Object Distance calculation using Y axis coordinates in Python - OpenCV

Today we will discuss how you can find the distance of an object from the camera using python OpenCV. Check out the video below. Before we continue, you should know how to detect a colored object. Click this  link  to check out my previous blog on object detection and tracking. I hope after checking out my previous blog, you are able to write your own code to detect and track objects. We will take forward the Object detection and tracking code to find the distance of an object from the camera. So let's start. Let us first understand the principle using which we will find the distance of the object from the camera. Principle:- As the object moves farther away from the camera, the Y-axis coordinate decreases. This simply means that, if your object is near to the camera, the Y-axis coordinate will be very large. As you move the object farther from the camera, the object will appear to move above in the image and thus decreasing the Y-axis coordinates proportionately. Th...