00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include "qvopticalflow.h"
00026
00027 void qvInitFlowGPU (TVL1_FlowEstimator * &flowEstimator, int w, int h, int nLevels, int nIterations, int nOuterIterations,
00028 double lambda, double tau, double theta) {
00029 int startLevel = 0;
00030 TVL1_FlowEstimator::Config flowCfg(tau, theta);
00031
00032 flowEstimator = new TVL1_FlowEstimator(nLevels);
00033 flowEstimator->configurePrecision(false, false, false);
00034 flowEstimator->allocate(w, h);
00035 flowEstimator->setLambda(lambda);
00036 flowEstimator->configure(flowCfg);
00037 flowEstimator->setInnerIterations(nIterations);
00038 flowEstimator->setOuterIterations(nOuterIterations);
00039 flowEstimator->setStartLevel(startLevel);
00040 }
00041
00042 void qvOpticalFlowGPU(TVL1_FlowEstimator * flowEstimator, QVPyramid* p1, QVPyramid* p2,
00043 QVImage<sFloat, 1> &x, QVImage<sFloat, 1> &y) {
00044
00045 int startLevel = 0;
00046 GLint textureWidth, textureHeight;
00047
00048 flowEstimator->run(p1->getID(), p2->getID());
00049 glFinish();
00050
00051 warpImageWithFlowField(flowEstimator->getFlowFieldTextureID(),
00052 p1->getID(), p2->getID(), startLevel,
00053 *flowEstimator->getWarpedBuffer(startLevel));
00054
00055 glActiveTexture(GL_TEXTURE0);
00056 glBindTexture(GL_TEXTURE_2D,flowEstimator->getFlowFieldTextureID());
00057 glEnable(GL_TEXTURE_2D);
00058
00059
00060 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &textureWidth);
00061 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &textureHeight);
00062
00063 glGetTexImage(GL_TEXTURE_2D, 0, GL_RED, GL_FLOAT, x.getWriteData());
00064 glGetTexImage(GL_TEXTURE_2D, 0, GL_GREEN, GL_FLOAT, y.getWriteData());
00065
00066 glDisable(GL_TEXTURE_2D);
00067 checkGLErrorsHere0();
00068 }