From: Jonathon H. <js...@ec...> - 2015-06-16 13:21:21
|
Try this: ByteArrayInputStream bais = new ByteArrayInputStream(decodedBytes); LocalFeatureList<ByteDSIFTKeypoint> decodedFeatures = MemoryLocalFeatureList.read(bais, ByteDSIFTKeypoint.class); (obviously this will only work for lists of features & is heavily optimised for this usecase) > On 16 Jun 2015, at 14:15, chalitha udara Perera <cha...@gm...> wrote: > > Thanks for quick response Sir. It works fine for serialization. But how can i again retrieve the list of local features by deserializing the byte array ? > > I tried following code, but it gives corrupted stream exception: java.io.StreamCorruptedException: invalid stream header: 4B505400 > ByteArrayInputStream bais = new ByteArrayInputStream(decodedBytes); > > ObjectInputStream ois = new ObjectInputStream(bais); > > LocalFeatureList<ByteDSIFTKeypoint> decodedFeatures = (LocalFeatureList<ByteDSIFTKeypoint>) ois.readObject(); > > Looking at OpenIMAJ api, there is a method to deserialze binaries, but how to use it to get LocalFeatureList<ByteDSIFTKeypoint> from the binary ? > > > > Thanks, > > Chalitha > > > On Tue, Jun 16, 2015 at 5:59 PM, Jonathon Hare <js...@ec... <mailto:js...@ec...>> wrote: > Do something like this (will automatically write the complete list of features without need to iterate through them): > > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > > org.openimaj.io.IOUtils.writeBinary(baos, features); > > byte[] bytes = baos.toByteArray(); > > > > > >> On 16 Jun 2015, at 11:19, chalitha udara Perera <cha...@gm... <mailto:cha...@gm...>> wrote: >> >> Hi All, >> I have extracted LocalFeaturesList<ByteDSIFTKeypoint> using Pyramid Dense Sift in OpenIMAJ. >> As indicated in API documentation, ByteDSIFTKeypoint implements Java Serializable interface and there fore I would like to serialize keypoints for latter use. >> I tried to serialize keypoints to get a byte array. But when retrieving key-points from the serialized object it loses all field values associated with it. >> >> I am using the following code for serialization >> >> ByteArrayOutputStream baos = new ByteArrayOutputStream(); >> >> ObjectOutputStream oos = new ObjectOutputStream(baos); >> >> >> LocalFeatureList<ByteDSIFTKeypoint> features = psift.getByteKeypoints(); >> >> for (ByteDSIFTKeypoint byteDSIFTKeypoint : features) { >> >> >> oos.writeObject(byteDSIFTKeypoint); >> >> >> byte[] bytes = baos.toByteArray(); >> >> } >> >> >> >> Any help regarding how to correctly serialize keypoints is greatly appreciated. >> >> Thanks, >> >> Chalitha >> >> >> -- >> J.M Chalitha Udara Perera >> >> Department of Computer Science and Engineering, >> University of Moratuwa, >> Sri Lanka >> ------------------------------------------------------------------------------ >> _______________________________________________ >> openimaj-discuss mailing list >> ope...@li... <mailto:ope...@li...> >> https://lists.sourceforge.net/lists/listinfo/openimaj-discuss <https://lists.sourceforge.net/lists/listinfo/openimaj-discuss> > > > > > -- > J.M Chalitha Udara Perera > > Department of Computer Science and Engineering, > University of Moratuwa, > Sri Lanka |