Browse Source

ID assignment delayed a bit

dev
sipp11 5 years ago
parent
commit
616d017a0d
  1. 53
      src/main.py

53
src/main.py

@ -274,6 +274,33 @@ while True:
trackers[idx]["status"] = "dont-care" trackers[idx]["status"] = "dont-care"
untracking.append(trackers[idx]) untracking.append(trackers[idx])
# TODO: assign id here! for anything that is -1 id
gid = None
if tk['id'] == -1 and 5 < h_count and h_count < 15:
_area_id = f"id_{tk['origin']['id']}"
if _area_id in W4A:
# check candidates which has "matched" opportunity too
_po = W4A[_area_id]["objects"]
_po = [_ for _ in _po if _frame_count > _[2]] # opportunity
_po = sorted(_po, key=lambda kk: kk[2]) # first one first
if _po:
trackers[idx]['id'] = gid = _po[0][0]["id"]
# remove this id out of next W4A
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" {gid} RE-ENTERS")
elif tk['id'] == -1 and h_count >= 15:
# assign an id
trackers[idx]['id'] = tracker_counter
tracker_counter += 1
print(f" {trackers[idx]['id']} ENTERS (& ID assigned)")
for lvng_cnd in OBJ_LEAVING_COND: for lvng_cnd in OBJ_LEAVING_COND:
_origin = tk["origin"]["id"] _origin = tk["origin"]["id"]
cond = dict(lvng_cnd) cond = dict(lvng_cnd)
@ -340,7 +367,7 @@ while True:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.putText( cv2.putText(
frame, frame,
f"{tk['id']} - {tk['type']}", f"{tk['id'] if tk['id'] > 0 else '?'} - {tk['type']}",
(x, y - 5), (x, y - 5),
cv2.FONT_HERSHEY_SIMPLEX, cv2.FONT_HERSHEY_SIMPLEX,
0.5, 0.5,
@ -404,29 +431,12 @@ while True:
break break
if not is_same: if not is_same:
gid = None
_area_id = f"id_{found_at['id']}"
if _area_id in W4A:
# check candidates which has "matched" opportunity too
_po = W4A[_area_id]["objects"]
_po = [_ for _ in _po if _frame_count > _[2]] # opportunity
_po = sorted(_po, key=lambda kk: kk[2]) # first one first
if _po:
gid = _po[0][0]["id"]
# remove this id out of next W4A
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")
# create tracker and add to multi-object tracker # create tracker and add to multi-object tracker
_tracker = OPENCV_OBJECT_TRACKERS["csrt"]() _tracker = OPENCV_OBJECT_TRACKERS["csrt"]()
bbox = (x, y, w, h) bbox = (x, y, w, h)
cv_trackers.add(_tracker, frame, bbox) cv_trackers.add(_tracker, frame, bbox)
t = { t = {
"id": tracker_counter if gid is None else gid, "id": -1, # NOTE: assign later; tracker_counter if gid is None else gid,
"type": _class, "type": _class,
"status": "", "status": "",
"curr_position": bbox, "curr_position": bbox,
@ -437,11 +447,6 @@ while True:
"last_position": bbox, "last_position": bbox,
"still": 0, "still": 0,
} }
if gid is None:
print(f" {t['id']} ENTERS")
tracker_counter += 1
else:
print(f" {t['id']} RE-ENTERS")
trackers.append(t) trackers.append(t)
print(f" total #{len(trackers)}") print(f" total #{len(trackers)}")
pp.pprint(t) pp.pprint(t)

Loading…
Cancel
Save