1+ # Source: https://github.com/geaxgx/depthai_movenet/
2+ # Adapted by: Hilary Luo (hluo@clearpathrobotics.com)
3+
4+ # Original source license:
5+
6+ # MIT License
7+
8+ # Copyright (c) [2021] [geax]
9+
10+ # Permission is hereby granted, free of charge, to any person obtaining a copy
11+ # of this software and associated documentation files (the "Software"), to deal
12+ # in the Software without restriction, including without limitation the rights
13+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+ # copies of the Software, and to permit persons to whom the Software is
15+ # furnished to do so, subject to the following conditions:
16+
17+ # The above copyright notice and this permission notice shall be included in all
18+ # copies or substantial portions of the Software.
19+
20+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+ # SOFTWARE.
27+
128from collections import namedtuple
229from math import gcd
330import numpy as np
835import depthai as dai
936import marshal
1037
11- from turtlebot4_vision_tutorials .FPS import FPS
12-
1338from ament_index_python .packages import get_package_share_directory
1439
1540SHARE_DIR = get_package_share_directory ('turtlebot4_vision_tutorials' )
@@ -138,7 +163,6 @@ class MovenetDepthai:
138163 - internal_frame_height : when using the internal color camera, set the frame height
139164 (calling setIspScale()). The width is calculated accordingly to
140165 height and depends on value of 'crop'
141- - stats : True or False, when True, display the global FPS when exiting.
142166 """
143167 def __init__ (self ,
144168 input_src = "rgb" ,
@@ -147,8 +171,7 @@ def __init__(self,
147171 crop = False ,
148172 smart_crop = True ,
149173 internal_fps = None ,
150- internal_frame_height = 640 ,
151- stats = True ):
174+ internal_frame_height = 640 ):
152175
153176 self .model = model
154177
@@ -166,14 +189,12 @@ def __init__(self,
166189 self .pd_input_length = 256
167190 print (f"Using blob file : { self .model } " )
168191
169- print (f"MoveNet imput size : { self .pd_input_length } x{ self .pd_input_length } x3" )
192+ print (f"MoveNet input size : { self .pd_input_length } x{ self .pd_input_length } x3" )
170193
171194 self .score_thresh = score_thresh
172-
173195 self .crop = crop
174196 self .smart_crop = smart_crop
175197 self .internal_fps = internal_fps
176- self .stats = stats
177198
178199 if input_src is None or input_src == "rgb" or input_src == "rgb_laconic" :
179200 self .input_type = "rgb" # OAK* internal color camera
@@ -223,15 +244,8 @@ def __init__(self,
223244 if not self .laconic :
224245 self .q_video = self .device .getOutputQueue (name = "cam_out" , maxSize = 1 , blocking = False )
225246 self .q_processing_out = self .device .getOutputQueue (name = "processing_out" ,
226- maxSize = 4 ,
247+ maxSize = 1 ,
227248 blocking = False )
228- # For debugging
229- # self.q_manip_out=self.device.getOutputQueue(name="manip_out", maxSize=1, blocking=False)
230-
231- self .fps = FPS ()
232-
233- self .nb_frames = 0
234- self .nb_pd_inferences = 0
235249
236250 def create_pipeline (self ):
237251 print ("Creating pipeline..." )
@@ -349,14 +363,11 @@ def pd_postprocess(self, inference):
349363 return body
350364
351365 def next_frame (self ):
352- self .fps .update ()
353-
354366 # Get the device camera frame if wanted
355367 if self .laconic :
356368 frame = np .zeros ((self .frame_size , self .frame_size , 3 ), dtype = np .uint8 )
357369 else :
358- in_video = self .q_video .get ()
359- frame = in_video .getCvFrame ()
370+ frame = self .q_video .get ().getCvFrame ()
360371
361372 # For debugging
362373 # manip = self.q_manip_out.get().getCvFrame()
@@ -367,16 +378,4 @@ def next_frame(self):
367378 body = self .pd_postprocess (inference )
368379 self .crop_region = body .next_crop_region
369380
370- size = (in_video .getWidth (), in_video .getHeight ())
371-
372- # Statistics
373- if self .stats :
374- self .nb_frames += 1
375- self .nb_pd_inferences += 1
376-
377- return frame , body , size
378-
379- def exit (self ):
380- # Print some stats
381- if self .stats :
382- print (f"FPS: { self .fps .global_duration ():.1f} f/s (# frames = { self .fps .nb_frames ()} )" )
381+ return frame , body
0 commit comments