-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageProcessing.py
More file actions
87 lines (67 loc) · 2.76 KB
/
Copy pathimageProcessing.py
File metadata and controls
87 lines (67 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
_, frame = cap.read()
# Save an image from the webcam
cv2.imwrite("Openhand.png",frame)
# Convert to HSV
#hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#cv2.imshow("HSV",hsv)
# Convert to Gray
grayScale = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Threshold
# ret, thresh = cv2.threshold(grayScale, 127, 255, cv2.THRESH_BINARY)
# cv2.imshow("Threshold", thresh)
# Adaptive Threshold
# threshGaussian = cv2.adaptiveThreshold(grayScale,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
# cv2.imshow("Adaptive Threshold", threshGaussian)
# Applying an opening transformation
# kernel = np.ones((5, 5), np.uint8)
# opening= cv2.morphologyEx(threshGaussian, cv2.MORPH_OPEN, kernel)
# cv2.imshow("Opening", opening)
# Applying an closing transformation
# kernel = np.ones((5, 5), np.uint8)
# closing = cv2.morphologyEx(threshGaussian, cv2.MORPH_CLOSE, kernel)
# cv2.imshow("Closing", closing)
# cv2.imwrite("MypictureGauss.png",threshGaussian)
# threshMean = cv2.adaptiveThreshold(grayScale, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 2)
# cv2.imshow("Adaptive Threshold Mean", threshMean)
# cv2.imwrite("MypictureMean.png", threshMean)
# Otsu's thresholding after Gaussian filtering
# blur = cv2.GaussianBlur(grayScale, (5, 5), 0)
# ret3, th3 = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# cv2.imshow("Otsu's thresholding", th3)
# Laplacian Gradient
# laplacian = cv2.Laplacian(grayScale, cv2.CV_64F)
# cv2.imshow("Laplacian",laplacian)
# Canny Edge Detection
# edges = cv2.Canny(grayScale, 100, 200)
# cv2.imshow("Cany", edges)
# Contours
# ret, thresh = cv2.threshold(grayScale, 127, 255, cv2.THRESH_BINARY)
# image, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#cv2.imshow("Contours",image)
# Drawing contours
# imgDraw1 = cv2.drawContours(thresh, contours, -1, (0, 255, 0), 3)
# cv2.imshow("Drawing Contours", imgDraw1)
# cnt = contours[4]
# imgDraw2 = cv2.drawContours(thresh, [cnt], 0, (0, 255, 0), 3)
# cv2.imshow("Last Drawing Contours", imgDraw2)
# Moments
# ret, thresh = cv2.threshold(grayScale, 127, 255, cv2.THRESH_BINARY)
# image, contours, hierarchy = cv2.findContours(thresh, 1, 2)
# cnt = contours[0]
# M = cv2.moments(cnt)
# print M
# Contour area
# area = cv2.contourArea(contours[4])
# cv2.imshow("Contour Area",area)
# Convex Hull
# hull = cv2.convexHull(contours[0])
# cv2.imshow("Convex Hull", hull)
c = cv2.waitKey(0)
if 'q' == chr(c & 255):
break
cap.release()
cv2.destroyAllWindows()