|
|
|
@ -184,6 +184,7 @@ while True:
|
|
|
|
|
(success, boxes) = cv_trackers.update(frame) |
|
|
|
|
# print("success", success) |
|
|
|
|
# print("boxes", boxes) |
|
|
|
|
print(f"[{_frame_count:08d}] ::") |
|
|
|
|
|
|
|
|
|
untracking = [] |
|
|
|
|
# loop over the bounding boxes and draw then on the frame |
|
|
|
@ -231,7 +232,7 @@ while True:
|
|
|
|
|
if (cond["heading"] in "NE" and x + w > cond["x"]) or ( |
|
|
|
|
cond["heading"] in "SW" and x < cond["x"] |
|
|
|
|
): |
|
|
|
|
print("REACH condition: X", x, cond["x"]) |
|
|
|
|
# print("REACH condition: X", x, cond["x"]) |
|
|
|
|
REACH_condition = True |
|
|
|
|
|
|
|
|
|
elif cond["y"] != -1: |
|
|
|
@ -239,7 +240,7 @@ while True:
|
|
|
|
|
if (cond["heading"] in "NE" and x + w > cond["y"]) or ( |
|
|
|
|
cond["heading"] in "SW" and x < cond["y"] |
|
|
|
|
): |
|
|
|
|
print("REACH condition: Y") |
|
|
|
|
# print("REACH condition: Y") |
|
|
|
|
REACH_condition = True |
|
|
|
|
if not REACH_condition: |
|
|
|
|
continue |
|
|
|
@ -248,9 +249,10 @@ while True:
|
|
|
|
|
# pp.pprint(cond) |
|
|
|
|
# TODO: should be a loop here if next has > 1 |
|
|
|
|
_nid = f"id_{cond['next_area'][0]}" |
|
|
|
|
print(f"#{tk['id']} origin:#{_origin} to#{_nid}", end="") |
|
|
|
|
# print(f"#{tk['id']} origin:#{_origin} to#{_nid}", end="") |
|
|
|
|
print(f" {tk['id']} LEFT from {_origin} -> {_nid}") |
|
|
|
|
if _nid not in W4A: |
|
|
|
|
print(f">>add AREA {_nid} to W4A", end="") |
|
|
|
|
# print(f">>add AREA {_nid} to W4A", end="") |
|
|
|
|
W4A[_nid] = {"objects": []} |
|
|
|
|
# put this object to W4A for next area if doesn't exist |
|
|
|
|
has_this = [_ for _ in W4A[_nid]["objects"] if _[0]["id"] == tk["id"]] |
|
|
|
@ -260,7 +262,7 @@ while True:
|
|
|
|
|
_expected_frame = _frame_count + cond["duration_to_next"] |
|
|
|
|
W4A[_nid]["objects"].append((tk, _frame_count, _expected_frame)) |
|
|
|
|
untracking.append(tk) |
|
|
|
|
print(f'>>GONE - W#{len(W4A[_nid]["objects"])}') |
|
|
|
|
# print(f'>>GONE - W#{len(W4A[_nid]["objects"])}') |
|
|
|
|
# print(f' {_nid} objs: ') |
|
|
|
|
# pp.pprint(W4A[_nid]["objects"]) |
|
|
|
|
# print(f' {_nid} untracking: ', [_['id'] for _ in untracking]) |
|
|
|
@ -303,8 +305,9 @@ while True:
|
|
|
|
|
for _trckr in trackers: |
|
|
|
|
__tkr = OPENCV_OBJECT_TRACKERS["csrt"]() |
|
|
|
|
cv_trackers.add(__tkr, frame, tuple(_trckr["curr_position"])) |
|
|
|
|
print(f"=== AFTER CLEANUP ---- UNTRACKING ===") |
|
|
|
|
print(f" cv #{len(cv_trackers.getObjects())} trackers #{len(trackers)}") |
|
|
|
|
# print(f"=== AFTER CLEANUP ---- UNTRACKING ===") |
|
|
|
|
# print(f" cv #{len(cv_trackers.getObjects())} trackers #{len(trackers)}") |
|
|
|
|
print(f" Total #{len(cv_trackers.getObjects())}") |
|
|
|
|
|
|
|
|
|
# only detect once a sec |
|
|
|
|
if _frame_count % 15 == 1: |
|
|
|
@ -346,9 +349,9 @@ while True:
|
|
|
|
|
W4A[_area_id]["objects"] = [ |
|
|
|
|
_ for _ in W4A[_area_id]["objects"] if _[0]["id"] != gid |
|
|
|
|
] |
|
|
|
|
print(f" --- {len(_po)} candicate: picked id={gid}") |
|
|
|
|
else: |
|
|
|
|
print(f" --- no candidate") |
|
|
|
|
# print(f" --- {len(_po)} candicate: picked id={gid}") |
|
|
|
|
# else: |
|
|
|
|
# print(f" --- no candidate") |
|
|
|
|
|
|
|
|
|
# create tracker and add to multi-object tracker |
|
|
|
|
_tracker = OPENCV_OBJECT_TRACKERS["csrt"]() |
|
|
|
@ -365,14 +368,38 @@ while True:
|
|
|
|
|
"still": 0, |
|
|
|
|
} |
|
|
|
|
if gid is None: |
|
|
|
|
print(f" {t['id']} ENTERS") |
|
|
|
|
tracker_counter += 1 |
|
|
|
|
else: |
|
|
|
|
print(f" {t['id']} RE-ENTERS") |
|
|
|
|
trackers.append(t) |
|
|
|
|
print(f"trackers ADDED - now total #{len(trackers)}") |
|
|
|
|
print(f" total #{len(trackers)}") |
|
|
|
|
pp.pprint(t) |
|
|
|
|
# print(f" i -> {i} ({x},{y}), {w},{h} ({x + w},{y + h})") |
|
|
|
|
|
|
|
|
|
_what = ",".join([LABELS[c] for c in classIDs]) |
|
|
|
|
print(f"[{_frame_count:08d}] :: {_what}") |
|
|
|
|
# _what = ",".join([LABELS[c] for c in classIDs]) |
|
|
|
|
# print(f"[{_frame_count:08d}] :: {_what}") |
|
|
|
|
|
|
|
|
|
# CLEANUP |
|
|
|
|
cleanups = [] |
|
|
|
|
for k in W4A: |
|
|
|
|
for _o in W4A[k]["objects"]: |
|
|
|
|
print(f" CLEANUP: {_o[0]['id']} - {_o[1]} - {_o[2]}", end="\r\n") |
|
|
|
|
if _o[2] < _frame_count: |
|
|
|
|
continue |
|
|
|
|
wf = _o[2] - _o[1] |
|
|
|
|
wf = wf if wf < 30 * 6 else 180 |
|
|
|
|
if _o[2] - wf > _frame_count: |
|
|
|
|
# get rid of this |
|
|
|
|
cleanups.append(_o) |
|
|
|
|
# remove this id out of next W4A |
|
|
|
|
W4A[k]["objects"] = [ |
|
|
|
|
_ for _ in W4A[_area_id]["objects"] if _[0]["id"] != _o[0]["id"] |
|
|
|
|
] |
|
|
|
|
for obj, _s, _e in cleanups: |
|
|
|
|
print( |
|
|
|
|
f" {obj['id']} CLEANED UP should found at {_e - _frame_count} ago" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if args["live"]: |
|
|
|
|
cv2.imshow("Frame", frame) |
|
|
|
@ -405,7 +432,6 @@ while True:
|
|
|
|
|
# write the output frame to disk |
|
|
|
|
writer.write(frame) |
|
|
|
|
|
|
|
|
|
# TODO: cleanup W4A that is WAY over due -- it's unknown anyway.. |
|
|
|
|
# TODO: find a way to get rid of IMPOSSIBLE obj for example |
|
|
|
|
# suddenly appear on area 7 then move up NORTH... -- this is incorrectly detected indeed. |
|
|
|
|
|
|
|
|
|