Guest User

Untitled

a guest
Mar 3rd, 2016
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.40 KB | None | 0 0
  1. #include "opencv2/video/tracking.hpp"
  2. #include "opencv2/imgproc/imgproc.hpp"
  3. #include "opencv2/videoio/videoio.hpp"
  4. #include "opencv2/highgui/highgui.hpp"
  5. #include "opencv2/imgcodecs.hpp"
  6. #include "opencv2/highgui.hpp"
  7. #include "opencv2/stitching.hpp"
  8.  
  9.  
  10. #include <iostream>
  11. #include <fstream>
  12. #include <ctype.h>
  13.  
  14. using namespace cv;
  15. using namespace std;
  16.  
  17.  
  18. //! type of the kernel
  19. enum
  20. {
  21.     KERNEL_GENERAL      = 0, // the kernel is generic. No any type of symmetry or other properties.
  22.     KERNEL_SYMMETRICAL  = 1, // kernel[i] == kernel[ksize-i-1] , and the anchor is at the center
  23.     KERNEL_ASYMMETRICAL = 2, // kernel[i] == -kernel[ksize-i-1] , and the anchor is at the center
  24.     KERNEL_SMOOTH       = 4, // all the kernel elements are non-negative and summed to 1
  25.     KERNEL_INTEGER      = 8  // all the kernel coefficients are integer numbers
  26. };
  27.  
  28. /*!
  29.  The Base Class for 1D or Row-wise Filters
  30.  This is the base class for linear or non-linear filters that process 1D data.
  31.  In particular, such filters are used for the "horizontal" filtering parts in separable filters.
  32.  Several functions in OpenCV return Ptr<BaseRowFilter> for the specific types of filters,
  33.  and those pointers can be used directly or within cv::FilterEngine.
  34. */
  35. class BaseRowFilter
  36. {
  37. public:
  38.     //! the default constructor
  39.     BaseRowFilter();
  40.     //! the destructor
  41.     virtual ~BaseRowFilter();
  42.     //! the filtering operator. Must be overridden in the derived classes. The horizontal border interpolation is done outside of the class.
  43.     virtual void operator()(const uchar* src, uchar* dst, int width, int cn) = 0;
  44.  
  45.     int ksize;
  46.     int anchor;
  47. };
  48.  
  49.  
  50. /*!
  51.  The Base Class for Column-wise Filters
  52.  This is the base class for linear or non-linear filters that process columns of 2D arrays.
  53.  Such filters are used for the "vertical" filtering parts in separable filters.
  54.  Several functions in OpenCV return Ptr<BaseColumnFilter> for the specific types of filters,
  55.  and those pointers can be used directly or within cv::FilterEngine.
  56.  Unlike cv::BaseRowFilter, cv::BaseColumnFilter may have some context information,
  57.  i.e. box filter keeps the sliding sum of elements. To reset the state BaseColumnFilter::reset()
  58.  must be called (e.g. the method is called by cv::FilterEngine)
  59.  */
  60. class BaseColumnFilter
  61. {
  62. public:
  63.     //! the default constructor
  64.     BaseColumnFilter();
  65.     //! the destructor
  66.     virtual ~BaseColumnFilter();
  67.     //! the filtering operator. Must be overridden in the derived classes. The vertical border interpolation is done outside of the class.
  68.     virtual void operator()(const uchar** src, uchar* dst, int dststep, int dstcount, int width) = 0;
  69.     //! resets the internal buffers, if any
  70.     virtual void reset();
  71.  
  72.     int ksize;
  73.     int anchor;
  74. };
  75.  
  76.  
  77. /*!
  78.  The Base Class for Non-Separable 2D Filters.
  79.  This is the base class for linear or non-linear 2D filters.
  80.  Several functions in OpenCV return Ptr<BaseFilter> for the specific types of filters,
  81.  and those pointers can be used directly or within cv::FilterEngine.
  82.  Similar to cv::BaseColumnFilter, the class may have some context information,
  83.  that should be reset using BaseFilter::reset() method before processing the new array.
  84. */
  85. class BaseFilter
  86. {
  87. public:
  88.     //! the default constructor
  89.     BaseFilter();
  90.     //! the destructor
  91.     virtual ~BaseFilter();
  92.     //! the filtering operator. The horizontal and the vertical border interpolation is done outside of the class.
  93.     virtual void operator()(const uchar** src, uchar* dst, int dststep, int dstcount, int width, int cn) = 0;
  94.     //! resets the internal buffers, if any
  95.     virtual void reset();
  96.  
  97.     Size ksize;
  98.     Point anchor;
  99. };
  100.  
  101.  
  102. /*!
  103.  The Main Class for Image Filtering.
  104.  The class can be used to apply an arbitrary filtering operation to an image.
  105.  It contains all the necessary intermediate buffers, it computes extrapolated values
  106.  of the "virtual" pixels outside of the image etc.
  107.  Pointers to the initialized cv::FilterEngine instances
  108.  are returned by various OpenCV functions, such as cv::createSeparableLinearFilter(),
  109.  cv::createLinearFilter(), cv::createGaussianFilter(), cv::createDerivFilter(),
  110.  cv::createBoxFilter() and cv::createMorphologyFilter().
  111.  Using the class you can process large images by parts and build complex pipelines
  112.  that include filtering as some of the stages. If all you need is to apply some pre-defined
  113.  filtering operation, you may use cv::filter2D(), cv::erode(), cv::dilate() etc.
  114.  functions that create FilterEngine internally.
  115.  Here is the example on how to use the class to implement Laplacian operator, which is the sum of
  116.  second-order derivatives. More complex variant for different types is implemented in cv::Laplacian().
  117.  \code
  118.  void laplace_f(const Mat& src, Mat& dst)
  119.  {
  120.      CV_Assert( src.type() == CV_32F );
  121.      // make sure the destination array has the proper size and type
  122.      dst.create(src.size(), src.type());
  123.      // get the derivative and smooth kernels for d2I/dx2.
  124.      // for d2I/dy2 we could use the same kernels, just swapped
  125.      Mat kd, ks;
  126.      getSobelKernels( kd, ks, 2, 0, ksize, false, ktype );
  127.      // let's process 10 source rows at once
  128.      int DELTA = std::min(10, src.rows);
  129.      Ptr<FilterEngine> Fxx = createSeparableLinearFilter(src.type(),
  130.      dst.type(), kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
  131.      Ptr<FilterEngine> Fyy = createSeparableLinearFilter(src.type(),
  132.      dst.type(), ks, kd, Point(-1,-1), 0, borderType, borderType, Scalar() );
  133.      int y = Fxx->start(src), dsty = 0, dy = 0;
  134.      Fyy->start(src);
  135.      const uchar* sptr = src.data + y*src.step;
  136.      // allocate the buffers for the spatial image derivatives;
  137.      // the buffers need to have more than DELTA rows, because at the
  138.      // last iteration the output may take max(kd.rows-1,ks.rows-1)
  139.      // rows more than the input.
  140.      Mat Ixx( DELTA + kd.rows - 1, src.cols, dst.type() );
  141.      Mat Iyy( DELTA + kd.rows - 1, src.cols, dst.type() );
  142.      // inside the loop we always pass DELTA rows to the filter
  143.      // (note that the "proceed" method takes care of possibe overflow, since
  144.      // it was given the actual image height in the "start" method)
  145.      // on output we can get:
  146.      //  * < DELTA rows (the initial buffer accumulation stage)
  147.      //  * = DELTA rows (settled state in the middle)
  148.      //  * > DELTA rows (then the input image is over, but we generate
  149.      //                  "virtual" rows using the border mode and filter them)
  150.      // this variable number of output rows is dy.
  151.      // dsty is the current output row.
  152.      // sptr is the pointer to the first input row in the portion to process
  153.      for( ; dsty < dst.rows; sptr += DELTA*src.step, dsty += dy )
  154.      {
  155.          Fxx->proceed( sptr, (int)src.step, DELTA, Ixx.data, (int)Ixx.step );
  156.          dy = Fyy->proceed( sptr, (int)src.step, DELTA, d2y.data, (int)Iyy.step );
  157.          if( dy > 0 )
  158.          {
  159.              Mat dstripe = dst.rowRange(dsty, dsty + dy);
  160.              add(Ixx.rowRange(0, dy), Iyy.rowRange(0, dy), dstripe);
  161.          }
  162.      }
  163.  }
  164.  \endcode
  165. */
  166. class FilterEngine
  167. {
  168. public:
  169.     //! the default constructor
  170.     FilterEngine();
  171.     //! the full constructor. Either _filter2D or both _rowFilter and _columnFilter must be non-empty.
  172.     FilterEngine(const Ptr<BaseFilter>& _filter2D,
  173.                  const Ptr<BaseRowFilter>& _rowFilter,
  174.                  const Ptr<BaseColumnFilter>& _columnFilter,
  175.                  int srcType, int dstType, int bufType,
  176.                  int _rowBorderType = BORDER_REPLICATE,
  177.                  int _columnBorderType = -1,
  178.                  const Scalar& _borderValue = Scalar());
  179.     //! the destructor
  180.     virtual ~FilterEngine();
  181.     //! reinitializes the engine. The previously assigned filters are released.
  182.     void init(const Ptr<BaseFilter>& _filter2D,
  183.               const Ptr<BaseRowFilter>& _rowFilter,
  184.               const Ptr<BaseColumnFilter>& _columnFilter,
  185.               int srcType, int dstType, int bufType,
  186.               int _rowBorderType = BORDER_REPLICATE,
  187.               int _columnBorderType = -1,
  188.               const Scalar& _borderValue = Scalar());
  189.     //! starts filtering of the specified ROI of an image of size wholeSize.
  190.     virtual int start(Size wholeSize, Rect roi, int maxBufRows = -1);
  191.     //! starts filtering of the specified ROI of the specified image.
  192.     virtual int start(const Mat& src, const Rect& srcRoi = Rect(0,0,-1,-1),
  193.                       bool isolated = false, int maxBufRows = -1);
  194.     //! processes the next srcCount rows of the image.
  195.     virtual int proceed(const uchar* src, int srcStep, int srcCount,
  196.                         uchar* dst, int dstStep);
  197.     //! applies filter to the specified ROI of the image. if srcRoi=(0,0,-1,-1), the whole image is filtered.
  198.     virtual void apply( const Mat& src, Mat& dst,
  199.                         const Rect& srcRoi = Rect(0,0,-1,-1),
  200.                         Point dstOfs = Point(0,0),
  201.                         bool isolated = false);
  202.     //! returns true if the filter is separable
  203.     bool isSeparable() const { return !filter2D; }
  204.     //! returns the number
  205.     int remainingInputRows() const;
  206.     int remainingOutputRows() const;
  207.  
  208.     int srcType;
  209.     int dstType;
  210.     int bufType;
  211.     Size ksize;
  212.     Point anchor;
  213.     int maxWidth;
  214.     Size wholeSize;
  215.     Rect roi;
  216.     int dx1;
  217.     int dx2;
  218.     int rowBorderType;
  219.     int columnBorderType;
  220.     std::vector<int> borderTab;
  221.     int borderElemSize;
  222.     std::vector<uchar> ringBuf;
  223.     std::vector<uchar> srcRow;
  224.     std::vector<uchar> constBorderValue;
  225.     std::vector<uchar> constBorderRow;
  226.     int bufStep;
  227.     int startY;
  228.     int startY0;
  229.     int endY;
  230.     int rowCount;
  231.     int dstY;
  232.     std::vector<uchar*> rows;
  233.  
  234.     Ptr<BaseFilter> filter2D;
  235.     Ptr<BaseRowFilter> rowFilter;
  236.     Ptr<BaseColumnFilter> columnFilter;
  237. };
  238.  
  239.  
  240. //! returns type (one of KERNEL_*) of 1D or 2D kernel specified by its coefficients.
  241. int getKernelType(InputArray kernel, Point anchor);
  242.  
  243. //! returns the primitive row filter with the specified kernel
  244. Ptr<BaseRowFilter> getLinearRowFilter(int srcType, int bufType,
  245.                                             InputArray kernel, int anchor,
  246.                                             int symmetryType);
  247.  
  248. //! returns the primitive column filter with the specified kernel
  249. Ptr<BaseColumnFilter> getLinearColumnFilter(int bufType, int dstType,
  250.                                             InputArray kernel, int anchor,
  251.                                             int symmetryType, double delta = 0,
  252.                                             int bits = 0);
  253.  
  254. //! returns 2D filter with the specified kernel
  255. Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
  256.                                            InputArray kernel,
  257.                                            Point anchor = Point(-1,-1),
  258.                                            double delta = 0, int bits = 0);
  259.  
  260. //! returns the separable linear filter engine
  261. Ptr<FilterEngine> createSeparableLinearFilter(int srcType, int dstType,
  262.                           InputArray rowKernel, InputArray columnKernel,
  263.                           Point anchor = Point(-1,-1), double delta = 0,
  264.                           int rowBorderType = BORDER_DEFAULT,
  265.                           int columnBorderType = -1,
  266.                           const Scalar& borderValue = Scalar());
  267.  
  268. //! returns the non-separable linear filter engine
  269. Ptr<FilterEngine> createLinearFilter(int srcType, int dstType,
  270.                  InputArray kernel, Point _anchor = Point(-1,-1),
  271.                  double delta = 0, int rowBorderType = BORDER_DEFAULT,
  272.                  int columnBorderType = -1, const Scalar& borderValue = Scalar());
  273.  
  274. //! returns the Gaussian filter engine
  275. Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
  276.                                     double sigma1, double sigma2 = 0,
  277.                                     int borderType = BORDER_DEFAULT);
  278.  
  279. //! returns filter engine for the generalized Sobel operator
  280. Ptr<FilterEngine> createDerivFilter( int srcType, int dstType,
  281.                                         int dx, int dy, int ksize,
  282.                                         int borderType = BORDER_DEFAULT );
  283.  
  284. //! returns horizontal 1D box filter
  285. Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType,
  286.                                               int ksize, int anchor = -1);
  287.  
  288. //! returns vertical 1D box filter
  289. Ptr<BaseColumnFilter> getColumnSumFilter( int sumType, int dstType,
  290.                                                      int ksize, int anchor = -1,
  291.                                                      double scale = 1);
  292. //! returns box filter engine
  293. Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
  294.                                               Point anchor = Point(-1,-1),
  295.                                               bool normalize = true,
  296.                                               int borderType = BORDER_DEFAULT);
  297.  
  298.  
  299. //! returns horizontal 1D morphological filter
  300. Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor = -1);
  301.  
  302. //! returns vertical 1D morphological filter
  303. Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int anchor = -1);
  304.  
  305. //! returns 2D morphological filter
  306. Ptr<BaseFilter> getMorphologyFilter(int op, int type, InputArray kernel,
  307.                                                Point anchor = Point(-1,-1));
  308.  
  309. //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.
  310. CV_EXPORTS Ptr<FilterEngine> createMorphologyFilter(int op, int type, InputArray kernel,
  311.                                                     Point anchor = Point(-1,-1), int rowBorderType = BORDER_CONSTANT,
  312.                                                     int columnBorderType = -1,
  313.                                                     const Scalar& borderValue = morphologyDefaultBorderValue());
  314.  
  315. static inline Point normalizeAnchor( Point anchor, Size ksize )
  316. {
  317.    if( anchor.x == -1 )
  318.        anchor.x = ksize.width/2;
  319.    if( anchor.y == -1 )
  320.        anchor.y = ksize.height/2;
  321.    CV_Assert( anchor.inside(Rect(0, 0, ksize.width, ksize.height)) );
  322.    return anchor;
  323. }
  324.  
  325. void preprocess2DKernel( const Mat& kernel, std::vector<Point>& coords, std::vector<uchar>& coeffs );
  326. void crossCorr( const Mat& src, const Mat& templ, Mat& dst,
  327.                Size corrsize, int ctype,
  328.                Point anchor=Point(0,0), double delta=0,
  329.                int borderType=BORDER_REFLECT_101 );
  330.  
  331.  
  332. template<typename T, typename ST> struct RowSum : public BaseRowFilter
  333. {
  334.     RowSum( int _ksize, int _anchor )
  335.     {
  336.         ksize = _ksize;
  337.         anchor = _anchor;
  338.     }
  339.  
  340.     void operator()(const uchar* src, uchar* dst, int width, int cn)
  341.     {
  342.         const T* S = (const T*)src;
  343.         ST* D = (ST*)dst;
  344.         int i = 0, k, ksz_cn = ksize*cn;
  345.  
  346.         width = (width - 1)*cn;
  347.         for( k = 0; k < cn; k++, S++, D++ )
  348.         {
  349.             ST s = 0;
  350.             for( i = 0; i < ksz_cn; i += cn )
  351.                 s += S[i];
  352.             D[0] = s;
  353.             for( i = 0; i < width; i += cn )
  354.             {
  355.                 s += S[i + ksz_cn] - S[i];
  356.                 D[i+cn] = s;
  357.             }
  358.         }
  359.     }
  360. };
  361.  
  362. template<typename ST, typename T> struct ColumnSum : public BaseColumnFilter
  363. {
  364.     ColumnSum( int _ksize, int _anchor, double _scale )
  365.     {
  366.         ksize = _ksize;
  367.         anchor = _anchor;
  368.         scale = _scale;
  369.         sumCount = 0;
  370.     }
  371.  
  372.     void reset() { sumCount = 0; }
  373.  
  374.     void operator()(const uchar** src, uchar* dst, int dststep, int count, int width)
  375.     {
  376.         int i;
  377.         ST* SUM;
  378.         bool haveScale = scale != 1;
  379.         double _scale = scale;
  380.  
  381.         if( width != (int)sum.size() )
  382.         {
  383.             sum.resize(width);
  384.             sumCount = 0;
  385.         }
  386.  
  387.         SUM = &sum[0];
  388.         if( sumCount == 0 )
  389.         {
  390.             for( i = 0; i < width; i++ )
  391.                 SUM[i] = 0;
  392.             for( ; sumCount < ksize - 1; sumCount++, src++ )
  393.             {
  394.                 const ST* Sp = (const ST*)src[0];
  395.                 for( i = 0; i <= width - 2; i += 2 )
  396.                 {
  397.                     ST s0 = SUM[i] + Sp[i], s1 = SUM[i+1] + Sp[i+1];
  398.                     SUM[i] = s0; SUM[i+1] = s1;
  399.                 }
  400.  
  401.                 for( ; i < width; i++ )
  402.                     SUM[i] += Sp[i];
  403.             }
  404.         }
  405.         else
  406.         {
  407.             CV_Assert( sumCount == ksize-1 );
  408.             src += ksize-1;
  409.         }
  410.  
  411.         for( ; count--; src++ )
  412.         {
  413.             const ST* Sp = (const ST*)src[0];
  414.             const ST* Sm = (const ST*)src[1-ksize];
  415.             T* D = (T*)dst;
  416.             if( haveScale )
  417.             {
  418.                 for( i = 0; i <= width - 2; i += 2 )
  419.                 {
  420.                     ST s0 = SUM[i] + Sp[i], s1 = SUM[i+1] + Sp[i+1];
  421.                     D[i] = saturate_cast<T>(s0*_scale);
  422.                     D[i+1] = saturate_cast<T>(s1*_scale);
  423.                     s0 -= Sm[i]; s1 -= Sm[i+1];
  424.                     SUM[i] = s0; SUM[i+1] = s1;
  425.                 }
  426.  
  427.                 for( ; i < width; i++ )
  428.                 {
  429.                     ST s0 = SUM[i] + Sp[i];
  430.                     D[i] = saturate_cast<T>(s0*_scale);
  431.                     SUM[i] = s0 - Sm[i];
  432.                 }
  433.             }
  434.             else
  435.             {
  436.                 for( i = 0; i <= width - 2; i += 2 )
  437.                 {
  438.                     ST s0 = SUM[i] + Sp[i], s1 = SUM[i+1] + Sp[i+1];
  439.                     D[i] = saturate_cast<T>(s0);
  440.                     D[i+1] = saturate_cast<T>(s1);
  441.                     s0 -= Sm[i]; s1 -= Sm[i+1];
  442.                     SUM[i] = s0; SUM[i+1] = s1;
  443.                 }
  444.  
  445.                 for( ; i < width; i++ )
  446.                 {
  447.                     ST s0 = SUM[i] + Sp[i];
  448.                     D[i] = saturate_cast<T>(s0);
  449.                     SUM[i] = s0 - Sm[i];
  450.                 }
  451.             }
  452.             dst += dststep;
  453.         }
  454.     }
  455.  
  456.     double scale;
  457.     int sumCount;
  458.     vector<ST> sum;
  459. };
  460.  
  461.  
  462.  
  463. template<> struct ColumnSum<float, float> : public BaseColumnFilter
  464. {
  465.     ColumnSum( int _ksize, int _anchor, double _scale )
  466.     {
  467.         ksize = _ksize;
  468.         anchor = _anchor;
  469.         scale = _scale;
  470.         sumCount = 0;
  471.     }
  472.  
  473.     void reset() { sumCount = 0; }
  474.  
  475.     void operator()(const uchar** src, uchar* dst, int dststep, int count, int width)
  476.     {
  477.         int i;
  478.         float* SUM;
  479.         bool haveScale = scale != 1;
  480.         double _scale = scale;
  481.  
  482.         #if CV_SSE2
  483.             bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2);
  484.         #endif
  485.  
  486.         if( width != (int)sum.size() )
  487.         {
  488.             sum.resize(width);
  489.             sumCount = 0;
  490.         }
  491.  
  492.         SUM = &sum[0];
  493.         if( sumCount == 0 )
  494.         {
  495.             memset((void*)SUM, 0, width*sizeof(float));
  496.             for( ; sumCount < ksize - 1; sumCount++, src++ )
  497.             {
  498.                 const float* Sp = (const float*)src[0];
  499.                 i = 0;
  500.                 #if CV_SSE2
  501.                 if(haveSSE2)
  502.                 {
  503.                     for( ; i < width-4; i+=4 )
  504.                     {
  505.                         __m128 _sum = _mm_loadu_ps((SUM+i));
  506.                         __m128 _sp = _mm_loadu_ps((Sp+i));
  507.                         _mm_storeu_ps((SUM+i),_mm_add_ps(_sum, _sp));
  508.                     }
  509.                 }
  510.                 #endif
  511.                 for( ; i < width; i++ )
  512.                     SUM[i] += Sp[i];
  513.             }
  514.         }
  515.         else
  516.         {
  517.             CV_Assert( sumCount == ksize-1 );
  518.             src += ksize-1;
  519.         }
  520.  
  521.  
  522.         for( ; count--; src++ )
  523.         {
  524.             const float* Sp = (const float*)src[0];
  525.             const float* Sm = (const float*)src[1-ksize];
  526.             float* D = (float*)dst;
  527.             if( haveScale )
  528.             {
  529.                 i = 0;
  530.                 #if CV_SSE2
  531.                 if(haveSSE2)
  532.                 {
  533.                     const __m128 scale4 = _mm_set1_ps((float)_scale);
  534.                     for( ; i < width-4; i+=4 )
  535.                     {
  536.                         __m128 _sm  = _mm_loadu_ps((Sm+i));
  537.                         __m128 _s0  = _mm_add_ps(_mm_loadu_ps((SUM+i)),
  538.                                                      _mm_loadu_ps((Sp+i)));
  539.                         _mm_storeu_ps(D+i, _mm_mul_ps(scale4,_s0));
  540.                         _mm_storeu_ps(SUM+i,_mm_sub_ps(_s0,_sm));
  541.                     }
  542.                 }
  543.                 #endif
  544.                 for( ; i < width; i++ )
  545.                 {
  546.                     float s0 = SUM[i] + Sp[i];
  547.                     D[i] = saturate_cast<float>(s0*_scale);
  548.                     SUM[i] = s0 - Sm[i];
  549.                 }
  550.             }
  551.             else
  552.             {
  553.                 i = 0;
  554.                 #if CV_SSE2
  555.                 if(haveSSE2)
  556.                 {
  557.                     for( ; i < width-4; i+=4 )
  558.                     {
  559.                         __m128 _sm  = _mm_loadu_ps((Sm+i));
  560.                         __m128 _s0  = _mm_add_ps(_mm_loadu_ps((SUM+i)),
  561.                                                      _mm_loadu_ps((Sp+i)));
  562.                         _mm_storeu_ps(D+i,_s0);
  563.                         _mm_storeu_ps(SUM+i,_mm_sub_ps(_s0,_sm));
  564.                     }
  565.                 }
  566.                 #endif
  567.  
  568.                 for( ; i < width; i++ )
  569.                 {
  570.                     float s0 = SUM[i] + Sp[i];
  571.                     D[i] = saturate_cast<uchar>(s0);
  572.                     SUM[i] = s0 - Sm[i];
  573.                 }
  574.             }
  575.             dst += dststep;
  576.         }
  577.     }
  578.  
  579.     double scale;
  580.     int sumCount;
  581.     vector<float> sum;
  582. };
  583.  
  584. cv::Ptr<FilterEngine> createBoxFilterFFF(int cn, Size ksize,
  585.                     Point anchor, bool normalize, int borderType )
  586. {
  587.  
  588.     Ptr<BaseRowFilter> rowFilter = Ptr<BaseRowFilter>(new RowSum<float, float>(ksize.width, anchor.x < 0 ? ksize.width/2 : anchor.x));
  589.  
  590.     Ptr<BaseColumnFilter> columnFilter = Ptr<BaseColumnFilter>(new ColumnSum<float, float>(ksize.height, anchor.y < 0 ? ksize.height/2 : anchor.y, normalize ? 1./(ksize.width*ksize.height) : 1));
  591.  
  592.     return Ptr<FilterEngine>(new FilterEngine(Ptr<BaseFilter>(/*0*/), rowFilter, columnFilter,
  593.            CV_32F, CV_32F, CV_32F, borderType ));
  594. }
  595.  
  596.  
  597. int main(int argc, char* argv[])
  598. {
  599.  
  600.  
  601.    Mat planes=imread("f:/lib/opencv/samples/data/graf1.png");
  602.  
  603.  
  604.    Ptr<BaseRowFilter> f;
  605.  
  606.    return 0;
  607. }
Advertisement
Add Comment
Please, Sign In to add comment