none
Getting incorrect/random color channel data RRS feed

  • Question

  • I have the Colorstream data displayed in a 640x480 rgb32 WriteableBitmap, and just want to see if I can get separate RGB data for any pixel that I click on in the image, starting with red. The values I'm getting are quite random and don't seem correct at all. I don't think it really matters whether the data is structured as RGB or BGR as the values I get don't have any real consistency when I click on multiple points on an object with constant color. Any ideas?

    private void KinectDevice_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
    
     if (this._LastColorFrame != null)
                    {
                        this._LastColorFrame.Dispose();
                        this._LastColorFrame = null;
                    }
                        this._LastColorFrame = e.OpenColorImageFrame();
    
                        if (this._LastColorFrame != null)
                        {
                            this._LastColorFrame.CopyPixelDataTo(this._ColorPixelData);
                           this._ColorImage.WritePixels(this._ColorImageRect, this._ColorPixelData, this._ColorImageStride,0);                      
                        }
    }
    
    
     private void canvas1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                Point p = e.GetPosition(canvas1);
                                        
                int x = Convert.ToInt32(p.X);
                int y = Convert.ToInt32(p.Y);
    
     if (this._ColorPixelData != null && this._ColorPixelData.Length > 0)
                {
                    _ColorImageStride = _KinectDevice.ColorStream.FrameBytesPerPixel * _KinectDevice.ColorStream.FrameWidth;
    
                    byte red = _ColorPixelData[x + (y * _ColorImageStride)];
    
                    textBox4.Text = Convert.ToString(red);
                }
    }

    Tuesday, July 3, 2012 5:27 PM

Answers

  • Fixed. Changing _ColorPixelData[x + (y * _ColorImageStride)]

    to   _ColorPixelData[(x + (y * 640)) * 4] seemed to fix it.

    • Marked as answer by Luke24dub Tuesday, July 3, 2012 8:50 PM
    Tuesday, July 3, 2012 8:50 PM