• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CUDAIMGPROC) || defined (CUDA_DISABLER)
49 
createOpticalFlowNeedleMap(const GpuMat &,const GpuMat &,GpuMat &,GpuMat &)50 void cv::cuda::createOpticalFlowNeedleMap(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&) { throw_no_cuda(); }
51 
52 #else
53 
54 namespace cv { namespace cuda { namespace device
55 {
56     namespace optical_flow
57     {
58         void NeedleMapAverage_gpu(PtrStepSzf u, PtrStepSzf v, PtrStepSzf u_avg, PtrStepSzf v_avg);
59         void CreateOpticalFlowNeedleMap_gpu(PtrStepSzf u_avg, PtrStepSzf v_avg, float* vertex_buffer, float* color_data, float max_flow, float xscale, float yscale);
60     }
61 }}}
62 
createOpticalFlowNeedleMap(const GpuMat & u,const GpuMat & v,GpuMat & vertex,GpuMat & colors)63 void cv::cuda::createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors)
64 {
65     using namespace cv::cuda::device::optical_flow;
66 
67     CV_Assert(u.type() == CV_32FC1);
68     CV_Assert(v.type() == u.type() && v.size() == u.size());
69 
70     const int NEEDLE_MAP_SCALE = 16;
71 
72     const int x_needles = u.cols / NEEDLE_MAP_SCALE;
73     const int y_needles = u.rows / NEEDLE_MAP_SCALE;
74 
75     GpuMat u_avg(y_needles, x_needles, CV_32FC1);
76     GpuMat v_avg(y_needles, x_needles, CV_32FC1);
77 
78     NeedleMapAverage_gpu(u, v, u_avg, v_avg);
79 
80     const int NUM_VERTS_PER_ARROW = 6;
81 
82     const int num_arrows = x_needles * y_needles * NUM_VERTS_PER_ARROW;
83 
84     vertex.create(1, num_arrows, CV_32FC3);
85     colors.create(1, num_arrows, CV_32FC3);
86 
87     colors.setTo(Scalar::all(1.0));
88 
89     double uMax, vMax;
90     cuda::minMax(u_avg, 0, &uMax);
91     cuda::minMax(v_avg, 0, &vMax);
92 
93     float max_flow = static_cast<float>(std::sqrt(uMax * uMax + vMax * vMax));
94 
95     CreateOpticalFlowNeedleMap_gpu(u_avg, v_avg, vertex.ptr<float>(), colors.ptr<float>(), max_flow, 1.0f / u.cols, 1.0f / u.rows);
96 
97     cuda::cvtColor(colors, colors, COLOR_HSV2RGB);
98 }
99 
100 #endif /* HAVE_CUDA */
101