AnsweredAssumed Answered

How to use apexcv::LKPyramidOpticalFlow

Question asked by user123 on May 13, 2020
Latest reply on May 14, 2020 by bpe

According to The APEX-CV Library document, apexcv::LKPyramidOpticalFlow::Initialize has following arguments: aSrc0Desc, aSrc1Desc, aCoor0Desc, aCoor1Desc, aCoor1Desc_O.
I want to know meaning of aCoor0Desc, aCoor1Desc, and aCoor1Desc_O.

 

The arguments of apexcv::LKPyramidOpticalFlow is not corresponding to OpenCV function (cv::calcOpticalFlowPyrLK).

I think aCoor0Desc and aCoor1Desc are input point list which is tracking feature of aSrc0Desc and aSrc1Desc, and aCoor1Desc_O is output point list which is detected flow.

However, on my code, X/Y coordinate of aCoor1Desc_O becomes always (0,0) even if "reverve" field in output "Feature32S" is 1.

 

my code:

// Prepare buffer

const int CORNERS_MAX = 400;
uint8_t features_cur_[sizeof(icp::Feature32S) * CORNERS_MAX] = {0};
uint8_t features_prev_[sizeof(icp::Feature32S) * CORNERS_MAX] = {0};
uint8_t features_out_[sizeof(icp::Feature32S) * CORNERS_MAX] = {0};
icp::Feature32SDescriptor features_cur((void *)features_cur_, (void *)features_cur_, CORNERS_MAX);
icp::Feature32SDescriptor features_prev((void *)features_prev_, (void *)features_prev_, CORNERS_MAX);
icp::Feature32SDescriptor features_out((void *)features_out_, (void *)features_out_, CORNERS_MAX);
{
    std::vector<cv::Point2f> features_cur_v;
    std::vector<cv::Point2f> features_prev_v;
    cv::goodFeaturesToTrack((cv::UMat)frame_prev, features_prev_v, CORNERS_MAX, 0.01, 3.0, cv::Mat(), 7, true, 0.08); // use OpenCV GFTT
    cv::goodFeaturesToTrack((cv::UMat)frame_cur, features_cur_v, CORNERS_MAX, 0.01, 3.0, cv::Mat(), 7, true, 0.08);
    for(cv::Point2f feature_cur : features_cur_v)
    {
        features_cur.Add(((int)feature_cur.x) << 8, ((int)feature_cur.y) << 8);
        features_out.Add(((int)feature_cur.x) << 8, ((int)feature_cur.y) << 8); // apexcv::LKPyramidOpticalFlow requires features_out.getCount() >= features_cur.getCount()
    }
    for(cv::Point2f feature_prev : features_prev_v)
    {
        features_prev.Add(((int)feature_prev.x) << 8, ((int)feature_prev.y) << 8);
    }
}

 

// Execute ApexCV
apexcv::LKPyramidOpticalFlow apex_processor;
apex_processor.Initialize(
    /*aSrc0Desc*/ frame_prev,
    /*aSrc1Desc*/ frame_cur,
    /*aCoor0Desc*/ features_prev,
    /*aCoor1Desc*/ features_cur,
    /*aCoor1Desc_O*/ features_out,
    /*aMaxCorners*/ CORNERS_MAX,
    /*aW*/ frame_cur.cols, /*aH*/ frame_cur.rows, /*aPyrLayers*/ 4, /*aBoxSize*/ 7, /*aNumIter*/ 10, /*aReqPadding*/1
);
apex_processor.Process();

Outcomes