Basic geometric transformations – OpenCV 3.4 with python 3 Tutorial 12
[python] import cv2 import numpy as np img = cv2.imread("red_panda.jpg") rows, cols, ch = img.shape print("Height: ", rows) print("Width: ", cols) scaled_img = cv2.resize(img, None, fx=1/2, fy=1/2) matrix_t = np.float32([[1, 0, -100], [0, 1, -30]]) translated_img = cv2.warpAffine(img, matrix_t, (cols, rows)) matrix_r = cv2.getRotationMatrix2D((cols/2, rows/2),…
Histograms – OpenCV 3.4 with python 3 Tutorial 11
Source code: [python] import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread("sea_beach.jpg") b, g, r = cv2.split(img) cv2.imshow("img", img) cv2.imshow("b", b) cv2.imshow("g", g) cv2.imshow("r", r) plt.hist(b.ravel(), 256, [0, 256]) plt.hist(g.ravel(), 256, [0, 256]) plt.hist(r.ravel(), 256, [0, 256]) plt.show() [/python]…
Basic Thresholding – OpenCV 3.4 with python 3 Tutorial 10
Threshold: [python] import cv2 import numpy as np img = cv2.imread("black_to_white.jpeg", cv2.IMREAD_GRAYSCALE) _, threshold_binary = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY) _, threshold_binary_inv = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY_INV) _, threshold_trunc = cv2.threshold(img, 128, 255, cv2.THRESH_TRUNC) _, threshold_to_zero = cv2.threshold(img, 12, 255, cv2.THRESH_TOZERO) cv2.imshow("Image", img) cv2.imshow("th binary", threshold_binary)…
Object detection using HSV Color space – OpenCV 3.4 with python 3 Tutorial 9
What we will learn in this tutorial: What is HSV How to object recognition by color works What is HSV HSV (Hue Saturation Value) is a color format that describes colors in terms of their shade (saturation) and brightness (value). How to object recognition by…
Trackbars – OpenCV 3.4 with python 3 Tutorial 8
Source code: [python] import cv2 import numpy as np def nothing(x): pass cap = cv2.VideoCapture(0) cv2.namedWindow("frame") cv2.createTrackbar("test", "frame", 50, 500, nothing) cv2.createTrackbar("color/gray", "frame", 0, 1, nothing) while True: _, frame = cap.read() test = cv2.getTrackbarPos("test", "frame") font = cv2.FONT_HERSHEY_COMPLEX cv2.putText(frame, str(test), (50, 150), font, 4,…
Bitwise Operators – OpenCV 3.4 with python 3 Tutorial 7
Source code: [python] import cv2 import numpy as np img1 = cv2.imread("drawing_1.png") img2 = cv2.imread("drawing_2.png") bit_and = cv2.bitwise_and(img2, img1) bit_or = cv2.bitwise_or(img2, img1) bit_xor = cv2.bitwise_xor(img1, img2) bit_not = cv2.bitwise_not(img1) bit_not2 = cv2.bitwise_not(img2) cv2.imshow("img1", img1) cv2.imshow("img2", img2) cv2.imshow("bit_and", bit_and) cv2.imshow("bit_or", bit_or) cv2.imshow("bit_xor", bit_xor) cv2.imshow("bit_not", bit_not)…
Blending images – OpenCV 3.4 with python 3 Tutorial 6
Source code: [python] import cv2 import numpy as np img1 = cv2.imread("road.jpg") img2 = cv2.imread("car.jpg") img2_gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) ret, mask = cv2.threshold(img2_gray, 240, 255, cv2.THRESH_BINARY) mask_inv = cv2.bitwise_not(mask) road = cv2.bitwise_and(img1, img1, mask=mask) car = cv2.bitwise_and(img2, img2, mask=mask_inv) result = cv2.add(road, car) cv2.imshow("img1", img1)…
Add images and Threshold – OpenCV 3.4 with python 3 Tutorial 5
We’re going to learn in this tutorial how to add two images using Python and Opencv. First let’s take two images. There is one condition, the images need to have the exact same size. Add images There are two different functions to add the images…
Basic operations on images – OpenCV 3.4 with python 3 Tutorial 4
We’re going to see in this tutorial a few basic operations with the images using Opencv with Python. Watching the video we will understand: How the computer sees the image. How to select a specific area of the image (ROI) How to print or change…
Drawing and writing on images – OpenCV 3.4 with python 3 Tutorial 3
In this video we are going to learn how to draw and write on images. You can read below a really quick explanation of the code.Fore more details and a complete explanation of the entire code you can check the video and I will guide…
Loading Video and Webcam – OpenCV 3.4 with python 3 Tutorial 2
In this tutorial we’re going to see how to load the video from it’s source whether it’s a webcam or a video file. The process is relatively simple. After we import the libraries cv2 and numpy, we need to define the cap object. To load…
Loading images – OpenCV 3.4 with python 3 Tutorial 1
Show images Load and show images with Opencv is a really simple operation. On Line 1 we import the opencv library. On Line 3 we load the image into a variable. You can put just the title of the image and the format (example .jpg)…
Most Read:
-
Train YOLO to detect a custom object (online with free GPU)
-
YOLO object detection using Opencv with Python
-
Detecting colors (Hsv Color Space) – Opencv with Python
-
How to install Python 3 and Opencv 4 on Windows
-
Check if two images are equal with Opencv and Python
-
How to install Dlib for Python 3 on Windows
-
Feature detection (SIFT, SURF, ORB) – OpenCV 3.4 with python 3 Tutorial 25
-
Simple shape detection – Opencv with Python 3