31 #ifndef SLIDINGWINDOWOPTICALFLOWOP2_H_
32 #define SLIDINGWINDOWOPTICALFLOWOP2_H_
34 #include <drain/image/ImageFile.h>
38 #include "drain/util/Fuzzy.h"
40 #include "FastOpticalFlowOp.h"
58 size_t getDiffChannelCount(){
return 5;};
92 template <
class R = OpticalFlowCore2 >
99 w = u = v = nom = quality = 0.0;
104 w = u = v = nom = quality = 0.0;
111 typedef OpticalFlowCore1::data_t data_t;
112 typedef OpticalFlowCore1::cumul_t cumul_t;
117 this->coordinateHandler.
setPolicy(this->GXX.getCoordinatePolicy());
118 this->coordinateHandler.
setLimits(this->GXX.getWidth(), this->GXX.getHeight());
129 Logger mout(getImgLog(),
"SlidingOpticalFlow", __FUNCTION__);
130 mout.
error(
"unimplemented" );
151 Logger mout(getImgLog(),
"SlidingOpticalFlow", __FUNCTION__);
152 mout.
error(
"unimplemented" );
190 nom = this->nominator();
208 if (nom > 0.00000001){
210 u = this->uDenominator()/nom;
211 v = this->vDenominator()/nom;
216 quality = sqrt(nom/this->W);
217 this->dstWeight.put(this->
location, sigmoid(quality));
220 this->uField.put(this->
location, 0);
221 this->vField.put(this->
location, 0);
222 this->dstWeight.put(this->
location, 0);
236 mutable size_t address;
243 mutable data_t quality;
250 Logger mout(getImgLog(),
"SlidingOpticalFlow2", __FUNCTION__);
252 this->setImageLimits();
253 this->setLoopLimits();
254 this->location.setLocation(0,0);
256 mout.
debug(
"window: " , *
this );
258 mout <<
"GXX: " << this->GXX <<
'\n';
259 mout <<
"GXY: " << this->GXY <<
'\n';
260 mout <<
"GXX: " << this->GYY <<
'\n';
261 mout <<
"GXX: " << this->GXT <<
'\n';
262 mout <<
"GXX: " << this->GYT <<
'\n';
263 mout <<
"W: " << this->srcWeight <<
'\n';
298 if (! this->coordinateHandler.
validate(p))
301 address = this->GXX.address(p.x, p.y);
307 w = this->srcWeight.get<data_t>(address);
311 Gxx += this->GXX.get<data_t>(address);
312 Gxy += this->GXY.get<data_t>(address);
313 Gyy += this->GYY.get<data_t>(address);
314 Gxt += this->GXT.get<data_t>(address);
315 Gyt += this->GYT.get<data_t>(address);
323 if (! this->coordinateHandler.
validate(p))
326 address = this->GXX.address(p.x, p.y);
329 w = this->srcWeight.get<data_t>(address);
333 Gxx -= this->GXX.get<data_t>(address);
334 Gxy -= this->GXY.get<data_t>(address);
335 Gyy -= this->GYY.get<data_t>(address);
336 Gxt -= this->GXT.get<data_t>(address);
337 Gyt -= this->GYT.get<data_t>(address);
375 typedef window_t::data_t data_t;
383 parameters.link(
"resize", resize = 0,
"0.0..1.0|pix");
384 parameters.link(
"threshold", threshold = NAN,
"value");
385 parameters.link(
"spread", spread = 0,
"0|1");
386 parameters.link(
"smooth", smoother = 0,
"0|1");
387 setSize(width, height);
393 parameters.
copyStruct(op.getParameters(), op, *
this);
402 dst.
setType(
typeid(OpticalFlowCore2::data_t));
403 dst.setArea(src.getGeometry());
404 dst.setChannelCount(2, 1);
408 size_t getDiffChannelCount()
const {
409 return window_t::getDiffChannelCount();
414 this->traverseMultiChannel(src, dst);
422 void computeDifferentials(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const;
427 void preprocess(
const Channel & srcImage,
const Channel & srcWeight, Image & dstImage, Image & dstWeight)
const;
455 bool optSpread()
const {
return spread; };
458 bool optSmoother()
const {
return smoother; };
463 bool checkQuality(
const Channel & alpha, std::size_t address,
int DX,
int DY)
const {
465 if (alpha.get<data_t>(address) == 0.0)
468 if (alpha.get<data_t>(address + DX) == 0.0)
471 if (alpha.get<data_t>(address - DX) == 0.0)
474 if (alpha.get<data_t>(address + DY) == 0.0)
477 if (alpha.get<data_t>(address - DY) == 0.0)
A smooth step function, by default from -1.0 to +1.0.
Definition: Fuzzy.h:497
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
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition: ReferenceMap.h:399
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: FastOpticalFlowOp2.h:371
virtual void computeDifferentials(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Computes an image with channels Gxx, Gxy, Gyy, Gxt, Gyt and w (quality of gradients)....
Definition: FastOpticalFlowOp2.cpp:189
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: FastOpticalFlowOp2.h:400
bool optResize() const
Returns true, if resizing is requested.
Definition: FastOpticalFlowOp2.h:437
bool optThreshold() const
Returns true, if threshold is requested as postprocessing.
Definition: FastOpticalFlowOp2.h:452
bool optPreprocess() const
Returns true, if resizing, thresholding or smoothing is requested.
Definition: FastOpticalFlowOp2.h:431
Struct for image (excluding data)
Definition: ImageConf.h:333
Container applicable for Channels and Images, with alpha support.
Definition: ImageTray.h:267
ImageFrame that also has channels.
Definition: ImageView.h:52
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: FastOpticalFlowOp2.h:52
void setSrcFrames(const ImageTray< const Channel > &srcTray)
Set inputs as channels.
Definition: FastOpticalFlowOp2.cpp:53
Definition: FastOpticalFlowOp.h:75
Currently not in use. See SlidingOpticalFlowWeighted2 below.
Definition: FastOpticalFlowOp2.h:93
virtual void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition: FastOpticalFlowOp2.h:116
virtual void write()
Returns the mean squared error of predicted.
Definition: FastOpticalFlowOp2.h:187
virtual void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition: FastOpticalFlowOp2.h:248
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition: FastOpticalFlowOp2.h:149
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition: FastOpticalFlowOp2.h:127
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition: FastOpticalFlowOp2.h:230
Definition: FastOpticalFlowOp2.h:285
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition: FastOpticalFlowOp2.h:321
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition: FastOpticalFlowOp2.h:296
Template for operators applying pipeline-like sliding window.
Definition: SlidingWindowOp.h:59
Window implementation that uses incremental update of state.
Definition: SlidingWindow.h:50
Point2D< int > location
Current location of this window.
Definition: Window.h:520
Definition: DataSelector.cpp:1277