31 #ifndef SLIDING_WINDOW_OPTICALFLOW_OP_H_
32 #define SLIDING_WINDOW_OPTICALFLOW_OP_H_
34 #include <drain/image/ImageFile.h>
39 #include "SlidingWindowOp.h"
41 #include "DifferentialOp.h"
42 #include "BlenderOp.h"
79 typedef double data_t;
80 typedef double cumul_t;
86 void setSrcFrameWeight(
const ImageFrame & srcW){
87 Logger mout(getImgLog(),
"WeightedOpticalFlowCore", __FUNCTION__);
90 mout.
debug(
"srcWeight (view): " , this->srcWeight );
115 void setDstFrameWeight(
const ImageFrame & dstW){
123 data_t nominator()
const {
124 return static_cast<data_t
>(Gxx*Gyy - Gxy*Gxy);
130 return static_cast<data_t
>(Gxy*Gyt - Gyy*Gxt);
136 return static_cast<data_t
>(Gxy*Gxt - Gxx*Gyt);
183 size_t getDiffChannelCount() {
return 3;};
211 template <
class R = OpticalFlowCore1 >
228 typedef OpticalFlowCore1::data_t data_t;
229 typedef OpticalFlowCore1::cumul_t cumul_t;
238 this->coordinateHandler.
setPolicy(this->Dx.getCoordinatePolicy());
239 this->coordinateHandler.
setLimits(this->Dx.getHeight(), this->Dy.getHeight());
253 if (! this->coordinateHandler.
validate(p))
256 address = this->Dx.address(p.x, p.y);
258 dx = this->Dx.template get<data_t>(this->address);
259 dy = this->Dy.template get<data_t>(this->address);
260 dt = this->Dt.template get<data_t>(this->address);
290 if (! this->coordinateHandler.
validate(p))
293 address = this->Dx.address(p.x, p.y);
295 dx = this->Dx.template get<data_t>(address);
296 dy = this->Dy.template get<data_t>(address);
297 dt = this->Dt.template get<data_t>(address);
318 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);
343 nom = this->nominator();
359 u = this->uDenominator()/nom;
360 v = this->vDenominator()/nom;
361 quality = sqrt(nom/this->W);
404 std::cerr <<
"SlidingOpticalFlow::" << __FUNCTION__ << std::endl;
409 mutable size_t address;
410 mutable data_t dx, dy, dt, w;
415 mutable data_t quality;
422 Logger mout(getImgLog(),
"SlidingOpticalFlow", __FUNCTION__);
425 this->setImageLimits();
426 this->setLoopLimits();
428 mout.
debug(
"window: " , *
this );
429 mout.debug3(
"Dx: " , this->Dx );
430 mout.debug3(
"Dy: " , this->Dy );
431 mout.debug3(
"Dt: " , this->Dt );
464 if (! coordinateHandler.
validate(p))
467 address = Dx.address(p.x, p.y);
469 dx = Dx.get<data_t>(address);
470 dy = Dy.get<data_t>(address);
471 dt = Dt.get<data_t>(address);
472 w = srcWeight.
get<data_t>(address);
495 if (! coordinateHandler.
validate(p))
498 address = Dx.address(p.x, p.y);
500 dx = Dx.get<data_t>(address);
501 dy = Dy.get<data_t>(address);
502 dt = Dt.get<data_t>(address);
503 w = srcWeight.
get<data_t>(address);
550 parameters.
append(blender.getParameters(),
false);
556 dst.
setType(
typeid(OpticalFlowCore1::data_t));
557 dst.setGeometry(src.getWidth(), src.getHeight(), 2, 1);
578 this->traverseMultiChannel(src, dst);
583 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
584 mout.
error(
"Not implemented (1/1)" );
588 size_t getDiffChannelCount()
const {
589 return window_t::getDiffChannelCount();
594 bool preSmooth()
const {
595 return !blender.getSmootherKey().empty();
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition: ReferenceMap.h:320
Image with static geometry.
Definition: ImageChannel.h:60
void setLimits(int xMin, int yMin, int xUpperLimit, int yUpperLimit)
Sets minimum values and outer upper limits for x and y.
Definition: CoordinateHandler.h:135
bool validate(Point2D< int > &p) const
Handles the coordinate, returning true if the position is reversible.
Definition: CoordinateHandler.h:223
void setPolicy(const CoordinatePolicy &p)
Assigns internal function pointers.
Definition: CoordinateHandler.h:160
void setType(const std::type_info &t)
Set storage type.
Definition: ImageConf.h:121
Definition: FastOpticalFlowOp.h:544
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:116
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition: FastOpticalFlowOp.h:582
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:555
Struct for image (excluding data)
Definition: ImageConf.h:333
Image with static geometry.
Definition: ImageFrame.h:67
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition: ImageFrame.h:192
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
Container applicable for Channels and Images, with alpha support.
Definition: ImageTray.h:267
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:57
bool invertV
If true, negate Y so that it will increase towards top (North)
Definition: FastOpticalFlowOp.h:70
bool invertU
If true, negate X so that it will increase towards left (West)
Definition: FastOpticalFlowOp.h:67
Definition: FastOpticalFlowOp.h:178
ImageView Dt
Precomputed time diffential.
Definition: FastOpticalFlowOp.h:190
ImageView Dy
Precomputed vertical diffential.
Definition: FastOpticalFlowOp.h:188
ImageView Dx
Precomputed horizontal diffential.
Definition: FastOpticalFlowOp.h:183
void setSrcFrames(const ImageTray< const Channel > &srcTray)
Set inputs as channels 0:Dx, 1:Dy, 2:Dt, 3/alpha: weight.
Definition: FastOpticalFlowOp.cpp:82
Definition: FastOpticalFlowOp.h:75
ImageView uField
Horizontal velocity.
Definition: FastOpticalFlowOp.h:91
data_t uDenominator() const
Returns the horizontal component of motion. Must be scaled by nominator().
Definition: FastOpticalFlowOp.h:129
void setDstFrames(ImageTray< Channel > &dstTray)
Set outputs as channels (uField, vField, w)
Definition: FastOpticalFlowOp.cpp:50
ImageView dstWeight
Quality of the velocity.
Definition: FastOpticalFlowOp.h:102
ImageView vField
Vertical velocity.
Definition: FastOpticalFlowOp.h:99
data_t vDenominator() const
Returns the vertical component of motion. Must be scaled by nominator().
Definition: FastOpticalFlowOp.h:135
ImageView srcWeight
Precomputed weight field (optional)
Definition: FastOpticalFlowOp.h:83
Definition: FastOpticalFlowOp.h:451
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition: FastOpticalFlowOp.h:493
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition: FastOpticalFlowOp.h:462
Definition: FastOpticalFlowOp.h:212
virtual void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition: FastOpticalFlowOp.h:236
virtual void write()
Write the result in the target image.
Definition: FastOpticalFlowOp.h:324
virtual void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition: FastOpticalFlowOp.h:420
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition: FastOpticalFlowOp.h:288
data_t predictionError(double u, double v) const
Returns the mean squared error of predicted.
Definition: FastOpticalFlowOp.h:314
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition: FastOpticalFlowOp.h:251
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: FastOpticalFlowOp.h:403
Template for operators applying pipeline-like sliding window.
Definition: SlidingWindowOp.h:59
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:56
Container for source and target images, and their setters.
Definition: Window.h:156
Point2D< int > location
Current location of this window.
Definition: Window.h:520
Definition: DataSelector.cpp:1277