AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

i want to see calculation pixel in class TwoFramesDifference

The forum is to discuss topics related to different areas of image processing and computer vision.

i want to see calculation pixel in class TwoFramesDifference

Postby jembatanpatah » Fri May 12, 2017 4:45 pm

how to convert (byte* prevFrame and byte* currFrame) or (previousFrame and motionFrame) to Datagridview on Windows form C# ???
i don't understand with the method code in TwoFrameDifferenceDetector class..
Can you give me the code to retrieve the value of the variable =(byte* prevFrame and byte* currFrame) or (previousFrame and motionFrame)
please helpme

public unsafe void ProcessFrame( UnmanagedImage videoFrame )
{
lock ( sync )
{
// check previous frame
if ( previousFrame == null )
{
// save image dimension
width = videoFrame.Width;
height = videoFrame.Height;

// alocate memory for previous and current frames
previousFrame = UnmanagedImage.Create( width, height, PixelFormat.Format8bppIndexed );
motionFrame = UnmanagedImage.Create( width, height, PixelFormat.Format8bppIndexed );

frameSize = motionFrame.Stride * height;

// temporary buffer
if ( suppressNoise )
{
tempFrame = UnmanagedImage.Create( width, height, PixelFormat.Format8bppIndexed );
}

// convert source frame to grayscale
Tools.ConvertToGrayscale( videoFrame, previousFrame );

return;
}

// check image dimension
if ( ( videoFrame.Width != width ) || ( videoFrame.Height != height ) )
return;

// convert current image to grayscale
Tools.ConvertToGrayscale( videoFrame, motionFrame );

// pointers to previous and current frames
byte* prevFrame = (byte*) previousFrame.ImageData.ToPointer( );
byte* currFrame = (byte*) motionFrame.ImageData.ToPointer( );
// difference value
int diff;

// 1 - get difference between frames
// 2 - threshold the difference
// 3 - copy current frame to previous frame
for ( int i = 0; i < frameSize; i++, prevFrame++, currFrame++ )
{
// difference
diff = (int) *currFrame - (int) *prevFrame;
// copy current frame to previous
*prevFrame = *currFrame;
// treshold
*currFrame = ( ( diff >= differenceThreshold ) || ( diff <= differenceThresholdNeg ) ) ? (byte) 255 : (byte) 0;
}

if ( suppressNoise )
{
// suppress noise and calculate motion amount
AForge.SystemTools.CopyUnmanagedMemory( tempFrame.ImageData, motionFrame.ImageData, frameSize );
erosionFilter.Apply( tempFrame, motionFrame );
}

// calculate amount of motion pixels
pixelsChanged = 0;
byte* motion = (byte*) motionFrame.ImageData.ToPointer( );

for ( int i = 0; i < frameSize; i++, motion++ )
{
pixelsChanged += ( *motion & 1 );
}
}
}
jembatanpatah
 
Posts: 1
Joined: Fri May 05, 2017 6:19 pm



Return to Image Processing and Computer Vision

cron