1

I am currently trying to save not only the skeletal data, but also the color frame images for post processing reasons. Currently, this is the section of the code that handles the color video, and outputs a color image in the UI. I figure, this is where the saving of the color frame images has to take place.

private void ColorFrameEvent(ColorImageFrameReadyEventArgs colorImageFrame)
{
    //Get raw image
    using (ColorImageFrame colorVideoFrame = colorImageFrame.OpenColorImageFrame())
    {
        if (colorVideoFrame != null)
        {
            //Create array for pixel data and copy it from the image frame
            Byte[] pixelData = new Byte[colorVideoFrame.PixelDataLength];
            colorVideoFrame.CopyPixelDataTo(pixelData);

            //Set alpha to 255
            for (int i = 3; i < pixelData.Length; i += 4)
            {
                pixelData[i] = (byte)255;
            }

            using (colorImage.GetBitmapContext())
            {
                colorImage.FromByteArray(pixelData);
            }
        }
    }
}

I have tried reading up on OpenCV, EmguCV, and multithreading; but I am pretty confused. It would be nice to have a solid good explanation in one location. However, I feel like the best way to do this without losing frames per second, would be to save all the images in a List of arrays perhaps, and then when the program finishes do some post processing to convert arrays->images->video in Matlab.

Can someone comment on how I would go about implementing saving the color image stream into a file?

famousgarkin
  • 13,687
  • 5
  • 58
  • 74
ajl123
  • 1,172
  • 5
  • 17
  • 40

1 Answers1

0

The ColorImageFrameReady event is triggered 30 seconds a second (30fps) if everything goes smoothly. I think it's rather heavy to save every picture at once.

I suggest you use a Backgroundworker, you can check if the worker is busy and if not just pass the bytes to the backgroundworker and do your magic.

You can easily save or make an image from a byte[]. Just google this.

http://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv

How to compare two images using byte arrays

Community
  • 1
  • 1
Kevin Cloet
  • 2,956
  • 1
  • 19
  • 36