[FIXED] Convert Bitmap to OpenCvSharp IplImage

Issue

I'm unfortunately struggling with this. I have a project that is mixed with Emgu and OpenCvSharp. Sounds odd but there are reasons.

At any rate, what I have is an EMGU.CV.Image that I'd like to use to populate an OpenCvSharp IplImage

I'm assuming this is possible, however I cannot wrap my head around it.

Relevant snippet of code (C#):

            FrameCapture = Cv.CreateFileCapture(@"C:\test\vid1.mp4");

            var frm = cap.QueryFrame();
            var frameBmp = frm.Bitmap;

            IplImage curFrame = ??? <<====== I'd like to create curFrame based on frameBmp

Solution

As usual, the answer is always simple.

For anyone who encounters this problem, the following is what you can do:

            var frm = cap.QueryFrame(); // this is an Emgu.CV.Image object
            var frameBmp = frm.Bitmap; // this is the bitmap from that object

            Frame = new IplImage(frameBmp.Width, frameBmp.Height, BitDepth.U8, 3);  //creates the OpenCvSharp IplImage;
            Frame.CopyFrom(frameBmp); // copies the bitmap data to the IplImage


Answered By - tronious
Answer Checked By - David Goodson (sql.easybugfix Volunteer)

Related Posts

Post a Comment