如何在使用OpenCV的Kinect传感器获得的RGB视频中使用Frame-Difference? [英] How to use Frame-Difference in the RGB video that got from the Kinect sensor with OpenCV?
问题描述
我想使用来自Kinect传感器的RGB视频中的Frame-Difference来实现前景分割
I wanna realize the foreground sementation using Frame-Difference in the RGB video that get from Kinect sensor
但是我对如何获得第1帧感到困惑,第2帧框架和.......
but I am confused with how to get the 1st frame ,2nd frame ,and.......
这里是实现获取RGB视频的主要代码。
here is the main code that implement got the RGB video.
/ ************************************** ****** /
/********************************************/
WaitForSingleObject(hEvents [0],INFINITE);
WaitForSingleObject( hEvents[0], INFINITE);
const NUI_IMAGE_FRAME * RGBFrame;
NuiImageStreamGetNextFrame(hStreams [0],NULL和 RGBFrame);
const NUI_IMAGE_FRAME *RGBFrame;
NuiImageStreamGetNextFrame( hStreams[0], NULL, &RGBFrame );
NUI_LOCKED_RECT lockedRGB;
RGBFrame-> pFrameTexture-> LockRect(NULL,& lockedRGB,NULL,NULL);
NUI_LOCKED_RECT lockedRGB;
RGBFrame->pFrameTexture->LockRect( NULL, &lockedRGB, NULL, NULL );
cvSetData( cvRGBImage,(unsigned char *)lockedRGB.pBits,lockedRGB.Pitch);
cvSetData( cvRGBImage, (unsigned char*)lockedRGB.pBits, lockedRGB.Pitch );
cvShowImage(" RGB",cvRGBImage);
cvShowImage( "RGB", cvRGBImage );
if(cvWaitKey(1)=='x'){break; }
if ( cvWaitKey( 1 ) == 'x' ){ break; }
NuiImageStreamReleaseFrame(hStreams [0],RGBFrame);
NuiImageStreamReleaseFrame( hStreams[0], RGBFrame );
/ ******** ************************************ /
/********************************************/
任何人都可以给我一些关于怎么做的建议吗?
Can anyone give me some advises about how to do it ?
(我用Opencv来做Frame-Difference)我只是无法想象如何逐个挑选框架并处理它们
(I am using Opencv to do the Frame-Difference) I just can't figure out how to pick out the frames one by one, and process them
plz help ~~~ thx~
plz help~~~thx~
推荐答案
您需要某种循环来定期检查何时新的框架可用。在Win32中,这通常在主消息循环中完成。以下是如何完成它的一般方法。如果你想要Win32特定的方式(我不是专家)在"Color Basics"中查看
。 SDK附带的示例。
You need some kind of a loop to periodically check when new frames are available. In Win32 this is usually done in the main message loop. Below is a generic way of how it can be done. If you want Win32 specific way (which I'm not an expert of) have a look at "Color Basics" sample which comes with the SDK.
// Declare handles to color stream and next frame event
void *colorStreamHandle;
void *colorNextFrameEvent;
// Initialize sensor
INuiSensor *sensor;
// ...
// Create an event
colorNextFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
// Open color stream and obtain handle to it
sensor->NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 2, colorNextFrameEvent, &colorStreamHandle);
// Events loop, you may want this in a separate thread
while(running)
{
if (WaitForSingleObject(nextColorFrameEvent, 0) == WAIT_OBJECT_0)
{
// the frame is ready
// call a function or send a signal, e.g.
processFrame();
}
Sleep(1);
}
void processFrame()
{
HRESULT hr;
NUI_IMAGE_FRAME rgbFrame;
hr = sensor->NuiImageStreamGetNextFrame(colorStreamHandle, 0, &rgbFrame);
// do what you want with the frame
}
这篇关于如何在使用OpenCV的Kinect传感器获得的RGB视频中使用Frame-Difference?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!