none
Region of interest ROI RRS feed

  • Question

  • Hello

    I'm trying to crop a rectangular region of a video RGB. First i found the coordinates of head joint and with this coordinates i drew a rectangle over the RGB video. Now i want to show in another video just the image that is inside of the rentangle in the first image.  Any help would be great

    thank you so much

     


    Rafael Poveda
    Thursday, September 29, 2011 2:47 AM

Answers

  • Well, the easiest way to do that depends on the UI framework you're using. If you're using WPF then you can basically create a BitmapSource object as shown in nui_ColorFrameReady method in SkeletalViewer sample and then copy the region of interest to a different BitmapSource:

    BitmapSource wholeImage = BitmapSource.Create(
                    Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
    Int32Rect regionCoords = new Int32Rect(100,100,200,200);
    byte[] regionData = new byte[200 * 200 * Image.BytesPerPixel];
    wholeImage.CopyPixels(regionCoords, regionData, 200 * Image.BytesPerPixel, 0);
    BitmapSource regionImage = BitmapSource.Create(
                    200, 200, 96, 96, PixelFormats.Bgr32, null, regionData, 200 * Image.BytesPerPixel);
    video.Source = wholeImage;
    region.Source = regionImage;

    And here I'm assuming that you created an <Image Name="region" .../> element in MainWindow.xaml, and also that your region of interest is the rectangle with (top,left) = (100,100) and (bottom,right) = (300,300), but these should be easy to generalize.

    Eddy


    I'm here to help
    Friday, September 30, 2011 12:50 AM

All replies

  • Well, the easiest way to do that depends on the UI framework you're using. If you're using WPF then you can basically create a BitmapSource object as shown in nui_ColorFrameReady method in SkeletalViewer sample and then copy the region of interest to a different BitmapSource:

    BitmapSource wholeImage = BitmapSource.Create(
                    Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
    Int32Rect regionCoords = new Int32Rect(100,100,200,200);
    byte[] regionData = new byte[200 * 200 * Image.BytesPerPixel];
    wholeImage.CopyPixels(regionCoords, regionData, 200 * Image.BytesPerPixel, 0);
    BitmapSource regionImage = BitmapSource.Create(
                    200, 200, 96, 96, PixelFormats.Bgr32, null, regionData, 200 * Image.BytesPerPixel);
    video.Source = wholeImage;
    region.Source = regionImage;

    And here I'm assuming that you created an <Image Name="region" .../> element in MainWindow.xaml, and also that your region of interest is the rectangle with (top,left) = (100,100) and (bottom,right) = (300,300), but these should be easy to generalize.

    Eddy


    I'm here to help
    Friday, September 30, 2011 12:50 AM
  • There is a bunch of related info to your question, without which it seems difficult to answer. For example, are you using C# or C++? WPF or Windows Forms? What is the format of your video? Do you need to save the video to file, or is it simply for display only?

    Your question is how to "show in another video just the [ROI]". The easy way to achieve this in WPF will be to use negative margins on the image and display it in front of the video. But this is for display only.

    Friday, September 30, 2011 12:53 AM
  • Thank you so much... that's exactly what i'm looking for
    Rafael Poveda
    Saturday, October 1, 2011 3:34 PM