OpenCV is an open-source programming library/package that has been created especially for allowing programmers to work with the world of Computer Vision. The OpenCV package was primarily developed by Intel Corporation. OpenCV stands for Open-Source Computer Vision (Library). Firstly import cv2. It is a cross-platform library using which we can develop real-time computer vision applications. The main focus, but not limited to, is on image processing, video capture, and analysis including features like face detection and object detection.
To begin with, for loading an image into our system RAM (Random Access Memory), we can use the imread()
method provided by OpenCV, as shown below.
import cv2
image =cv2.imread("location_of_image")
cv2.imshow('InterviewBit Computer Vision', image)
cv2.waitkey(“1”) # This displays the image indefinitely till you cut the window or press any key
You can read the image with the cv2.imread( ) function and the functioncv2. The imshow() function is used to display the current image on the screen (in google colab this will be cv2_imshow imported from google.colab.patches).
cv2.VideoCapture(0)
function captures video from the computer’s camera. The parameter 0 here is for accessing the camera connected to your computer.
ret, frame = capture.read()
is used in order to see the images we captured in the video. Because videos consist of frames here we will read the captured image and then return that image.
(B, G, R) = image[h,w] # here we are extracting the RGB values of a pixel at h,w for height and width.
resized_image = cv2.resize(image, (1000, 200))
using this function we can resize the dimensions of an image here as we are resizing here to new dimensions.
We can also rotate an image after generating a 2dmatrix. getRotationMatrix2D()
function returns a 2*3 matrix and warpAffline() calculates new x, y coordinates of the image and transforms it. You can try out these functions, along with multiple others, and see how it affects the image.