Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
13 Views

how to process two consecutive frame(objects dectection)

 

I want to realize the function of real-time detection of moving objects. At the moment, I only find a way that get segmented image  to dectect objects by using  3Dseg in SDK . The 3Dseg use the  depth information of image, only requiring the current frame image.But it also has some flaws

The commonly  method of moving objects detection is comparing the two consecutive frames (pixel gray level) to find out the moving objects. However,  I don't know how to deal with data of two consecutive frames to find differences in every pixel (so that i can find out whether it is belong to foreground image )between the two frame. 
 

Can you give me a example about processing two consecutive frames?
 I couldnt appreciate more if you give me some advice.

0 Kudos
7 Replies
Highlighted
Valued Contributor II
13 Views

Create two images, currentFrame, previousFrame.

When you acquire a new image, save it to currentFrame and process it. At the end of the main loop, transfer currentFrame to previousFrame.

Repeat until satisfied.

0 Kudos
Highlighted
Beginner
13 Views

samontab wrote:

Create two images, currentFrame, previousFrame.

When you acquire a new image, save it to currentFrame and process it. At the end of the main loop, transfer currentFrame to previousFrame.

Repeat until satisfied.

 

Thanks for your answer! It seems that I misunderstand the function of some  interface. 

0 Kudos
Highlighted
Beginner
13 Views

samontab wrote:

Create two images, currentFrame, previousFrame.

When you acquire a new image, save it to currentFrame and process it. At the end of the main loop, transfer currentFrame to previousFrame.

Repeat until satisfied.

I am a beginner to F200 and poor at coding..

I have found a sample in F200 ,below are the codes

what I should do is getting two consecutive image's data and  researching algorithm(this is my focus) to deal with the data.

 But now I have trouble  in first step.It maybe easy for you ,but the problem really troubles me for days.

Can you help me to add some codes to the sample?

PXCSenseManager *sm=PXCSenseManager.CreateInstance();

sm->Enable3DSeg();

sm->Init();

while (sm->AcquireFrame(true)>=PXC_STATUS_NO_ERROR) {

   PXC3DSeg *seg=sm->Query3DSeg();

      PXCImage *image=seg->AcquireSegmentedImage();

  PXCMImage.ImageData imageData = null;

  pxcmStatus acquireAccessStatus = image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out imageData);

//

i want to deal with  imageData with two consecutive frame.

I don not know where to get previousframe and deal with data with both previousframe and current frame.

      image.ReleaseAccess(imageData);

   sm->ReleaseFrame();

}

sm->Release()

 

0 Kudos
Highlighted
Valued Contributor II
13 Views

Have a look at this video tutorial that describes how to acquire frames. It follows a standard main loop procedure, so you could easily implement something like this based on that:

https://www.youtube.com/watch?v=wIkIdjN6Oyw

0 Kudos
Highlighted
Beginner
13 Views

samontab wrote:

Have a look at this video tutorial that describes how to acquire frames. It follows a standard main loop procedure, so you could easily implement something like this based on that:

 

sorry I can not watch this vedio.can you send it to my e-mail?

my e-mail address is weijie0213@163.com  or 513519532@qq.com

0 Kudos
Highlighted
Valued Contributor II
13 Views

Here is some of the code of the video that you can run. It acquires images one by one from an F200, and converts them into an OpenCV Mat, using a single thread to make it as simple as possible:

#include <pxcsensemanager.h>
#include <opencv2/opencv.hpp>

cv::Mat PXCImage2CVMat(PXCImage *pxcImage, PXCImage::PixelFormat format)
{
    PXCImage::ImageData data;
    pxcImage->AcquireAccess(PXCImage::ACCESS_READ, format, &data);

    int width = pxcImage->QueryInfo().width;
    int height = pxcImage->QueryInfo().height;

    if(!format)
        format = pxcImage->QueryInfo().format;

    int type;
    if(format == PXCImage::PIXEL_FORMAT_Y8)
        type = CV_8UC1;
    else if(format == PXCImage::PIXEL_FORMAT_RGB24)
        type = CV_8UC3;
    else if(format == PXCImage::PIXEL_FORMAT_DEPTH_F32)
        type = CV_32FC1;

    cv::Mat ocvImage = cv::Mat(cv::Size(width, height), type, data.planes[0]);

    pxcImage->ReleaseAccess(&data);
    return ocvImage;
}

int main(int argc, char* argv[])
{
    //Define some parameters for the camera
    cv::Size frameSize = cv::Size(640, 480);
    float frameRate = 60;

    //Create the OpenCV windows and images
    cv::namedWindow("IR", cv::WINDOW_NORMAL);
    cv::namedWindow("Color", cv::WINDOW_NORMAL);
    cv::namedWindow("Depth", cv::WINDOW_NORMAL);
    cv::Mat frameIR = cv::Mat::zeros(frameSize, CV_8UC1);
    cv::Mat frameColor = cv::Mat::zeros(frameSize, CV_8UC3);
    cv::Mat frameDepth = cv::Mat::zeros(frameSize, CV_8UC1);


    //Initialize the RealSense Manager
    PXCSenseManager *pxcSenseManager = PXCSenseManager::CreateInstance();

    //Enable the streams to be used
    pxcSenseManager->EnableStream(PXCCapture::STREAM_TYPE_IR, frameSize.width, frameSize.height, frameRate);
    pxcSenseManager->EnableStream(PXCCapture::STREAM_TYPE_COLOR, frameSize.width, frameSize.height, frameRate);
    pxcSenseManager->EnableStream(PXCCapture::STREAM_TYPE_DEPTH, frameSize.width, frameSize.height, frameRate);

    //Initialize the pipeline
    pxcSenseManager->Init();

    bool keepRunning = true;
    while(keepRunning)
    {
        //Acquire any frame from the camera
        pxcSenseManager->AcquireFrame(false);
        PXCCapture::Sample *sample = pxcSenseManager->QuerySample();

        //Convert each frame into an OpenCV image
        //You need to make sure that the image is there first
        if(sample->ir)
            frameIR = PXCImage2CVMat(sample->ir, PXCImage::PIXEL_FORMAT_Y8);
        if(sample->color)
            frameColor = PXCImage2CVMat(sample->color, PXCImage::PIXEL_FORMAT_RGB24);
        if(sample->depth)
            PXCImage2CVMat(sample->depth, PXCImage::PIXEL_FORMAT_DEPTH_F32).convertTo(frameDepth, CV_8UC1);

        //Display the images
        cv::imshow("IR", frameIR);
        cv::imshow("Color", frameColor);
        cv::imshow("Depth", frameDepth);

        //Check for user input
        int key = cv::waitKey(1);
        if(key == 27)
            keepRunning = false;

        //Release the memory from the frames
        pxcSenseManager->ReleaseFrame();
    }

    //Release the memory from the RealSense manager
    pxcSenseManager->Release();

    return 0;
}

 

0 Kudos
Highlighted
Beginner
13 Views

samontab wrote:

Here is some of the code of the video that you can run. It acquires images one by one from an F200, and converts them into an OpenCV Mat, using a single thread to make it as simple as possible:



 

 

Thanks for your help!

0 Kudos