资源简介
斯坦福一牛人的稀疏光流法源码+PPT+注释。我附加opencv开发库及我的运行结果。
代码片段和文件信息
/* --稀疏光流示例程序--
* Written by David Stavens (david.stavens@ai.stanford.edu)
*/
#include
#include
#include
#include
static const double pi = 3.14159265358979323846;
inline static double square(int a)
{
return a * a;
}
/* This is just an inline that allocates images. I did this to reduce clutter in the
* actual computer vision algorithmic code. Basically it allocates the requested image
* unless that image is already non-NULL. It always leaves a non-NULL image as-is even
* if that image‘s size depth and/or channels are different than the request.
*/
inline static void allocateOnDemand(IplImage **img CvSize size int depth int channels)
{
if (*img != NULL) return;
*img = cvCreateImage(size depth channels);
if (*img == NULL)
{
fprintf(stderr “Error: Couldn‘t allocate image. Out of memory?\n“);
exit(-1);
}
}
int main(void)
{
/* Create an object that decodes the input video stream. */
CvCapture *input_video = cvCaptureFromFile(
“C://Users//caigaojian//Desktop//桌面//view//avi.avi“
);
if (input_video == NULL)
{
/* Either the video didn‘t exist OR it uses a codec OpenCV
* doesn‘t support.
*/
fprintf(stderr “Error: Can‘t open video.\n“);
return -1;
}
/* Read the video‘s frame size out of the AVI. */
CvSize frame_size;
frame_size.height =
(int)cvGetCaptureProperty(input_video CV_CAP_PROP_frame_HEIGHT);
frame_size.width =
(int)cvGetCaptureProperty(input_video CV_CAP_PROP_frame_WIDTH);
/* Determine the number of frames in the AVI. */
long number_of_frames;
/* Go to the end of the AVI (ie: the fraction is “1“) */
cvSetCaptureProperty(input_video CV_CAP_PROP_POS_AVI_RATIO 1.);
/* Now that we‘re at the end read the AVI position in frames */
number_of_frames = (int)cvGetCaptureProperty(input_video CV_CAP_PROP_POS_frameS);
/* Return to the beginning */
cvSetCaptureProperty(input_video CV_CAP_PROP_POS_frameS 0.);
/* Create a windows called “Optical Flow“ for visualizing the output.
* Have the window automatically change its size to match the output.
*/
cvNamedWindow(“Optical Flow“ CV_WINDOW_AUTOSIZE);
long current_frame = 0;
while (true)
{
static IplImage *frame = NULL *frame1 = NULL *frame1_1C = NULL *frame2_1C = NULL *eig_image = NULL *temp_image = NULL *pyramid1 = NULL *pyramid2 = NULL;
/* Go to the frame we want. Important if multiple frames are queried in
* the loop which they of course are for optical flow. Note that the very
* first call to this is actually not needed. (Because the correct position
* is set outsite the for() loop.)
*/
cvSetCaptureProperty(input_video CV_CAP_PROP_POS_frameS current_frame);
/* Get the next frame of the v
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 69632 2016-07-21 10:26 optical_flow\bin\20160721stavens.exe
文件 431056 2016-07-21 10:26 optical_flow\bin\20160721stavens.ilk
文件 1133568 2016-07-21 10:26 optical_flow\bin\20160721stavens.pdb
文件 184 2016-07-21 10:58 optical_flow\bin\说明.txt
文件 13100 2016-07-21 10:38 optical_flow\main.cpp
文件 13974216 2016-07-21 10:39 optical_flow\opcv.rar
文件 2160607 2009-12-25 14:57 optical_flow\stavens_opencv_optical_flow.pdf
文件 412 2016-07-21 11:00 optical_flow\说明.txt
目录 0 2016-07-21 10:54 optical_flow\bin
目录 0 2016-07-21 10:51 optical_flow
----------- --------- ---------- ----- ----
17782775 10
- 上一篇:最优控制习题集含答案
- 下一篇:用opencv实现全景图拼接
评论
共有 条评论