31#ifndef SLIDINGWINDOWOPTICALFLOWOP2_H_
32#define SLIDINGWINDOWOPTICALFLOWOP2_H_
36#include "drain/util/Fuzzy.h"
38#include "FastOpticalFlowOp.h"
56 size_t getDiffChannelCount(){
return 5;};
90template <
class R = OpticalFlowCore2 >
97 w = u = v = nom = quality = 0.0;
102 w = u = v = nom = quality = 0.0;
109 typedef OpticalFlowCore1::data_t data_t;
110 typedef OpticalFlowCore1::cumul_t cumul_t;
115 this->coordinateHandler.
setPolicy(this->GXX.getCoordinatePolicy());
116 this->coordinateHandler.
setLimits(this->GXX.getWidth(), this->GXX.getHeight());
127 Logger mout(getImgLog(),
"SlidingOpticalFlow", __FUNCTION__);
128 mout.
error(
"unimplemented" );
149 Logger mout(getImgLog(),
"SlidingOpticalFlow", __FUNCTION__);
150 mout.
error(
"unimplemented" );
188 nom = this->nominator();
206 if (nom > 0.00000001){
208 u = this->uDenominator()/nom;
209 v = this->vDenominator()/nom;
214 quality = sqrt(nom/this->W);
215 this->dstWeight.put(this->
location, sigmoid(quality));
218 this->uField.put(this->
location, 0);
219 this->vField.put(this->
location, 0);
220 this->dstWeight.put(this->
location, 0);
234 mutable size_t address;
241 mutable data_t quality;
248 Logger mout(getImgLog(),
"SlidingOpticalFlow2", __FUNCTION__);
250 this->setImageLimits();
251 this->setLoopLimits();
252 this->location.setLocation(0,0);
254 mout.
debug(
"window: " , *
this );
256 mout <<
"GXX: " << this->GXX <<
'\n';
257 mout <<
"GXY: " << this->GXY <<
'\n';
258 mout <<
"GXX: " << this->GYY <<
'\n';
259 mout <<
"GXX: " << this->GXT <<
'\n';
260 mout <<
"GXX: " << this->GYT <<
'\n';
261 mout <<
"W: " << this->srcWeight <<
'\n';
296 if (! this->coordinateHandler.
validate(p))
299 address = this->GXX.address(p.x, p.y);
305 w = this->srcWeight.get<data_t>(address);
309 Gxx += this->GXX.get<data_t>(address);
310 Gxy += this->GXY.get<data_t>(address);
311 Gyy += this->GYY.get<data_t>(address);
312 Gxt += this->GXT.get<data_t>(address);
313 Gyt += this->GYT.get<data_t>(address);
321 if (! this->coordinateHandler.
validate(p))
324 address = this->GXX.address(p.x, p.y);
327 w = this->srcWeight.get<data_t>(address);
331 Gxx -= this->GXX.get<data_t>(address);
332 Gxy -= this->GXY.get<data_t>(address);
333 Gyy -= this->GYY.get<data_t>(address);
334 Gxt -= this->GXT.get<data_t>(address);
335 Gyt -= this->GYT.get<data_t>(address);
373 typedef window_t::data_t data_t;
381 parameters.link(
"resize", resize = 0,
"0.0..1.0|pix");
382 parameters.link(
"threshold", threshold = NAN,
"value");
383 parameters.link(
"spread", spread = 0,
"0|1");
384 parameters.link(
"smooth", smoother = 0,
"0|1");
385 setSize(width, height);
391 parameters.
copyStruct(op.getParameters(), op, *
this);
400 dst.
setType(
typeid(OpticalFlowCore2::data_t));
401 dst.setArea(src.getGeometry());
402 dst.setChannelCount(2, 1);
406 size_t getDiffChannelCount()
const {
407 return window_t::getDiffChannelCount();
412 this->traverseMultiChannel(src, dst);
420 void computeDifferentials(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const;
425 void preprocess(
const Channel & srcImage,
const Channel & srcWeight, Image & dstImage, Image & dstWeight)
const;
453 bool optSpread()
const {
return spread; };
456 bool optSmoother()
const {
return smoother; };
461 bool checkQuality(
const Channel & alpha, std::size_t address,
int DX,
int DY)
const {
463 if (alpha.get<data_t>(address) == 0.0)
466 if (alpha.get<data_t>(address + DX) == 0.0)
469 if (alpha.get<data_t>(address - DX) == 0.0)
472 if (alpha.get<data_t>(address + DY) == 0.0)
475 if (alpha.get<data_t>(address - DY) == 0.0)
A smooth step function, by default from -1.0 to +1.0.
Definition Fuzzy.h:571
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
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:677
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:415
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 FastOpticalFlowOp2.h:369
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:188
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:398
bool optResize() const
Returns true, if resizing is requested.
Definition FastOpticalFlowOp2.h:435
bool optThreshold() const
Returns true, if threshold is requested as postprocessing.
Definition FastOpticalFlowOp2.h:450
bool optPreprocess() const
Returns true, if resizing, thresholding or smoothing is requested.
Definition FastOpticalFlowOp2.h:429
Struct for image (excluding data)
Definition ImageConf.h:333
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
ImageFrame that also has channels.
Definition ImageView.h:52
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 FastOpticalFlowOp2.h:50
void setSrcFrames(const ImageTray< const Channel > &srcTray)
Set inputs as channels.
Definition FastOpticalFlowOp2.cpp:52
Definition FastOpticalFlowOp.h:73
Currently not in use. See SlidingOpticalFlowWeighted2 below.
Definition FastOpticalFlowOp2.h:91
virtual void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition FastOpticalFlowOp2.h:114
virtual void write()
Returns the mean squared error of predicted.
Definition FastOpticalFlowOp2.h:185
virtual void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition FastOpticalFlowOp2.h:246
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition FastOpticalFlowOp2.h:147
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition FastOpticalFlowOp2.h:125
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition FastOpticalFlowOp2.h:228
Definition FastOpticalFlowOp2.h:283
virtual void removePixel(Point2D< int > &p)
Removes a pixel from window statistics. Unvalidated location.
Definition FastOpticalFlowOp2.h:319
virtual void addPixel(Point2D< int > &p)
Adds a pixel to window statistics. Unvalidated location.
Definition FastOpticalFlowOp2.h:294
Template for operators applying pipeline-like sliding window.
Definition SlidingWindowOp.h:57
Window implementation that uses incremental update of state.
Definition SlidingWindow.h:50
Point2D< int > location
Current location of this window.
Definition Window.h:521
Definition DataSelector.cpp:1277