[Mono-dev] Remoting IplImage/Bitmap return type problem

Euan MacInnes euan_macinnes at hotmail.com
Sun Nov 25 20:37:44 EST 2007


Assuming you're doing something similar to the following (pixel depth may vary, this assumes 32 bit):

IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3);

Then you can access the image as an array like so:

RgbImageFloat imgA(img);
imgA[i][j].b = 111;
imgA[i][j].g = 111;
imgA[i][j].r = 111;

If that is what you are doing, then you will be able to take the imgA array and serialise that across, arrays are easy to copy over (unless it's arrays of pointers. Pointers don't survive being remoted).

Worst-case scenario is creating another byte array and copying imgA[x][y].r .g & .b  into a linear array. Assuming OpenGL display is needed on your remote client, the client will be able to take this byte array and create a texture out of it, as it would just be in GL_RGB format. It's 2-3 lines of code for that.


----------------------------------------
> Date: Sun, 25 Nov 2007 16:13:53 -0300
> From: buhochileno at gmail.com
> To: mono-devel-list at lists.ximian.com
> Subject: Re: [Mono-dev] Remoting IplImage/Bitmap return type problem
> 
> Is posible to create a binary representation of an object in memory with
> some serialization and transmit the bytes[] of the object with remoting
> and in the other side re-build the object with his bytes?, or I crazy :-S
> .
> 
> 
> Euan MacInnes wrote:
>> Hi Mauricio,
>>      One option to do this is to extract the bitmap as a series of bytes, and then stream the byte array across.
>>
>> given a bitmap called "mybitmap"
>>
>> MemoryStream ms = New MemoryStream();
>> mybitmap.Save(ms,  ImageFormat.Jpeg);  // Save it as Jpeg if you don't mind it being compressed
>>
>> then you can either serialise the stream, or convert to an array of bytes and send that: 
>>
>> byte[] picBuf = ms.GetBuffer();
>>
>> Cheers,
>>
>> Euan.
>>
>> ----------------------------------------
>>   
>>> Date: Sat, 24 Nov 2007 20:12:15 -0300
>>> From: buhochileno at gmail.com
>>> To: mono-devel-list at lists.ximian.com
>>> Subject: [Mono-dev] Remoting IplImage/Bitmap return type problem
>>>
>>> Hi:
>>>
>>> I still have my problem about how to get the remoting object picture 
>>> from a client. First I try to make a property and a method to return a 
>>> Bitmap, but finally I only get "some class/type is not marked as 
>>> Serializable...", and now I try to use a IplImage from a basic OpenCv 
>>> implementation that I have for mono based on the SharpCV wrapper (yes, 
>>> the wrapper use IntPtr and DllImport native calls :-S. With my IplImage 
>>> test I allmost succed, in the client side I can make the asignation to a 
>>> local copy of the image, something like this:
>>>
>>> CvImage frame = remOrbitKit.Video.LastIplFrame; //-> this is the remote 
>>> object property that return a "CvImage" picture type
>>> ..this work...
>>> ..but if I later try to show the image the applicatio crash with this:
>>>
>>> Unhandled Exception: System.NotSupportedException: Unsupported primitive 
>>> type: System.IntPtr
>>> Server stack trace:
>>>   at 
>>> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WritePrimitiveValue 
>>> (System.IO.BinaryWriter writer, System.Object value) [0x001b4] in 
>>> /mnt/data/opt/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectWriter.cs:898
>>>   at 
>>> System.Runtime.Serialization.Formatters.Binary.MessageFormatter.WriteMethodResponse 
>>> (System.IO.BinaryWriter writer, System.Object obj, 
>>> System.Runtime.Remoting.Messaging.Header[] headers, ISurrogateSelector 
>>> surrogateSelector, StreamingContext context, FormatterAssemblyStyle 
>>> assemblyFormat, FormatterTypeStyle typeFormat) [0x00191] in 
>>> /mnt/data/opt/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/MessageFormatter.cs:237
>>>   at 
>>> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize 
>>> (System.IO.Stream serializationStream, System.Object graph, 
>>> System.Runtime.Remoting.Messaging.Header[] headers) [0x00061] in 
>>> /mnt/data/opt/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:226
>>>
>>>
>>> I know that this may sound to a specific opencv or image question, but I 
>>> only want to know how can I traslate picture information with remoting, 
>>> I also know that may be this is not recomended due the large amount of 
>>> binary info..but I only need this for test porpuses, so bitmap, mpeg, 
>>> jpg, other streaming approach??.
>>>
>>> in advance, thank you very much.
>>>
>>> Mauricio
>>> _______________________________________________
>>> Mono-devel-list mailing list
>>> Mono-devel-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>     
>>
>>   
> 



More information about the Mono-devel-list mailing list