Skip to content

Commit 295888f

Browse files
committed
test implement of dlc-live
1 parent fe432a8 commit 295888f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

DeepLabStream.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ def write_video(self, frames: dict, index: int):
264264
######################
265265
@staticmethod
266266
def get_pose_mp(input_q, output_q):
267+
from dlclive import DLCLive
268+
267269
"""
268270
Process to be used for each camera/DLC stream of analysis
269271
Designed to be run in an infinite loop
@@ -278,6 +280,19 @@ def get_pose_mp(input_q, output_q):
278280
peaks = find_local_peaks_new(scmap, locref, ANIMALS_NUMBER, config)
279281
output_q.put((index, peaks))
280282

283+
284+
dlc_live = DLCLive(DLC_LIVE)
285+
while True:
286+
if input_q.full():
287+
index, frame = input_q.get()
288+
if not dlc_live.is_initialized:
289+
peaks = dlc_live.init_inference(frame)
290+
else:
291+
peaks = dlc_live.get_pose(frame)
292+
293+
output_q.put((index, peaks))
294+
295+
281296
@staticmethod
282297
def create_mp_tools(devices):
283298
"""

utils/poser.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,31 @@ def create_animal_skeleton(dots_cluster: tuple) -> dict:
187187
animal_skeletons.append(create_animal_skeleton(unique_cluster))
188188

189189
return animal_skeletons
190+
191+
192+
def transform_2skeleton(pose):
193+
from utils.configloader import ALL_BODYPARTS
194+
skeleton = dict()
195+
counter = 0
196+
for bp in pose:
197+
skeleton[ALL_BODYPARTS[counter]] = tuple(np.array(bp[0:2],dtype = int))
198+
counter += 1
199+
return skeleton
200+
201+
202+
def transform_2pose(skeleton):
203+
pose = np.array([*skeleton.values()])
204+
return pose
205+
206+
207+
208+
def calculate_skeletons_dlc_live(pose ,animals_number: int = 1) -> list:
209+
"""
210+
Creating skeletons from given pose
211+
There could be no more skeletons than animals_number
212+
Only unique skeletons output
213+
"""
214+
215+
skeletons = [transform_2skeleton(pose)]
216+
217+
return skeletons

0 commit comments

Comments
 (0)