Skip to content

Instantly share code, notes, and snippets.

View siddhant-swaroop-dash's full-sized avatar

siddhant-swaroop-dash

View GitHub Profile
# get shape of arrow image
rows,cols,channel = img2.shape
# region of image of logo image with same dimensions as arrow image
roi = img3[0:rows,0:cols]
# converting arrow image to grayscale and thresholding
img2gray = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
_ , mask = cv2.threshold(img2gray,200,255,cv2.THRESH_BINARY)
cv2.imshow('not',cv2.bitwise_not(img1)) # not
cv2.imshow('and',cv2.bitwise_and(img1,img2)) # and
cv2.imshow('or',cv2.bitwise_or(img1,img2)) # or
cv2.imshow('xor',cv2.bitwise_xor(img1,img2)) # xor
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow('wadd',cv2.addWeighted(img1,0.6,img2,0.4,0))
cv2.waitKey(0)
cv2.destroyAllWindows()
# mathematical operators
cv2.imshow('+',img1+img2)
cv2.imshow('-',img1-img2)
cv2.imshow('*',img1*img2)
# cv2 functions
cv2.imshow('add',cv2.add(img1,img2))
cv2.imshow('sub',cv2.subtract(img1,img2))
cv2.imshow('mul',cv2.multiply(img1,img2))
cv2.imshow('+100',cv2.add(img1,100)) # add 100
cv2.imshow('-100',cv2.subtract(img1,100)) # subtract 100
cv2.imshow('*5',cv2.multiply(img1,5)) # multiply 5
cv2.waitKey(0)
cv2.destroyAllWindows()
@siddhant-swaroop-dash
siddhant-swaroop-dash / read images
Created October 11, 2020 06:15
cv for beginners part 2
img1 = cv2.imread('c:/Users/siddhant.dash/Downloads/left.jpg')
img2 = cv2.imread('c:/Users/siddhant.dash/Downloads/up.jpg')
img3 = cv2.imread('c:/Users/siddhant.dash/Downloads/among_us.png')
@siddhant-swaroop-dash
siddhant-swaroop-dash / operations with scalar to image
Created October 11, 2020 06:07
image operations with scalars
cv2.imshow('+150',img1+150)
cv2.imshow('-250',img1-250)
cv2.imshow('x10',img1*10)
cv2.waitKey(0)
cv2.destroyAllWindows()
@siddhant-swaroop-dash
siddhant-swaroop-dash / thresholding
Created September 28, 2020 02:49
Medium Blog : Computer Vision for Beginners (part 1) : import libs
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow('gray',gray)
val1,th1 = cv2.threshold(gray,125,255,cv2.THRESH_BINARY)
cv2.imshow('t1',th1)
val2,th2 = cv2.threshold(gray,125,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imshow('t2',th2)
th3 = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,155,1)
@siddhant-swaroop-dash
siddhant-swaroop-dash / writing\drawing
Created September 28, 2020 02:09
Medium Blog : Computer Vision for Beginners (part 1) : Writing on image
# Write Text on Image
img1 = cv2.putText(img.copy(),'Klaus',(30,150),cv2.FONT_HERSHEY_SIMPLEX,1,(200,100,0),2,cv2.LINE_AA)
cv2.imshow('1',img1)
# Draw Rectangle on Image
img2 = cv2.rectangle(img.copy(),(60,0),(150,120),(0,0,255),2)
cv2.imshow('2',img2)
# Draw Circle on Image
img3 = cv2.circle(img.copy(),(80,80),30,(0,255,255),2)
@siddhant-swaroop-dash
siddhant-swaroop-dash / Image Slicing
Created September 27, 2020 15:58
Medium Blog : Computer Vision for Beginners (part 1) : Image Slicing
cv2.imshow('Cropped',img[0:120,60:150])
cv2.waitKey(0)
cv2.destroyAllWindows()