31#ifndef SLIDING_WINDOW_OPTICALFLOW_OP_H_
32#define SLIDING_WINDOW_OPTICALFLOW_OP_H_
37#include "drain/image/SlidingWindow.h"
38#include "SlidingWindowOp.h"
77 typedef double data_t;
78 typedef double cumul_t;
84 void setSrcFrameWeight(
const ImageFrame & srcW){
85 Logger mout(getImgLog(),
"WeightedOpticalFlowCore", __FUNCTION__);
88 mout.
debug(
"srcWeight (view): " , this->srcWeight );
113 void setDstFrameWeight(
const ImageFrame & dstW){
121 data_t nominator()
const {
122 return static_cast<data_t
>(Gxx*Gyy - Gxy*Gxy);
128 return static_cast<data_t
>(Gxy*Gyt - Gyy*Gxt);
134 return static_cast<data_t
>(Gxy*Gxt - Gxx*Gyt);
181 size_t getDiffChannelCount() {
return 3;};
209template <
class R = OpticalFlowCore1 >
226 typedef OpticalFlowCore1::data_t data_t;
227 typedef OpticalFlowCore1::cumul_t cumul_t;
236 this->coordinateHandler.
setPolicy(this->Dx.getCoordinatePolicy());
237 this->coordinateHandler.
setLimits(this->Dx.getHeight(), this->Dy.getHeight());
251 if (! this->coordinateHandler.
validate(p))
254 address = this->Dx.address(p.x, p.y);
256 dx = this->Dx.template get<data_t>(this->address);
257 dy = this->Dy.template get<data_t>(this->address);
258 dt = this->Dt.template get<data_t>(this->address);
288 if (! this->coordinateHandler.
validate(p))
291 address = this->Dx.address(p.x, p.y);
293 dx = this->Dx.template get<data_t>(address);
294 dy = this->Dy.template get<data_t>(address);
295 dt = this->Dt.template get<data_t>(address);
316 return sqrt((this->Gtt + 2.0*(this->Gxy*u*v - this->Gxt*u - this->Gyt*v) + this->Gxx*u*u + this->Gyy*v*v)/this->W);
341 nom = this->nominator();
357 u = this->uDenominator()/nom;
358 v = this->vDenominator()/nom;
359 quality = sqrt(nom/this->W);
402 std::cerr <<
"SlidingOpticalFlow::" << __FUNCTION__ << std::endl;
407 mutable size_t address;
408 mutable data_t dx, dy, dt, w;
413 mutable data_t quality;
420 Logger mout(getImgLog(),
"SlidingOpticalFlow", __FUNCTION__);
423 this->setImageLimits();
424 this->setLoopLimits();
426 mout.
debug(
"window: " , *
this );
427 mout.debug3(
"Dx: " , this->Dx );
428 mout.debug3(
"Dy: " , this->Dy );
429 mout.debug3(
"Dt: " , this->Dt );
462 if (! coordinateHandler.
validate(p))
465 address = Dx.address(p.x, p.y);
467 dx = Dx.get<data_t>(address);
468 dy = Dy.get<data_t>(address);
469 dt = Dt.get<data_t>(address);
470 w = srcWeight.
get<data_t>(address);
493 if (! coordinateHandler.
validate(p))
496 address = Dx.address(p.x, p.y);
498 dx = Dx.get<data_t>(address);
499 dy = Dy.get<data_t>(address);
500 dt = Dt.get<data_t>(address);
501 w = srcWeight.
get<data_t>(address);
548 parameters.
append(blender.getParameters(),
false);
554 dst.
setType(
typeid(OpticalFlowCore1::data_t));
555 dst.setGeometry(src.getWidth(), src.getHeight(), 2, 1);
576 this->traverseMultiChannel(src, dst);
581 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
582 mout.
error(
"Not implemented (1/1)" );
586 size_t getDiffChannelCount()
const {
587 return window_t::getDiffChannelCount();
592 bool preSmooth()
const {
593 return !blender.getSmootherKey().empty();
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:667
Logger & error(const TT &... args)
Echoes.
Definition Log.h:417
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition ReferenceMap.h:336
Image with static geometry.
Definition ImageChannel.h:58
void setLimits(int xMin, int yMin, int xUpperLimit, int yUpperLimit)
Sets minimum values and outer upper limits for x and y.
Definition CoordinateHandler.h:147
bool validate(Point2D< int > &p) const
Handles the coordinate, returning true if the position is reversible.
Definition CoordinateHandler.h:235
void setPolicy(const CoordinatePolicy &p)
Assigns internal function pointers.
Definition CoordinateHandler.h:172
void setType(const std::type_info &t)
Set storage type.
Definition ImageConf.h:121
Definition FastOpticalFlowOp.h:542
virtual void computeDifferentials(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Computes an image with channels dx, dy, dt and w (quality of gradients). User may redefine this.
Definition FastOpticalFlowOp.cpp:114
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition FastOpticalFlowOp.h:580
virtual void getDstConf(const ImageConf &src, ImageConf &dst) const
Creates a double precision image of 2+1 channels for storing motion (uField,vField) and quality (q).
Definition FastOpticalFlowOp.h:553
Struct for image (excluding data)
Definition ImageConf.h:333
Image with static geometry.
Definition ImageFrame.h:62
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition ImageFrame.h:187
T get(size_t i) const
Gets the intensity at location i. See address().
Definition ImageFrame.h:249
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
ImageFrame that also has channels.
Definition ImageView.h:52
void setView(const ImageFrame &src)
Views the whole image.
Definition ImageView.h:65
Consider using SlidingStripeOpticalFlow instead.
Definition FastOpticalFlowOp.h:55
bool invertV
If true, negate Y so that it will increase towards top (North)
Definition FastOpticalFlowOp.h:68
bool invertU
If true, negate X so that it will increase towards left (West)
Definition FastOpticalFlowOp.h:65
Definition FastOpticalFlowOp.h:176
ImageView Dt
Precomputed time diffential.
Definition FastOpticalFlowOp.h:188
ImageView Dy
Precomputed vertical diffential.
Definition FastOpticalFlowOp.h:186
ImageView Dx
Precomputed horizontal diffential.
Definition FastOpticalFlowOp.h:184
void setSrcFrames(const ImageTray< const Channel > &srcTray)
Set inputs as channels 0:Dx, 1:Dy, 2:Dt, 3/alpha: weight.
Definition FastOpticalFlowOp.cpp:80
Definition FastOpticalFlowOp.h:73
ImageView uField
Horizontal velocity.
Definition FastOpticalFlowOp.h:94
data_t uDenominator() const
Returns the horizontal component of motion. Must be scaled by nominator().
Definition FastOpticalFlowOp.h:127
void setDstFrames(ImageTray< Channel > &dstTray)
Set outputs as channels (uField, vField, w)
Definition FastOpticalFlowOp.cpp:48
ImageView dstWeight
Quality of the velocity.
Definition FastOpticalFlowOp.h:100
ImageView vField
Vertical velocity.
Definition FastOpticalFlowOp.h:97
data_t vDenominator() const
Returns the vertical component of motion. Must be scaled by nominator().
Definition FastOpticalFlowOp.h:133
ImageView srcWeight
Precomputed weight field (optional)
Definition FastOpticalFlowOp.h:81
Definition FastOpticalFlowOp.h:449
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition FastOpticalFlowOp.h:491
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition FastOpticalFlowOp.h:460
Definition FastOpticalFlowOp.h:210
virtual void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition FastOpticalFlowOp.h:234
virtual void write()
Write the result in the target image.
Definition FastOpticalFlowOp.h:322
virtual void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition FastOpticalFlowOp.h:418
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition FastOpticalFlowOp.h:286
data_t predictionError(double u, double v) const
Returns the mean squared error of predicted.
Definition FastOpticalFlowOp.h:312
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition FastOpticalFlowOp.h:249
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition FastOpticalFlowOp.h:401
Template for operators applying pipeline-like sliding window.
Definition SlidingWindowOp.h:57
Window implementation that uses incremental update of state.
Definition SlidingWindow.h:50
Base class for configurations applied in image processing windows, e.g. for operators of type WindowO...
Definition Window.h:55
Container for source and target images, and their setters.
Definition Window.h:154
Point2D< int > location
Current location of this window.
Definition Window.h:521
Definition DataSelector.cpp:1277