Skip to content

Commit 67bc377

Browse files
committed
reconstruct the repo. and add some new code files
1 parent 2cc5400 commit 67bc377

26 files changed

+169
-17
lines changed

Readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<p align="center">
2+
<img src="test_images/opencv-logo.png" height=450 width=350>
3+
</p>
4+
15
# OpenCV Tutorials⭐:
26

37
## Follow Tutorial Files in Below Sequence⭐:
@@ -15,6 +19,9 @@
1519
* simple_thresholding_matplotlib_with_python.py
1620
* morphological_transformation_opencv_python.py
1721
* smoothing_images_and_blurring_images.py
22+
* image_gradients.py
23+
* canny_edge_detection.py
24+
* image_pyramids_opencv.py
1825

1926
## Helpful Documentations⭐:
2027
* OpenCV : https://docs.opencv.org/master/

adaptive_thresholding_opencv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cv2
22
import numpy as np
33

4-
img = cv2.imread('sudoku.png' , 0)
4+
img = cv2.imread('test_images/sudoku.png' , 0)
55

66
cv2.imshow('Main Image' , img)
77

basic_operations_opencv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import numpy as np
22
import cv2
33

4-
img = cv2.imread('messi5.jpg')
5-
img2 = cv2.imread('opencv-logo.png')
4+
img = cv2.imread('test_images/messi5.jpg')
5+
img2 = cv2.imread('test_images/opencv-logo.png')
66

77
print(img.shape) # row , column , channles
88
print(img.size) # total number of pixels

bitwise_operation_opencv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# height width channls
55
img1 = np.zeros((250,500,3) , np.uint8)
66
img1 = cv2.rectangle(img1,(200,0),(300,100) , (255,255,255) , -1)
7-
img2 = cv2.imread('messi5.jpg')
7+
img2 = cv2.imread('test_images/messi5.jpg')
88

99
cv2.imshow('Main image1' , img1)
1010
cv2.imshow('Main image2' , img2)

canny_edge_detection.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import cv2
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
img = cv2.imread('test_images/smarties.png', 0)
6+
7+
## Canny Edge Detection : It is multi-stage algorithm useful for wide range of edge detection.
8+
## Total 5 Steps :
9+
# (1) Noise Reduction
10+
# (2) Gradient Calculation
11+
# (3) Non-maximum supression
12+
# (4) Double threshold
13+
# (5) Edge Tracking by hysteresis
14+
## All things will be done by using one simple function frmo OpenCV
15+
16+
17+
### Using Matplotlib ###
18+
19+
canny = cv2.Canny(img ,100 ,200)
20+
21+
22+
titles = ['Main image', 'Canny']
23+
images = [img , canny]
24+
25+
26+
for i in range(len(images)):
27+
plt.subplot(1,2,i+1)
28+
plt.imshow(images[i] , 'gray')
29+
plt.title(titles[i])
30+
plt.xticks([]) , plt.yticks([])
31+
32+
plt.show()
33+
34+
35+
### Using Trackbar ###
36+
37+
# def nothing(x):
38+
# pass
39+
# cv2.namedWindow('threshold meter')
40+
# cv2.createTrackbar('th1' , 'threshold meter' , 0 ,255 , nothing)
41+
# cv2.createTrackbar('th2' , 'threshold meter', 0 , 255 , nothing)
42+
43+
# cv2.imshow('Image' , img)
44+
45+
# while True:
46+
# th1 = cv2.getTrackbarPos('th1','threshold meter')
47+
# th2 = cv2.getTrackbarPos('th2','threshold meter')
48+
# canny = cv2.Canny(img , th1 , th2 )
49+
# cv2.imshow('canny' , canny)
50+
51+
# key = cv2.waitKey(1)
52+
# if key == 27:
53+
# break
54+
55+
56+
# cv2.destroyAllWindows()

draw_shapes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cv2
22
import numpy as np
3-
# img = cv2.imread('lena.jpg', 1)
3+
# img = cv2.imread('test_images/lena.jpg', 1)
44

55
# img with numpy
66
img = np.zeros([600,600,3] , np.uint8 )

first_tut.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cv2
22

3-
# img = cv2.imread('lena.jpg',-1)
3+
# img = cv2.imread('test_images/lena.jpg',-1)
44

55
# cv2.imshow('image',img)
66

@@ -9,7 +9,7 @@
99
# if k == 27:
1010
# cv2.destroyAllWindows()
1111
# elif k == ord('s'):
12-
# cv2.imwrite('lena_copy_2.png' , img)
12+
# cv2.imwrite('test_images/lena_copy_2.png' , img)
1313
# cv2.destroyAllWindows()
1414

1515

image_gradients.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import cv2
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
# Image Gradient : directional change in intensity or color in image.
6+
# img = cv2.imread('test_images/messi5.jpg' , cv2.IMREAD_GRAYSCALE)
7+
img = cv2.imread('test_images/lena.jpg' , cv2.IMREAD_GRAYSCALE)
8+
9+
##### Laplacian Gradient : detect edges in images. ######
10+
11+
# 64 bit float type. It supports negative number
12+
# negative slop due to induced by transformaing the image white to black.
13+
# NOTE : kernelsize must be odd
14+
15+
lap = cv2.Laplacian(img,cv2.CV_64F , ksize=1)
16+
17+
# take absolute value and convert it into unsigned interger 8 bit.
18+
lap = np.uint8(np.absolute(lap))
19+
20+
21+
22+
##### Sobel Gradient ######
23+
24+
sobelX = cv2.Sobel(img , cv2.CV_64F , 1, 0 )
25+
sobelY = cv2.Sobel(img , cv2.CV_64F , 0, 1 )
26+
27+
sobelX = np.uint8(np.absolute(sobelX))
28+
sobelY = np.uint8(np.absolute(sobelY))
29+
30+
sobelCombined = cv2.bitwise_or(sobelX , sobelY)
31+
32+
titles = ['image' , 'Laplacian', 'sobelX' , 'sobelY', 'Sobel Combined']
33+
images = [img , lap , sobelX , sobelY , sobelCombined]
34+
35+
36+
for i in range(len(images)):
37+
plt.subplot(2,3, i+1)
38+
plt.imshow(images[i] , 'gray')
39+
plt.title(titles[i])
40+
plt.xticks([]) , plt.yticks([])
41+
42+
43+
plt.show()

image_pyramids_opencv.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import cv2
2+
import numpy as np
3+
4+
## Pyramid : Using Blur and subsample we downscale the image in low size.
5+
## Use for Reduce the size of images.
6+
7+
img = cv2.imread('test_images/lena.jpg')
8+
layer = img.copy()
9+
10+
# 1. Gaussian Pyramid
11+
12+
# pyrDown : reduce the size
13+
# pyrUp : increase the size
14+
15+
# applying pyrUp on pyrdowned image will not be same as original.
16+
# pyrdown image lose data at the time of compression.
17+
gp = [layer]
18+
19+
for i in range(6):
20+
layer = cv2.pyrDown(layer)
21+
gp.append(layer)
22+
# cv2.imshow(str(i) , layer)
23+
24+
25+
# 2. Laplacian Pyramid
26+
# Difference between that level in gaussian pyramid and expanded version of its upper level
27+
# in gaussian pyramid
28+
# Its like edge detection
29+
30+
layer = gp[5]
31+
cv2.imshow('final upper layer',layer)
32+
lp = [layer]
33+
34+
for i in range(5,0,-1):
35+
gaussian_expaned = cv2.pyrUp(gp[i])
36+
laplacian = cv2.subtract(gp[i-1],gaussian_expaned)
37+
cv2.imshow(str(i) , laplacian)
38+
39+
cv2.waitKey(0)
40+
cv2.destroyAllWindows()

matplotlib_with_opencv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from matplotlib import pyplot as plt
44

5-
img = cv2.imread('lena.jpg' , -1)
5+
img = cv2.imread('test_images/lena.jpg' , -1)
66

77
plt.imshow(img)
88
plt.title('BGR Format Image')

0 commit comments

Comments
 (0)