Skip to content

Commit 910c936

Browse files
fixing previous codes
1 parent c01e6ff commit 910c936

File tree

14 files changed

+155
-37
lines changed

14 files changed

+155
-37
lines changed

01. Basic operations/drawingOnImage.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
pt2=(300, 300),
1717
color=(0, 255, 255),
1818
thickness=2)
19-
20-
img = cv2.rectangle(img,
19+
20+
img = cv2.rectangle(img,
2121
pt1=(250, 0),
2222
pt2=(450, 250),
2323
color=(0, 255, 0),
2424
thickness=2)
2525

2626
img = cv2.circle(img,
27-
center=(100, 100),
28-
radius=50,
29-
color=(255, 0, 255),
27+
center=(100, 100),
28+
radius=50,
29+
color=(255, 0, 255),
3030
thickness=-1)
3131

3232
cv2.imshow("output", img)
3333
else:
3434
print('file not found.')
35-
35+
3636
cv2.waitKey(0)
3737
cv2.destroyAllWindows()
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
''' Getting started with opencv
2+
3+
Reading and saving image with opencv using waitKey
4+
'''
15
import cv2
26

37
#load an color image in grayscale color
48
img = cv2.imread('./Media/sample.jpeg',0)
59

610
cv2.imshow('image', img)
711
k = cv2.waitKey(0) & 0xFF
8-
# esc key to exit
12+
13+
# esc key to exit
914
if k == 27:
1015
cv2.destroyAllWindows()
16+
1117
# s key to save and exit
1218
elif k == ord('s'):
13-
cv2.imwrite("./Media/sample2.jpeg", img)
14-
cv2.destroyAllWindows()
19+
cv2.imwrite("./Media/sample2.jpeg", img)
20+
cv2.destroyAllWindows()
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
# capture video from camera
2-
import numpy as np
1+
''' Getting started with Videos in Opencv'''
32
import cv2
43

54
cap = cv2.VideoCapture(0)
65

76
while True:
87
# capture frame by frame
9-
ret, frame = cap.read()
10-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
8+
check, frame = cap.read()
9+
if check:
10+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
1111

12-
# display the result
13-
cv2.imshow('frame', gray)
14-
if cv2.waitKey(1) & 0xFF == ord('q'):
15-
break
12+
# display the result
13+
cv2.imshow('frame', gray)
14+
15+
# break the while loop by 'q'
16+
if cv2.waitKey(1) & 0xFF == ord('q'):
17+
break
1618

1719
#release the cap
1820
cap.release()
19-
cv2.destroyAllWindows()
21+
cv2.destroyAllWindows()

01. Basic operations/mouseEvents.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
''' Mouse Events in OpenCV '''
2+
23
import cv2
34
import numpy as np
45

@@ -16,4 +17,4 @@ def draw_circle(event, x, y, flags, param):
1617
cv2.imshow('image', img)
1718
if cv2.waitKey(20) & 0xFF == 27:
1819
break
19-
cv2.destroyAllWindows()
20+
cv2.destroyAllWindows()

01. Basic operations/savingVideosFromCamera.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
while(cap.isOpened()):
1111
ret, frame = cap.read()
12-
if ret == True:
12+
if ret:
1313
frame = cv2.flip(frame,0)
1414

1515
# write the filpped frame
1616
out.write(frame)
1717

1818
cv2.imshow('video',frame)
19+
1920
if cv2.waitKey(1) & 0xFF == ord('q'):
2021
break
2122
else:
@@ -24,4 +25,4 @@
2425
# release video capture
2526
cap.release()
2627
out.release()
27-
cv2.destroyAllWindows()
28+
cv2.destroyAllWindows()
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
''' Showing output using matplotlib '''
22

3-
from matplotlib import pyplot as plt
43
import cv2
4+
from matplotlib import pyplot as plt
55

66
img = cv2.imread('./Media/sample.jpeg', 0)
7+
78
plt.imshow(img, cmap="gray")
8-
plt.show()
9+
plt.title('Sample Image')
10+
plt.xticks([])
11+
plt.yticks([])
12+
plt.show()

01. Basic operations/usingSkimage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cv2
2+
from skimage import io
3+
4+
# reading the image
5+
img = cv2.imread('./Media/sample.jpeg')
6+
7+
# changing image from BGR to RGB for correct output
8+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
9+
10+
# showing output
11+
io.imshow(img)
12+
io.show()

04. Image Filter/SkImageFilter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from skimage import data, io, filters
2+
3+
image = data.coins()
4+
# ... or any other NumPy array!
5+
edges = filters.sobel(image)
6+
io.imshow(edges)
7+
io.show()

09. Template Matching/portMatching.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"""
2-
Template Matching is a method for searching and finding the location of a template image in a larger image.
3-
OpenCV comes with a function cv2.matchTemplate() for this purpose. It simply slides the template image over the input
4-
image (as in 2D convolution) and compares the template and patch of input image under the template image.
1+
"""
2+
Template Matching is a method for searching and finding the location of a template image in a larger image.
3+
OpenCV comes with a function cv2.matchTemplate() for this purpose. It simply slides the template image over the input
4+
image (as in 2D convolution) and compares the template and patch of input image under the template image.
55
"""
66
import cv2
77
import numpy as np
@@ -28,4 +28,3 @@
2828
elif k == ord("s"):
2929
cv2.imwrite('./Media/port-detected.jpeg', source_color)
3030
cv2.destroyAllWindows()
31-
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
''' watershed Algorithm in opencv '''
2+
3+
import cv2
4+
import numpy as np
5+
6+
img = cv2.imread('./Media/coins.jpg')
7+
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
8+
9+
ret, thresh = cv2.threshold(gray_img, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
10+
11+
# noise removal
12+
kernel = np.ones((3, 3), np.uint8)
13+
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=2)
14+
15+
#sure background area
16+
sure_bg = cv2.dilate(opening, kernel)
17+
18+
# finding sure foreground area
19+
dist_transform = cv2.distanceTransform(opening, cv2.DIST_L2, 5)
20+
ret, sure_fg = cv2.threshold(dist_transform, 0.7*dist_transform.max(), 255, 0)
21+
22+
# finding unknown region
23+
24+
sure_fg = np.uint8(sure_fg)
25+
unknown = cv2.subtract(sure_bg, sure_fg)
26+
27+
# makrer labeling
28+
ret, markers = cv2.connectedComponents(sure_fg)
29+
30+
# add one to all labels so that sure background is not 0, but 1
31+
markers = markers + 1
32+
33+
# mark the region of unknown with zero
34+
markers[unknown==255] = 0
35+
36+
markers = cv2.watershed(img, markers)
37+
img[markers == -1] = [255, 0, 0]
38+
39+
cv2.imshow('output', img)
40+
41+
key = cv2.waitKey(0) & 0xFF
42+
if key == 27:
43+
cv2.destroyAllWindows()

21. Facial Recognition/FaceRec.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55

66
video_capture = cv2.VideoCapture(0)
77

8-
98
# Create arrays of known face encodings and their names
109
known_face_encodings = []
1110
known_face_names = []
1211

1312
root_dir = os.path.dirname(os.path.abspath(os.path.abspath(__file__)))
1413
image_dir = os.path.join(root_dir, "images")
1514

15+
# creating encodings for faces from images folder
1616
for file in os.listdir(image_dir):
17-
if file.endswith == ".jpeg" or ".jpg":
17+
if file.endswith == "jpeg" or "jpg":
1818
input_face_name = file.split('.')[0]
1919
input_face = face_recognition.load_image_file(os.path.join(image_dir, file))
2020
input_face_encoding = face_recognition.face_encodings(input_face)[0]
21+
22+
# appending face_names and face encoding
2123
known_face_names.append(input_face_name)
2224
known_face_encodings.append(input_face_encoding)
2325

Media/coins.jpg

15.9 KB
Loading

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- [Contributing](#contributing)
1111
- [Authors and acknowledgment](#authors-and-acknowledgment)
1212
- [License](#license)
13-
- [Project status](#project-status)
13+
- [Citation](#citation)
1414
- [Author](#author)
1515

1616
## Introduction
@@ -93,7 +93,13 @@ Perform basic troubleshooting steps:
9393

9494
For open source projects,Under MIT License.
9595

96-
## Project status
96+
## Citation
97+
98+
```
99+
Stéfan van der Walt, Johannes L. Schönberger, Juan Nunez-Iglesias, François Boulogne, Joshua D. Warner, Neil Yager, Emmanuelle Gouillart, Tony Yu and the scikit-image contributors. scikit-image: Image processing in Python. PeerJ 2:e453 (2014) https://doi.org/10.7717/peerj.453
100+
101+
Coelho, L.P. 2013. Mahotas: Open source software for scriptable computer vision. Journal of Open Research Software 1(1):e3, DOI: http://dx.doi.org/10.5334/jors.ac
102+
```
97103

98104
## Author
99105

requirements.txt

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
1+
absl-py==0.12.0
2+
astunparse==1.6.3
3+
cachetools==4.2.2
14
certifi==2020.6.20
25
chardet==3.0.4
6+
click==7.1.2
37
cvlib==0.2.5
48
cycler==0.10.0
9+
decorator==4.4.2
10+
dlib==19.22.0
11+
face-recognition==1.3.0
12+
face-recognition-models==0.3.0
13+
flatbuffers==1.12
14+
gast==0.3.3
15+
google-auth==1.30.0
16+
google-auth-oauthlib==0.4.4
17+
google-pasta==0.2.0
18+
grpcio==1.32.0
19+
h5py==2.10.0
520
idna==2.10
621
imageio==2.9.0
722
imutils==0.5.3
23+
Keras-Preprocessing==1.1.2
824
kiwisolver==1.2.0
25+
mahotas==1.4.11
26+
Markdown==3.3.4
927
matplotlib==3.3.2
28+
networkx==2.5.1
1029
numpy==1.19.2
30+
oauthlib==3.1.0
1131
opencv-python==4.5.1.48
32+
opt-einsum==3.3.0
1233
Pillow==8.2.0
1334
progressbar==2.5
35+
protobuf==3.15.8
36+
pyasn1==0.4.8
37+
pyasn1-modules==0.2.8
1438
pyparsing==2.4.7
1539
PySide2==5.15.2
40+
pytesseract==0.3.7
1641
python-dateutil==2.8.1
42+
PyWavelets==1.1.1
1743
requests==2.24.0
44+
requests-oauthlib==1.3.0
45+
rsa==4.7.2
46+
scikit-image==0.18.1
47+
scipy==1.6.3
1848
shiboken2==5.15.2
1949
six==1.15.0
20-
tensorflow==2.4.1
50+
tensorboard==2.5.0
51+
tensorboard-data-server==0.6.0
52+
tensorboard-plugin-wit==1.8.0
53+
tensorflow-estimator==2.4.0
54+
tensorflow-gpu==2.4.1
55+
termcolor==1.1.0
56+
tifffile==2021.4.8
57+
typing-extensions==3.7.4.3
2158
urllib3==1.25.10
22-
click==7.1.2
23-
dlib==19.22.0
24-
face-recognition==1.3.0
25-
face-recognition-models==0.3.0
59+
Werkzeug==1.0.1
60+
wrapt==1.12.1

0 commit comments

Comments
 (0)