2
I’m working with the OPENCVSHARP (Opencv) to access a camera Ps3eye (Playstation 3) camera in C#.
But I am having a serious problem with protected memory! I use visual studio 2010 on Windows7.
Code:
IntPtr _ptr;
public IntPtr _ptrBmpPixels;
static IntPtr _camera;
static int w = 0, h = 0;
public void button2_Click(object sender, EventArgs e)
{
_camera = CLEyeCreateCamera(CameraUUID(0), CLEyeCameraColorMode.CLEYE_COLOR_RAW, CLEyeCameraResolution.CLEYE_VGA, 75);
CLEyeCameraGetFrameDimensions(_camera, ref w, ref h);
CLEyeCameraStart(_camera);
_ptrBmpPixels = Marshal.AllocHGlobal(w * h * 4);
RtlZeroMemory(_ptrBmpPixels, w * h * 4);
Bitmap bmpGraph = new Bitmap(w, h, w * 4, PixelFormat.Format32bppRgb, _ptrBmpPixels);
pictureBox2.Image = bmpGraph;
myTimer2.Enabled = true;
}
public void timer2(object sender, EventArgs e)
{
CvInvoke.cvQueryFrame(_camera);// AQUI ESTÁ O ERRO ao ACESSAR O "_camera"
CLEyeCameraGetFrame( _camera,_ptrBmpPixels,500);
pictureBox2.Invalidate();
//IntPtr img = CvInvoke.cvQueryFrame(_ptrBmpPixels);
//IplImage iplImage = (IplImage)Marshal.PtrToStructure(img, typeof(IplImage));
Bitmap bmpGraph = new Bitmap (160, 480, 640, PixelFormat.Format32bppRgb, _ptrBmpPixels);
IplImage mp = Cv.CreateImage(Cv.Size(bmpGraph.Width, bmpGraph.Height), BitDepth.U8, 3);
//learn(mp, bmpGraph);
}