Skip to content

Commit 6790d45

Browse files
committed
configuring blob detector for color and area only
1 parent 6e8e329 commit 6790d45

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

server_raspberrypi/main.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@
7575
config_main = {
7676
"size": (args.width, args.height)
7777
}
78-
if not args.no_hflip:
79-
config_main["transform"] = Transform(hflip=1)
8078
picam2 = Picamera2()
8179
# Not entirely sure how configurations work, preview/main etc.
82-
config = picam2.create_preview_configuration(main=config_main)
80+
hflip_num = 1
81+
if args.no_hflip:
82+
hflip_num = 0
83+
config = picam2.create_preview_configuration(main=config_main, transform=Transform(hflip=hflip_num))
8384
picam2.configure(config)
8485

8586
controls_main = {
@@ -99,11 +100,20 @@
99100

100101
# Not entirely sure the difference between start_preview and start.
101102
picam2.start()
102-
time.sleep(1) # let camera warm up
103+
sleep(1) # let camera warm up
103104

104105
# OpenCV blob detection config
105106
params = cv2.SimpleBlobDetector_Params()
107+
params.filterByColor = True
108+
params.filterByArea = True
106109
params.blobColor = args.blob_color
110+
params.minArea = 25
111+
params.minThreshold = 150
112+
params.minRepeatability = 3
113+
params.filterByCircularity = False
114+
params.filterByConvexity = False
115+
params.filterByInertia = False
116+
params.minDistBetweenBlobs = 100
107117
detector = cv2.SimpleBlobDetector_create(params)
108118

109119
# Set up UDP socket to receiving computer
@@ -121,7 +131,6 @@ class PhilNav:
121131
y = 0.0
122132
keypoint = None # for debugging inspection
123133

124-
125134
# This is where the Magic happens! The camera should pick up nothing but a white
126135
# dot from your reflective IR sticker. I use opencv blob detection to track its
127136
# (x, y) coordinates and send the changes to the receiving computer, which moves
@@ -183,12 +192,11 @@ def blobby(request):
183192
sock.sendto(MESSAGE, (args.ip, args.port))
184193

185194
# Log once per second
186-
if PhilNav.frame_nume % args.fps == 0:
195+
if PhilNav.frame_num % args.fps == 0:
187196
fps = PhilNav.frame_num / (time() - PhilNav.started_at)
188197
ms = (perf_counter() - PhilNav.frame_start) * 1000
189198
logging.info(
190-
f"Frame: {PhilNav.frame_num}, Diff: ({int(x_diff)}, {int(y_diff)}), FPS: {
191-
int(fps)}, loc ms: {int(ms)}"
199+
f"Frame: {PhilNav.frame_num}, Diff: ({int(x_diff)}, {int(y_diff)}), FPS: {int(fps)}, loc ms: {int(ms)}"
192200
)
193201

194202
# I'm setting these at the end rather than the beginning, because I want

0 commit comments

Comments
 (0)