@@ -301,14 +301,14 @@ def test_read_annot_old_format():
301
301
"""Test reading an old-style .annot file."""
302
302
def gen_old_annot_file (fpath , nverts , labels , rgba , names ):
303
303
dt = '>i'
304
- vdata = np .zeros ((nverts , 2 ))
304
+ vdata = np .zeros ((nverts , 2 ), dtype = dt )
305
305
vdata [:, 0 ] = np .arange (nverts )
306
306
vdata [:, [1 ]] = _pack_rgba (rgba [labels , :])
307
307
fbytes = b''
308
308
# number of vertices
309
309
fbytes += struct .pack (dt , nverts )
310
310
# vertices + annotation values
311
- fbytes += vdata .astype (dt ).tobytes ( )
311
+ fbytes += bytes ( vdata .astype (dt ).tostring () )
312
312
# is there a colour table?
313
313
fbytes += struct .pack (dt , 1 )
314
314
# number of entries in colour table
@@ -320,15 +320,15 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
320
320
# length of entry name (+1 for terminating byte)
321
321
fbytes += struct .pack (dt , len (names [i ]) + 1 )
322
322
fbytes += names [i ].encode ('ascii' ) + b'\00 '
323
- fbytes += rgba [i , :].astype (dt ). tobytes ( )
323
+ fbytes += bytes ( rgba [i , :].astype (dt ))
324
324
with open (fpath , 'wb' ) as f :
325
325
f .write (fbytes )
326
326
with InTemporaryDirectory ():
327
327
nverts = 10
328
328
nlabels = 3
329
329
names = ['Label {}' .format (l ) for l in range (nlabels )]
330
330
labels = np .concatenate ((
331
- np .arange (nlabels ), np .random .randint (0 , 3 , nverts - nlabels )))
331
+ np .arange (nlabels ), np .random .randint (0 , nlabels , nverts - nlabels )))
332
332
np .random .shuffle (labels )
333
333
rgba = np .random .randint (0 , 255 , (nlabels , 4 ))
334
334
# write an old .annot file
0 commit comments