elelubng commited on
Commit
f6b1b5d
1 Parent(s): 2d6d185

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +113 -0
README.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import tkinter as tk
3
+ from tkinter import filedialog
4
+
5
+ def save_image():
6
+ filename = filedialog.asksaveasfilename(defaultextension='.jpg')
7
+ if filename:
8
+ cv2.imwrite(filename, frame)
9
+
10
+ def update_params():
11
+ detector = cv2.SimpleBlobDetector_create(params)
12
+
13
+ def update_sliders():
14
+ min_size_slider.set(params.minArea)
15
+ max_size_slider.set(params.maxArea)
16
+ threshold_slider.set(params.thresholdStep)
17
+
18
+ def on_value_changed(value):
19
+ if value == "min_size":
20
+ params.minArea = min_size_slider.get()
21
+ elif value == "max_size":
22
+ params.maxArea = max_size_slider.get()
23
+ elif value == "threshold":
24
+ params.thresholdStep = threshold_slider.get()
25
+
26
+ update_params()
27
+
28
+ cap = cv2.VideoCapture(0)
29
+ cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
30
+ cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
31
+
32
+ params = cv2.SimpleBlobDetector_Params()
33
+ params.filterByArea = True
34
+ params.minArea = 1
35
+ params.maxArea = 5000
36
+ params.thresholdStep = 10
37
+ detector = cv2.SimpleBlobDetector_create(params)
38
+
39
+ root = tk.Tk()
40
+ root.title("Detector de microparticulas")
41
+
42
+ min_size_label = tk.Label(root, text="Tamaño minimo")
43
+ min_size_slider = tk.Scale(root, from_=0, to=1000, length=200, orient=tk.HORIZONTAL, label="Tamaño mínimo", command=lambda value: on_value_changed("min_size"))
44
+
45
+ max_size_label = tk.Label(root, text="Tamaño maximo")
46
+ max_size_slider = tk.Scale(root, from_=0, to=10000, length=200, orient=tk.HORIZONTAL, label="Tamaño máximo", command=lambda value: on_value_changed("max_size"))
47
+
48
+ threshold_label = tk.Label(root, text="Sensibilidad")
49
+ threshold_slider = tk.Scale(root, from_=0, to=255, length=200, orient=tk.HORIZONTAL, label="Sensibilidad", command=lambda value: on_value_changed("threshold"))
50
+
51
+ min_dist_label = tk.Label(root, text="Distancia minima entre blobs")
52
+ min_dist_slider = tk.Scale(root, from_=0, to=100, length=200, orient=tk.HORIZONTAL, label="Distancia minima", command=lambda value: on_value_changed("min_dist"))
53
+
54
+ circularity_label = tk.Label(root, text="Circulatidad")
55
+ circularity_slider = tk.Scale(root, from_=0, to=1, resolution=0.1, length=200, orient=tk.HORIZONTAL, label="Circulatidad", command=lambda value: on_value_changed("circularity"))
56
+
57
+ convexity_label = tk.Label(root, text="Convexidad")
58
+ convexity_slider = tk.Scale(root, from_=0, to=1, resolution=0.1, length=200, orient=tk.HORIZONTAL, label="Convexidad", command=lambda value: on_value_changed("convexity"))
59
+
60
+ inertia_label = tk.Label(root, text="Inercia")
61
+ inertia_slider = tk.Scale(root, from_=0, to=1, resolution=0.1, length=200, orient=tk.HORIZONTAL, label="Inercia", command=lambda value: on_value_changed("inertia"))
62
+
63
+ save_button = tk.Button(root, text="Guardar imagen", command=save_image)
64
+
65
+ min_size_label.pack()
66
+ min_size_slider.pack()
67
+ max_size_label.pack()
68
+ max_size_slider.pack()
69
+ threshold_label.pack()
70
+ threshold_slider.pack()
71
+ min_dist_label.pack()
72
+ min_dist_slider.pack()
73
+ circularity_label.pack()
74
+ circularity_slider.pack()
75
+
76
+ update_params()
77
+ update_sliders()
78
+
79
+ while True:
80
+ ret, frame = cap.read()
81
+
82
+ if not ret:
83
+ continue
84
+
85
+ gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
86
+ keypoints = detector.detect(gray)
87
+
88
+ if keypoints:
89
+ for kp in keypoints:
90
+ x, y = kp.pt
91
+ size = kp.size
92
+ cv2.rectangle(frame, (int(x - size / 2), int(y - size / 2)), (int(x + size / 2), int(y + size / 2)), (0, 255, 0), 2)
93
+
94
+ count = len(keypoints)
95
+ cv2.putText(frame, "Contador: " + str(count), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
96
+
97
+ cv2.imshow("Detector de micropartículas", frame)
98
+
99
+ key = cv2.waitKey(1)
100
+ if key == ord('q'):
101
+ break
102
+ elif key == ord('+'):
103
+ params.maxArea += 5000
104
+ update_sliders()
105
+ elif key == ord('-'):
106
+ params.maxArea -= 5000
107
+ update_sliders()
108
+
109
+ cap.release()
110
+ cv2.destroyAllWindows()
111
+
112
+
113
+