C#, WinForms, and Bitmap
Posted: 11 August 2015 04:17 PM   [ Ignore ]
New Member
Rank
Total Posts:  3
Joined  2015-08-11

I’m trying to get a full color QVGA image from the PS3 Eye at 187 frames per second.
I modified the sample called “CLEyeWinFormsTest” in the following ways:

void OnLoaded(object senderEventArgs e)
        
{
            int w 
00;
            
_camera CLEyeCreateCamera(CameraUUID(0), CLEyeCameraColorMode.CLEYE_COLOR_PROCESSEDCLEyeCameraResolution.CLEYE_QVGA187);
            if (
_camera == IntPtr.Zero) return;
            
CLEyeCameraGetFrameDimensions(_cameraref wref h);
            
CreateBitmap(wh);
            
// create thread exit event
            
_exitEvent = new ManualResetEvent(false);
            
// start capture here
            
ThreadPool.QueueUserWorkItem(Capture);
        
}

        void CreateBitmap
(int wint h)
        
{
            
// allocate bitmap memory
            
_ptrBmpPixels Marshal.AllocHGlobal(h);
            
RtlZeroMemory(_ptrBmpPixelsh);

            
// create bitmap object
            
Bitmap bmpGraph = new Bitmap(whwPixelFormat.Format32bppRgb_ptrBmpPixels);

            
// setup gray-scale palette
            //ColorPalette GrayPalette = bmpGraph.Palette;
            //for (int i = 0; i < GrayPalette.Entries.Length; i++)
            //    GrayPalette.Entries[i] = Color.FromArgb(i, i, i);
            //bmpGraph.Palette = GrayPalette;

            // set bitmap to the picture box
            
_form.pictureBox1.Image bmpGraph;
        

However, when this runs it crashes and complains about memory access problems. In particular this is thrown:

Unhandled exception at 0x72E6E64B (clr.dllin CLEyeWinFormsTest.exe0xC0000005Access violation reading location 0x00050400.

If 
there is a handler for this exceptionthe program may be safely continued

Followed by a whole bunch of these:

Exception thrown at 0x72E6E64B (clr.dllin CLEyeWinFormsTest.exe0xC0000005Access violation reading location 0x00050400.

If 
there is a handler for this exceptionthe program may be safely continued

I haven’t been able to tell what’s causing it, but my best guess is that the Bitmap object isn’t setup correctly. Can anyone shed some light on this?

Thanks.

Profile
 
 
Posted: 13 August 2015 10:45 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

Hello,

You seem to be allocating w*h bytes for an 32bit image that should be w*h*4.

Please take a look at the following lines of code:

_ptrBmpPixels Marshal.AllocHGlobal(h);
RtlZeroMemory(_ptrBmpPixels4); 

and change to:

_ptrBmpPixels Marshal.AllocHGlobal(4);
RtlZeroMemory(_ptrBmpPixels4); 

Hope that helps.

Profile
 
 
Posted: 13 August 2015 11:29 AM   [ Ignore ]   [ # 2 ]
New Member
Rank
Total Posts:  3
Joined  2015-08-11
AlexP - 13 August 2015 10:45 AM

and change to:

_ptrBmpPixels Marshal.AllocHGlobal(4);
RtlZeroMemory(_ptrBmpPixels4); 

Hope that helps.

Of course! Thanks for the second set of eyes. That does help; it’s not crashing anymore. However, I think I’m still using the wrong format. Here’s the output (attached).

Is the CLEYE_COLOR_PROCESSED mode indeed 32-bit RGB? It’s almost like the stride is offset or something. Thoughts?

Thanks again.

Image Attachments
ps3eye_bad.png
Profile
 
 
 
 


RSS 2.0     Atom Feed