Home | History | Annotate | Download | only in src
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                           License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
     14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
     15 // Third party copyrights are property of their respective owners.
     16 //
     17 // Redistribution and use in source and binary forms, with or without modification,
     18 // are permitted provided that the following conditions are met:
     19 //
     20 //   * Redistribution's of source code must retain the above copyright notice,
     21 //     this list of conditions and the following disclaimer.
     22 //
     23 //   * Redistribution's in binary form must reproduce the above copyright notice,
     24 //     this list of conditions and the following disclaimer in the documentation
     25 //     and/or other materials provided with the distribution.
     26 //
     27 //   * The name of the copyright holders may not be used to endorse or promote products
     28 //     derived from this software without specific prior written permission.
     29 //
     30 // This software is provided by the copyright holders and contributors "as is" and
     31 // any express or implied warranties, including, but not limited to, the implied
     32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     33 // In no event shall the Intel Corporation or contributors be liable for any direct,
     34 // indirect, incidental, special, exemplary, or consequential damages
     35 // (including, but not limited to, procurement of substitute goods or services;
     36 // loss of use, data, or profits; or business interruption) however caused
     37 // and on any theory of liability, whether in contract, strict liability,
     38 // or tort (including negligence or otherwise) arising in any way out of
     39 // the use of this software, even if advised of the possibility of such damage.
     40 //
     41 //M*/
     42 
     43 #include "precomp.hpp"
     44 
     45 using namespace cv;
     46 using namespace cv::cuda;
     47 
     48 #if !defined (HAVE_CUDA) || !defined (HAVE_OPENCV_CUDALEGACY) || defined (CUDA_DISABLER)
     49 
     50 void cv::cuda::interpolateFrames(const GpuMat&, const GpuMat&, const GpuMat&, const GpuMat&, const GpuMat&, const GpuMat&, float, GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
     51 
     52 #else
     53 
     54 void cv::cuda::interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, const GpuMat& fu, const GpuMat& fv, const GpuMat& bu, const GpuMat& bv,
     55                                 float pos, GpuMat& newFrame, GpuMat& buf, Stream& s)
     56 {
     57     CV_Assert(frame0.type() == CV_32FC1);
     58     CV_Assert(frame1.size() == frame0.size() && frame1.type() == frame0.type());
     59     CV_Assert(fu.size() == frame0.size() && fu.type() == frame0.type());
     60     CV_Assert(fv.size() == frame0.size() && fv.type() == frame0.type());
     61     CV_Assert(bu.size() == frame0.size() && bu.type() == frame0.type());
     62     CV_Assert(bv.size() == frame0.size() && bv.type() == frame0.type());
     63 
     64     newFrame.create(frame0.size(), frame0.type());
     65 
     66     buf.create(6 * frame0.rows, frame0.cols, CV_32FC1);
     67     buf.setTo(Scalar::all(0));
     68 
     69     // occlusion masks
     70     GpuMat occ0 = buf.rowRange(0 * frame0.rows, 1 * frame0.rows);
     71     GpuMat occ1 = buf.rowRange(1 * frame0.rows, 2 * frame0.rows);
     72 
     73     // interpolated forward flow
     74     GpuMat fui = buf.rowRange(2 * frame0.rows, 3 * frame0.rows);
     75     GpuMat fvi = buf.rowRange(3 * frame0.rows, 4 * frame0.rows);
     76 
     77     // interpolated backward flow
     78     GpuMat bui = buf.rowRange(4 * frame0.rows, 5 * frame0.rows);
     79     GpuMat bvi = buf.rowRange(5 * frame0.rows, 6 * frame0.rows);
     80 
     81     size_t step = frame0.step;
     82 
     83     CV_Assert(frame1.step == step && fu.step == step && fv.step == step && bu.step == step && bv.step == step && newFrame.step == step && buf.step == step);
     84 
     85     cudaStream_t stream = StreamAccessor::getStream(s);
     86     NppStStreamHandler h(stream);
     87 
     88     NppStInterpolationState state;
     89 
     90     state.size         = NcvSize32u(frame0.cols, frame0.rows);
     91     state.nStep        = static_cast<Ncv32u>(step);
     92     state.pSrcFrame0   = const_cast<Ncv32f*>(frame0.ptr<Ncv32f>());
     93     state.pSrcFrame1   = const_cast<Ncv32f*>(frame1.ptr<Ncv32f>());
     94     state.pFU          = const_cast<Ncv32f*>(fu.ptr<Ncv32f>());
     95     state.pFV          = const_cast<Ncv32f*>(fv.ptr<Ncv32f>());
     96     state.pBU          = const_cast<Ncv32f*>(bu.ptr<Ncv32f>());
     97     state.pBV          = const_cast<Ncv32f*>(bv.ptr<Ncv32f>());
     98     state.pos          = pos;
     99     state.pNewFrame    = newFrame.ptr<Ncv32f>();
    100     state.ppBuffers[0] = occ0.ptr<Ncv32f>();
    101     state.ppBuffers[1] = occ1.ptr<Ncv32f>();
    102     state.ppBuffers[2] = fui.ptr<Ncv32f>();
    103     state.ppBuffers[3] = fvi.ptr<Ncv32f>();
    104     state.ppBuffers[4] = bui.ptr<Ncv32f>();
    105     state.ppBuffers[5] = bvi.ptr<Ncv32f>();
    106 
    107     ncvSafeCall( nppiStInterpolateFrames(&state) );
    108 
    109     if (stream == 0)
    110         cudaSafeCall( cudaDeviceSynchronize() );
    111 }
    112 
    113 #endif /* HAVE_CUDA */
    114