├── blending.py ├── blurring.py ├── gradient.py ├── histogram.py ├── homework ├── OpenCV ile Görüntü İşleme Ödevi.py ├── cevaplar.py └── odev1.jpg ├── image thresholding.py ├── imgs ├── MOT17-04-DPM.mp4 ├── NYC.jpg ├── goldenGate.jpg ├── hist_equ.jpg ├── img1.JPG ├── img2.JPG ├── j.png ├── kart.png ├── lenna.png ├── red_blue.jpg └── sudoku.jpg ├── joinImage.py ├── morphology.py ├── openImage.py ├── shapeText.py ├── videoPlay.py └── warp perspective.py /blending.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/imgs/" 6 | 7 | img1=cv2.imread(path+"img1.jpg") 8 | img1=cv2.cvtColor(img1,cv2.COLOR_BGR2RGB) 9 | img2=cv2.imread(path+"img2.jpg") 10 | img2=cv2.cvtColor(img2,cv2.COLOR_BGR2RGB) 11 | 12 | img1=cv2.resize(img1,(600,600)) 13 | img2=cv2.resize(img2,(600,600)) 14 | 15 | print(img1.shape,img2.shape) 16 | 17 | #blending = a*img1+b*img2 18 | blend=cv2.addWeighted(src1=img1,alpha=0.3,src2=img2,beta=0.7,gamma=0) 19 | 20 | plt.figure() 21 | plt.imshow(img1) 22 | 23 | plt.figure() 24 | plt.imshow(img2) 25 | 26 | plt.figure() 27 | plt.imshow(blend) 28 | 29 | plt.show() 30 | 31 | -------------------------------------------------------------------------------- /blurring.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import warnings 5 | warnings.filterwarnings('ignore') 6 | 7 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/imgs/" 8 | 9 | 10 | #blurring detayı azalt, gürültüyü engeller 11 | img=cv2.imread(path+'NYC.jpg') 12 | img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB) 13 | #plt.imshow(img), plt.axis('off'), plt.title('Original') 14 | 15 | #mean blurring 16 | dst2=cv2.blur(img,(3,3)) 17 | #plt.figure(),plt.imshow(dst2),plt.axis('off'),plt.title('Mean Blurring') 18 | 19 | #Gaussian blurring 20 | gb=cv2.GaussianBlur(img,(3,3),7) 21 | #plt.figure(),plt.imshow(gb),plt.axis('off'),plt.title('Gauissian Blurring') 22 | 23 | #Median blurring 24 | mb=cv2.medianBlur(img,3) 25 | #plt.figure(),plt.imshow(mb),plt.axis('off'),plt.title('Median Blurring') 26 | 27 | #%% 28 | def gausNoise(image): 29 | row, col, ch=image.shape 30 | mean=0 31 | var=0.05 32 | sigma=var**0.5 33 | 34 | gauss=np.random.normal(mean,sigma,(row,col,ch)) 35 | gauss=gauss.reshape(row,col,ch) 36 | noisy=image+gauss 37 | 38 | return noisy 39 | 40 | #Normalization 41 | img=cv2.imread(path+'NYC.jpg') 42 | img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)/255 43 | plt.imshow(img), plt.axis('off'), plt.title('Original') 44 | 45 | plt.figure() 46 | noisyImage=gausNoise(img) 47 | plt.imshow(noisyImage), plt.axis('off'), plt.title('Noisy Image') 48 | 49 | #Blurring with noisy image 50 | gb2=cv2.GaussianBlur(noisyImage,(3,3),7) 51 | plt.figure(),plt.imshow(gb2),plt.axis('off'),plt.title('with Gauissian Blurring') 52 | 53 | #%% 54 | #salt pepper noise 55 | 56 | def saltPepperNoise(img): 57 | row, col, ch=img.shape 58 | s_vs_p=0.5 59 | amount=0.004 60 | noisy=np.copy(img) 61 | 62 | num_salt=np.ceil(amount*img.size*s_vs_p) 63 | coords=[np.random.randint(0,i-1, int(num_salt)) for i in img.shape] 64 | noisy[coords]=1 65 | 66 | num_pepper=np.ceil(amount*img.size*s_vs_p) 67 | coords=[np.random.randint(0,i-1, int(num_pepper)) for i in img.shape] 68 | noisy[coords]=0 69 | 70 | return noisy 71 | 72 | spImage=saltPepperNoise(img) 73 | 74 | plt.figure() 75 | plt.imshow(spImage), plt.axis('off'), plt.title('saltPapper Image') 76 | 77 | #Median blurring 78 | mb2=cv2.medianBlur(spImage.astype('float32'),3) 79 | plt.figure(),plt.imshow(mb2),plt.axis('off'),plt.title('with Median Blurring') 80 | 81 | 82 | plt.show() 83 | 84 | -------------------------------------------------------------------------------- /gradient.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | import matplotlib.pyplot as plt 4 | 5 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/imgs/" 6 | img=cv2.imread(path+'sudoku.jpg',0) 7 | 8 | plt.imshow(img,cmap='gray'), plt.axis('off'),plt.title('Original Image') 9 | 10 | #x gradyan 11 | sobelX=cv2.Sobel(img,ddepth=cv2.CV_16S,dx=1,dy=0,ksize=5) 12 | plt.figure(),plt.imshow(sobelX,cmap='gray'), plt.axis('off'),plt.title('SobelX Image') 13 | 14 | #y gradyna 15 | sobelY=cv2.Sobel(img,ddepth=cv2.CV_16S,dx=0,dy=1,ksize=5) 16 | plt.figure(),plt.imshow(sobelY,cmap='gray'), plt.axis('off'),plt.title('SobelY Image') 17 | 18 | #laplacian gradyan 19 | laplacian=cv2.Laplacian(img,ddepth=cv2.CV_16S) 20 | plt.figure(),plt.imshow(laplacian,cmap='gray'), plt.axis('off'),plt.title('Laplacian Image') 21 | 22 | plt.show() -------------------------------------------------------------------------------- /histogram.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | import matplotlib.pyplot as plt 4 | 5 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/imgs/" 6 | 7 | img1=cv2.imread(path+"red_blue.jpg") 8 | img1=cv2.cvtColor(img1,cv2.COLOR_BGR2RGB) 9 | plt.imshow(img1),plt.axis('off'),plt.title('Red Blue') 10 | 11 | print(img1.shape) 12 | img1_hist=cv2.calcHist([img1],channels=[0],mask=None,histSize=[256],ranges=[0,256]) 13 | print(img1_hist.shape) 14 | plt.figure(),plt.plot(img1_hist),plt.title('Red Blue Histogram') 15 | 16 | colors=("b","g","r") 17 | plt.figure() 18 | for i,c in enumerate(colors): 19 | hist=cv2.calcHist([img1],channels=[i],mask=None,histSize=[256],ranges=[0,256]) 20 | plt.plot(hist,color=c) 21 | 22 | #goldenGate Img 23 | goldenGateImg=cv2.imread(path+"goldenGate.jpg") 24 | goldenGateImg=cv2.cvtColor(goldenGateImg,cv2.COLOR_BGR2RGB) 25 | plt.figure(),plt.imshow(goldenGateImg) 26 | print(goldenGateImg.shape) 27 | 28 | mask=np.zeros(goldenGateImg.shape[:2],np.uint8) 29 | plt.figure(),plt.imshow(mask,cmap='gray') 30 | 31 | mask[1500:2000, 1000:2000]=255 32 | plt.figure(),plt.imshow(mask,cmap='gray') 33 | 34 | maskedImg=cv2.bitwise_and(goldenGateImg,goldenGateImg,mask=mask) 35 | plt.figure(),plt.imshow(maskedImg) 36 | 37 | goldeGateHist=cv2.calcHist([goldenGateImg],channels=[0],mask=mask,histSize=[256],ranges=[0,256]) 38 | plt.figure(),plt.plot(goldeGateHist),plt.title('Golden Gate Histogram') 39 | 40 | #Histogram Esitleme 41 | img=cv2.imread(path+'hist_equ.jpg',0) 42 | plt.figure(),plt.imshow(img,cmap='gray') 43 | 44 | img_hist=cv2.calcHist([img],channels=[0],mask=None,histSize=[256],ranges=[0,256]) 45 | plt.figure(),plt.plot(img_hist) 46 | 47 | eq_hist=cv2.equalizeHist(img) 48 | plt.figure(),plt.imshow(eq_hist,cmap='gray') 49 | 50 | eq_hist=cv2.calcHist([eq_hist],channels=[0],mask=None,histSize=[256],ranges=[0,256]) 51 | plt.figure(),plt.plot(eq_hist) 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | plt.show() -------------------------------------------------------------------------------- /homework/OpenCV ile Görüntü İşleme Ödevi.py: -------------------------------------------------------------------------------- 1 | # opencv kütüphanesini içe aktaralım 2 | # ... 3 | 4 | # matplotlib kütüphanesini içe aktaralım 5 | # ... 6 | 7 | # resmi siyah beyaz olarak içe aktaralım 8 | # ... 9 | 10 | # resmi çizdirelim 11 | # ... 12 | 13 | # resmin boyutuna bakalım 14 | # ... 15 | 16 | # resmi 4/5 oranında yeniden boyutlandıralım ve resmi çizdirelim 17 | # ... 18 | # ... 19 | 20 | # orijinal resme bir yazı ekleyelim mesela "kopek" ve resmi çizdirelim 21 | # ... 22 | # ... 23 | 24 | # orijinal resmin 50 threshold değeri üzerindekileri beyaz yap altındakileri siyah yapalım, 25 | # binary threshold yöntemi kullanalım ve resmi çizdirelim 26 | # ... 27 | # ... 28 | 29 | # orijinal resme gaussian bulanıklaştırma uygulayalım ve resmi çizdirelim 30 | # ... 31 | # ... 32 | 33 | # orijinal resme Laplacian gradyan uygulayalım ve resmi çizdirelim 34 | # ... 35 | # ... 36 | 37 | # orijinal resmin histogramını çizdirelim 38 | # ... 39 | # ... 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /homework/cevaplar.py: -------------------------------------------------------------------------------- 1 | # opencv kütüphanesini içe aktaralım 2 | import cv2 3 | import matplotlib.pyplot as plt 4 | import numpy as np 5 | 6 | # resmi siyah beyaz olarak içe aktaralım 7 | img=cv2.imread('odev1.jpg',0) 8 | 9 | # resmi çizdirelim 10 | plt.imshow(img,cmap='gray'),plt.axis('off'),plt.title('Homework Image') 11 | 12 | # resmin boyutuna bakalım 13 | print(img.shape)#560,860 14 | 15 | # resmi 4/5 oranında yeniden boyutlandıralım ve resmi çizdirelim 16 | resizedImg=cv2.resize(img,(int(568*0.8),int(860*0.8))) 17 | plt.figure(),plt.imshow(resizedImg,cmap='gray'),plt.axis('off'),plt.title('Resized Image') 18 | 19 | # orijinal resme bir yazı ekleyelim mesela "kopek" ve resmi çizdirelim 20 | cv2.putText(img,'Cat and dog image',(100,150),cv2.FONT_HERSHEY_COMPLEX,2,(0,255,0),2) 21 | plt.figure(),plt.imshow(img),plt.axis('off'),plt.title('Image with text') 22 | 23 | # orijinal resmin 50 threshold değeri üzerindekileri beyaz yap altındakileri siyah yapalım, 24 | # binary threshold yöntemi kullanalım ve resmi çizdirelim 25 | 26 | _,imgThresh=cv2.threshold(img,50,255,cv2.THRESH_BINARY) 27 | plt.figure(),plt.imshow(imgThresh,cmap='gray'),plt.axis('off'),plt.title('ThreshHold Image') 28 | 29 | 30 | # orijinal resme gaussian bulanıklaştırma uygulayalım ve resmi çizdirelim 31 | GaussianBluredImg=cv2.GaussianBlur(img,(5,5),0) 32 | plt.figure(),plt.imshow(GaussianBluredImg,cmap='gray'),plt.axis('off'),plt.title('Gaussian Blured Image') 33 | 34 | 35 | # orijinal resme Laplacian gradyan uygulayalım ve resmi çizdirelim 36 | laplacianGradImg=cv2.Laplacian(img,ddepth=cv2.CV_16S,ksize=3) 37 | plt.figure(),plt.imshow(laplacianGradImg,cmap='gray'),plt.axis('off'),plt.title('with laplacian Image') 38 | 39 | 40 | # orijinal resmin histogramını çizdirelim 41 | img1_hist=cv2.calcHist([img],channels=[0],mask=None,histSize=[256],ranges=[0,256]) 42 | print(img1_hist.shape) 43 | plt.figure(),plt.plot(img1_hist),plt.title('Histogram') 44 | 45 | 46 | 47 | plt.show() 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /homework/odev1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/homework/odev1.jpg -------------------------------------------------------------------------------- /image thresholding.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | import matplotlib.pyplot as plt 4 | 5 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/imgs/" 6 | 7 | img=cv2.imread(path+'img1.jpg') 8 | img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 9 | 10 | #threshold 11 | _, thresh_image=cv2.threshold(img,thresh=60,maxval=255,type=cv2.THRESH_BINARY) 12 | 13 | #adaptive threshold 14 | thresh_image2=cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,8) 15 | 16 | 17 | #cv2.imshow('img1',img) 18 | plt.imshow(img,cmap='gray') 19 | plt.axis('off') 20 | 21 | plt.figure() 22 | plt.imshow(thresh_image,cmap='gray') 23 | plt.axis('off') 24 | 25 | plt.figure() 26 | plt.imshow(thresh_image2,cmap='gray') 27 | plt.axis('off') 28 | 29 | plt.show() 30 | 31 | 32 | -------------------------------------------------------------------------------- /imgs/MOT17-04-DPM.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/MOT17-04-DPM.mp4 -------------------------------------------------------------------------------- /imgs/NYC.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/NYC.jpg -------------------------------------------------------------------------------- /imgs/goldenGate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/goldenGate.jpg -------------------------------------------------------------------------------- /imgs/hist_equ.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/hist_equ.jpg -------------------------------------------------------------------------------- /imgs/img1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/img1.JPG -------------------------------------------------------------------------------- /imgs/img2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/img2.JPG -------------------------------------------------------------------------------- /imgs/j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/j.png -------------------------------------------------------------------------------- /imgs/kart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/kart.png -------------------------------------------------------------------------------- /imgs/lenna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/lenna.png -------------------------------------------------------------------------------- /imgs/red_blue.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/red_blue.jpg -------------------------------------------------------------------------------- /imgs/sudoku.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mftnakrsu/ImageProcessing-with-openCV/8c7d0fdf9b8c61a9afc21f297d4284933d5796c6/imgs/sudoku.jpg -------------------------------------------------------------------------------- /joinImage.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | 5 | 6 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/lenna.png" 7 | img=cv2.imread(path) 8 | 9 | #horizontal 10 | hor=np.hstack((img,img)) 11 | cv2.imshow('horizontal',hor) 12 | 13 | #vertical 14 | ver=np.vstack((img,img)) 15 | cv2.imshow('vertical',ver) 16 | 17 | cv2.imshow('img',img) 18 | 19 | cv2.waitKey(0) 20 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /morphology.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | 5 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/imgs/" 6 | img=cv2.imread(path+"j.png",0) 7 | 8 | #original image 9 | plt.imshow(img,cmap='gray'),plt.axis('off'),plt.title('Original Image'), 10 | 11 | #ERODE 12 | kernel=np.ones((5,5),dtype=np.uint8) 13 | resultImg=cv2.erode(img,kernel,iterations=1) 14 | plt.figure(),plt.imshow(resultImg,cmap='gray'),plt.axis('off'),plt.title('ERODE Image'), 15 | 16 | #DILATION 17 | resultImg2=cv2.dilate(img,kernel,iterations=1) 18 | plt.figure(),plt.imshow(resultImg2,cmap='gray'),plt.axis('off'),plt.title('DILATION Image'), 19 | 20 | #white noise 21 | whiteNoise=np.random.randint(0,2,size=img.shape[:2]) 22 | whiteNoise=whiteNoise*255 23 | plt.figure(),plt.imshow(whiteNoise, cmap='gray'),plt.axis('off'),plt.title('Noises for Morphology') 24 | 25 | noisy_img=whiteNoise+img 26 | plt.figure(),plt.imshow(noisy_img, cmap='gray'),plt.axis('off'),plt.title('Noisey Image') 27 | 28 | #morphologyEx(beyzları azalt erode, sonra dilation uygula) 29 | openedImg=cv2.morphologyEx(img.astype(np.float32),cv2.MORPH_OPEN,kernel) 30 | plt.figure(),plt.imshow(openedImg, cmap='gray'),plt.axis('off'),plt.title('Opened Image') 31 | 32 | #black noise for morphClose 33 | blackNoise=np.random.randint(0,2,size=img.shape[:2]) 34 | blackNoise=whiteNoise*-255 35 | plt.figure(),plt.imshow(blackNoise, cmap='gray'),plt.axis('off'),plt.title('black noise for Morphology') 36 | 37 | noisy_img2=blackNoise+img 38 | noisy_img2[noisy_img2 <= -245] =0 39 | plt.figure(),plt.imshow(noisy_img2, cmap='gray'),plt.axis('off'),plt.title('Black Noisy Image') 40 | 41 | closedImg=cv2.morphologyEx(img.astype(np.float32),cv2.MORPH_CLOSE,kernel) 42 | plt.figure(),plt.imshow(closedImg, cmap='gray'),plt.axis('off'),plt.title('Black Noisy Image after Closed morph') 43 | 44 | #gradient # basic edge detection 45 | gradient=cv2.morphologyEx(img, cv2.MORPH_GRADIENT,kernel) 46 | plt.figure(),plt.imshow(gradient, cmap='gray'),plt.axis('off'),plt.title('Gradian Image') 47 | 48 | 49 | 50 | plt.show() -------------------------------------------------------------------------------- /openImage.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cap=cv2.VideoCapture(0) 4 | 5 | width=int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) 6 | heigth=int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 7 | 8 | print(width,heigth) 9 | 10 | 11 | 12 | while cap.isOpened(): 13 | 14 | _,frame=cap.read() 15 | 16 | cv2.imshow('vid',frame) 17 | 18 | if cv2.waitKey(1) & 0xFF == ord('q'):break 19 | 20 | cap.release() 21 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /shapeText.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | #create black image 5 | img= np.zeros((512,512,3),np.uint8) 6 | print(img.shape) 7 | 8 | cv2.imshow('Black Image',img) 9 | 10 | #line 11 | #(img,sp,fp,colour,thickness) 12 | cv2.line(img,(0,0),(512,512),(0,255,0),3)#opencv bgr 13 | cv2.imshow('Green Image',img) 14 | 15 | #rectangle 16 | cv2.rectangle(img,(0,0),(256,139),(255,0,0),-1)#cv2.FILLED 17 | cv2.imshow('Rectangle Image',img) 18 | 19 | #circle 20 | cv2.circle(img,(250,300),65,(0,0,255),-5) 21 | cv2.imshow('Cırcle Image',img) 22 | 23 | #text 24 | cv2.putText(img,"Imagetext",(150,359),cv2.FONT_HERSHEY_COMPLEX,2,(255,255,200),2) 25 | cv2.imshow('Text Image',img) 26 | 27 | 28 | cv2.waitKey(0) 29 | cv2.destroyAllWindows() 30 | -------------------------------------------------------------------------------- /videoPlay.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import time 3 | 4 | #MOT17-04-DPM 5 | 6 | name="MOT17-04-DPM.mp4" 7 | 8 | cap=cv2.VideoCapture(name) 9 | 10 | print("genislik:",cap.get(3)) 11 | print("yukseklik:",cap.get(4)) 12 | 13 | 14 | while cap.isOpened(): 15 | _,frame=cap.read() 16 | #time.sleep(0.01) 17 | cv2.imshow('video',frame) 18 | 19 | 20 | if cv2.waitKey(1) & 0xFF==ord('q'): 21 | break 22 | 23 | cap.release() 24 | cv2.destroyAllWindows() 25 | 26 | -------------------------------------------------------------------------------- /warp perspective.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | path="C:/Users/Asus/Desktop/imageProcessingOpenCV/kart.png" 5 | 6 | img=cv2.imread(path) 7 | cv2.imshow("Image perspective with OpenCV",img) 8 | 9 | width=400 10 | height=500 11 | 12 | pts1=np.float32([[230,1],[1,472],[540,150],[338,617]])#take coordinates paint 13 | pts2=np.float32([[0,0],[0,height],[width,0],[width,height]]) 14 | 15 | matrix=cv2.getPerspectiveTransform(pts1,pts2) 16 | print(matrix) 17 | 18 | imgOut=cv2.warpPerspective(img,matrix,(width,height)) 19 | cv2.imshow("Final Image", imgOut) 20 | 21 | 22 | 23 | cv2.waitKey(0) 24 | cv2.destroyAllWindows() --------------------------------------------------------------------------------