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 = test = cv2.getTrackbarPos("test", "frame") font = cv2.FONT_HERSHEY_COMPLEX cv2.putText(frame, str(test), (50, 150), font, 4, (0, 0, 255)) s = cv2.getTrackbarPos("color/gray", "frame") if s == […]

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) cv2.imshow("bit_not2", bit_not2) cv2.waitKey(0) cv2.destroyAllWindows() [/python]   Files: drawing_1.png drawing_2.png

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) cv2.imshow("img2", img2) cv2.imshow("road background", road) cv2.imshow("car no background", car) cv2.imshow("mask", […]

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 together.The function cv2.add (see line below) that adds rispectively the […]

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 the frames from the webcam: cap = cv2.VideoCapture(0) The number […]

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) if the image is in the same folder as the […]

Tutorial: Remove background – opencv 3.2 with python 3

In this tutorial, we will see how to delete the background using only OpenCV and python. In this case, I will identify the color through HSV, and for more details I suggest you see my most recent article on the subject: Detecting colors (Hsv Color Space) – Opencv with Python or use other techniques, always […]