@@ -203,43 +203,42 @@ def run(self, ips, imgs, para = None):
203203 if para ['buf' ]:ips .mark = Mark (mark )
204204
205205class ShortRoute (Filter ):
206- title = 'Short Route'
207- note = ['auto_snap' ,'8-bit' , '16-bit' ,'int' , 'float' , 'req_roi' ,'preview' ]
206+ title = 'Shortest Route'
207+ note = ['auto_snap' ,'8-bit' , '16-bit' ,'int' , 'float' , 'req_roi' , '2int' , 'preview' ]
208208
209- para = {'fully connected' :True , 'geometric' :True ,'type' :'white line' }
210- view = [(bool , 'fully connected' , 'fully connected' ),
209+ para = {'fully connected' :True , 'lcost' :0 , 'max' :False , 'geometric' :True , 'type' :'white line' }
210+ view = [(float , 'lcost' , (0 , 1e5 ), 3 , 'step' , 'cost' ),
211+ (bool , 'max' , 'max cost' ),
212+ (bool , 'fully connected' , 'fully connected' ),
211213 (bool , 'geometric' , 'geometric' ),
212214 (list , 'type' , ['white line' , 'gray line' , 'white line on ori' ], str , 'output' , '' )]
213215
214216 def load (self , ips ):
215217 if not isinstance (ips .roi , LineRoi ):
216- IPy .alert ('LineRoi are needed!' )
217- return False
218+ return IPy .alert ('LineRoi are needed!' )
218219 return True
219220
220221 def run (self , ips , snap , img , para = None ):
221222 img [:] = snap
222- print (np .array (ips .roi .body ))
223- pts = np .array (ips .roi .body ).astype (np .int )
224- img_min ,img_max = snap .min (),snap .max ()
225- arr = img .copy ()
226- arr = (arr - arr .min ())/ np .ptp (arr )
227-
228- print (pts )
229-
230- if para ['type' ]== 'gray line' or para ['type' ]== 'white line' :
231- img [:] = img_min
232- for i in pts :
233- for j in range (len (i )- 1 ):
234- p0 = (i [j ][1 ],i [j ][0 ])
235- p1 = (i [j + 1 ][1 ],i [j + 1 ][0 ])
236- indices , weight = route_through_array (arr ,p0 , p1 )
237- indices = np .array (indices )
238- if para ['type' ]== 'white line on ori' :
239- img [indices [:,0 ],indices [:,1 ]]= img_max
240- elif para ['type' ]== 'gray line' :
241- img [indices [:,0 ],indices [:,1 ]] = snap [indices [:,0 ],indices [:,1 ]]
242- elif para ['type' ]== 'white line' :
243- img [indices [:,0 ],indices [:,1 ]] = img_max
223+ if para ['max' ]: img *= - 1
224+ np .add (img , para ['lcost' ]- img .min (), casting = 'unsafe' , out = img )
225+
226+ minv , maxv = ips .range
227+ routes = []
228+ for line in ips .roi .body :
229+ pts = np .array (list (zip (line [:- 1 ], line [1 :])))
230+ for p0 , p1 in pts [:,:,::- 1 ].astype (int ):
231+ indices , weight = route_through_array (img , p0 , p1 )
232+ routes .append (indices )
233+ rs , cs = np .vstack (routes ).T
234+ if para ['type' ]== 'white line on ori' :
235+ img [:] = snap
236+ img [rs ,cs ] = maxv
237+ elif para ['type' ]== 'gray line' :
238+ img [:] = minv
239+ img [rs ,cs ] = snap [rs ,cs ]
240+ elif para ['type' ]== 'white line' :
241+ img [:] = minv
242+ img [rs ,cs ] = maxv
244243
245244plgs = [Frequence , Statistic , Histogram , PointsValue ,ShortRoute ]
0 commit comments