Skip to content

Instantly share code, notes, and snippets.

View Yuktha-Majella's full-sized avatar

Yuktha-Majella

View GitHub Profile
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('C:\\Users\\Admin\\Downloads\\thresholding\\landscape.jpg',0)
#Global thresholding
ret1,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
#Otsu's thresholding
import cv2
import numpy as np
img = cv.imread('C:\\Users\\Admin\\Downloads\\thresholding\\annefrank_diary.jpg',0)
#Simple Thresholding
ret,thresh1 = cv.threshold(img,127,255,cv2.THRESH_BINARY)
#Different types of Adaptive Thresholding
thresh2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2)
import cv2
import numpy as np
#import image as Gray-scale
img = cv.imread('C:\\Users\\Admin\\Downloads\\thresholding\\gradient.jpg',0)
#Different types of Simple Threshold
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
import cv2
flags = [i for i in dir(cv2) if i.startswith('COLOR_')]
print(flags)
blue = np.uint8([[[255,0,0]]])
hsv_blue = cv2.cvtColor(blue,cv2.COLOR_BGR2HSV)
print("HSV value of Blue: ", hsv_blue)
import numpy as np
capture = cv2.VideoCapture(0)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 300)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 300)
while(1):
# Take each frame
_, frame = capture.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
import numpy as np
bgr = cv2.imread('C:\\Users\\Admin\\Downloads\\color space\\pebbles.jpg')
#Conversion BGR -> Grayscale
gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)
#Conversion BGR -> HSV
hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
cv2.imshow('BGR', bgr)
cv2.imshow('Grayscale', gray)
#Making Borders
import cv2
import numpy as np
BLUE = [255,0,0]
img = cv2.imread('C:\\Users\\Admin\\Downloads\\operations on images\\olympic_logo.png')
replicate = cv2.copyMakeBorder(img,10,10,10,10,cv2.BORDER_REPLICATE)
reflect = cv2.copyMakeBorder(img,10,10,10,10,cv2.BORDER_REFLECT)
reflect101 = cv2.copyMakeBorder(img,10,10,10,10,cv2.BORDER_REFLECT_101)
#Setting all values of Green channel in image to 0
img[:,:,1] = 0
#Merging Blue, Green and Red channels
imgmerge = cv2.merge((b,g,r))