简体   繁体   中英

Optical Flow - Motion histograms

I'm currently working on optical flow with OpenCV C++. I'm using calcOpticalFlowPyrLK with a grid of point (= one interest point for each 5*5 pixels square).

Which is the best way to :

1) Compute the histogram of the computed values (orientation and distance) for each frame

2) Compute an histogram of the values (orientation and distance) that a given pixel took during several frames (for instance 100)

Are the functions of OpenCV adapted for this work ? How may I use them in a simple way in combination with calcOpticalFlowPyrLK ?

I was searching for the same OpenCV tools a couple of months ago. Unfortunately, OpenCV does not include any Motion Histogram implementation. Instead, what you should have to do is to run calcOpticalFlowPyrLK for each frame and calculate the orientation/length of each displacement. Then, you have to create/fill the histograms yourself . Not as hard as it sounds, believe me :)

The OpenCV implementation for the fist part of HOOF can be like below:

const int rows = flow1.rows;
const int cols = flow1.cols;

for (int y = 0; y < rows; ++y)  
for (int x = 0; x < cols; ++x)
{
    Vec2f flow1_at_point = flow1.at<Vec2f>(y, x);
    float u1 = flow1_at_point[0];
    float v1 = flow1_at_point[1];
    magnitudeImage += sqrt((u1*u1) + (v1 + v1));
    orientationImage += atan2(u1, v1);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM