Tuesday , March 19 2024

Computer Vision

Face Detection with Name in Python using OpenCV

15 Face Detection with Name Face Detection with Name in Python using OpenCV¶ python -m pip install opencv-contrib-python pip install pillow Step 1: Collect 20 Samples of a Face¶ In [11]: import cv2 cam = cv2.VideoCapture(0) detector=cv2.CascadeClassifier('haarcascade_frontalface_default.xml') Id=input('Enter Your Id:') sampleNum=0 while(True): ret, img = cam.read() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces …

Read More »

Face Detection From an Image in Python using OpenCV

13 Face Detection from Image Face Detection From an Image in Python using OpenCV¶ https://github.com/opencv/opencv/tree/master/data/haarcascades You need to download the trained classifier XML file (haarcascade_frontalface_default.xml), which is available in OpenCv’s GitHub repository. Save it to your working location. The detection works only on grayscale images. So it is important to …

Read More »

Record Video From a Webcam using OpenCV

12 Record Video using OpenCV Record Video From a Webcam using OpenCV¶ cv2.VideoWriter( filename, fourcc, fps, frameSize ) The parameters are : filename: Specifies the name of the output video file. fourcc: (for recording) Defining the codec fps: Defined frame rate of the output video stream frameSize: Size of the …

Read More »

Access Camera Using OpenCV with Python

11 Open Webcam Access Camera Using OpenCV with Python¶ first, we Import libraries OpenCV. Then we use VideoCapture(0) function to capture the feed of the webcam, here 0 indicates the default value of webcam. If you have secondary webcam use 1 instead of 0 Now read the frame of the …

Read More »

Arithmetic Operations on Images using OpenCV

10 Arithmetic Operations on Images using OpenCV Arithmetic Operations on Images using OpenCV¶Arithmetic Operations like Addition, Subtraction, and Bitwise Operations(AND, OR, NOT, XOR) can be applied to the input images Addition Subtraction Bitwise operations are used in image manipulation and used for extracting essential parts in the image. In this …

Read More »

Visualizing the Different Color Channels of an RGB Image in Python using OpenCV

9 Visualizing the different color channels of an RGB image. Visualizing the Different Color Channels of an RGB Image in Python using OpenCV¶ In [2]: import cv2 img = cv2.imread('ocv2.png',1) cv2.imshow('Machine Learning',img) cv2.waitKey(0) cv2.destroyAllWindows() In [3]: import cv2 img=cv2.imread("ocv2.png",1) B, G, R = cv2.split(img) print(B) print(G) print(R) [[255 255 255 ... 255 …

Read More »

Displaying text on Image in Python using OpenCV

8 Displaying Text on Image <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_HTML"></script> <!-- MathJax configuration --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true, processEnvironments: true }, // Center justify equations in code and markdown cells. Elsewhere // we use CSS to left justify single line …

Read More »

Drawing a Rectangle on Image in Python using OpenCV

7 Drawing a Rectangle Drawing a Rectangle on Image in Python using OpenCV¶ In [2]: import cv2 img = cv2.imread('machinelearning.png',1) cv2.imshow('Machine Learning',img) cv2.waitKey(0) cv2.destroyAllWindows() Drawing a Rectangle¶rectangle() function take 5 Arguments Image Top-left corner co-ordinates Bottom-right corner co-ordinates Color (in BGR format) Line width In [3]: import cv2 img = cv2.imread('machinelearning.png',1) output …

Read More »

Rotate the Image in Python using OpenCV

6 Rotating the Image Rotate the Image in Python using OpenCV¶ In [2]: import cv2 img = cv2.imread('machinelearning.png',1) cv2.imshow('Machine Learning',img) cv2.waitKey(0) cv2.destroyAllWindows() Rotating the Image¶There are a lot of steps involved in rotating an image. The 2 main functions used here are – getRotationMatrix2D() warpAffine() getRotationMatrix2D() : It takes 3 arguments …

Read More »