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 #include "opencv2/ts/cuda_perf.hpp"
     45 #include "opencv2/core/cuda.hpp"
     46 
     47 using namespace cv;
     48 using namespace std;
     49 
     50 namespace perf
     51 {
     52     Mat readImage(const string& fileName, int flags)
     53     {
     54         return imread(perf::TestBase::getDataPath(fileName), flags);
     55     }
     56 
     57     void PrintTo(const CvtColorInfo& info, std::ostream* os)
     58     {
     59         static const char* str[] =
     60         {
     61             "BGR2BGRA",
     62             "BGRA2BGR",
     63             "BGR2RGBA",
     64             "RGBA2BGR",
     65             "BGR2RGB",
     66             "BGRA2RGBA",
     67 
     68             "BGR2GRAY",
     69             "RGB2GRAY",
     70             "GRAY2BGR",
     71             "GRAY2BGRA",
     72             "BGRA2GRAY",
     73             "RGBA2GRAY",
     74 
     75             "BGR2BGR565",
     76             "RGB2BGR565",
     77             "BGR5652BGR",
     78             "BGR5652RGB",
     79             "BGRA2BGR565",
     80             "RGBA2BGR565",
     81             "BGR5652BGRA",
     82             "BGR5652RGBA",
     83 
     84             "GRAY2BGR565",
     85             "BGR5652GRAY",
     86 
     87             "BGR2BGR555",
     88             "RGB2BGR555",
     89             "BGR5552BGR",
     90             "BGR5552RGB",
     91             "BGRA2BGR555",
     92             "RGBA2BGR555",
     93             "BGR5552BGRA",
     94             "BGR5552RGBA",
     95 
     96             "GRAY2BGR555",
     97             "BGR5552GRAY",
     98 
     99             "BGR2XYZ",
    100             "RGB2XYZ",
    101             "XYZ2BGR",
    102             "XYZ2RGB",
    103 
    104             "BGR2YCrCb",
    105             "RGB2YCrCb",
    106             "YCrCb2BGR",
    107             "YCrCb2RGB",
    108 
    109             "BGR2HSV",
    110             "RGB2HSV",
    111 
    112             "",
    113             "",
    114 
    115             "BGR2Lab",
    116             "RGB2Lab",
    117 
    118             "BayerBG2BGR",
    119             "BayerGB2BGR",
    120             "BayerRG2BGR",
    121             "BayerGR2BGR",
    122 
    123             "BGR2Luv",
    124             "RGB2Luv",
    125 
    126             "BGR2HLS",
    127             "RGB2HLS",
    128 
    129             "HSV2BGR",
    130             "HSV2RGB",
    131 
    132             "Lab2BGR",
    133             "Lab2RGB",
    134             "Luv2BGR",
    135             "Luv2RGB",
    136 
    137             "HLS2BGR",
    138             "HLS2RGB",
    139 
    140             "BayerBG2BGR_VNG",
    141             "BayerGB2BGR_VNG",
    142             "BayerRG2BGR_VNG",
    143             "BayerGR2BGR_VNG",
    144 
    145             "BGR2HSV_FULL",
    146             "RGB2HSV_FULL",
    147             "BGR2HLS_FULL",
    148             "RGB2HLS_FULL",
    149 
    150             "HSV2BGR_FULL",
    151             "HSV2RGB_FULL",
    152             "HLS2BGR_FULL",
    153             "HLS2RGB_FULL",
    154 
    155             "LBGR2Lab",
    156             "LRGB2Lab",
    157             "LBGR2Luv",
    158             "LRGB2Luv",
    159 
    160             "Lab2LBGR",
    161             "Lab2LRGB",
    162             "Luv2LBGR",
    163             "Luv2LRGB",
    164 
    165             "BGR2YUV",
    166             "RGB2YUV",
    167             "YUV2BGR",
    168             "YUV2RGB",
    169 
    170             "BayerBG2GRAY",
    171             "BayerGB2GRAY",
    172             "BayerRG2GRAY",
    173             "BayerGR2GRAY",
    174 
    175             //YUV 4:2:0 formats family
    176             "YUV2RGB_NV12",
    177             "YUV2BGR_NV12",
    178             "YUV2RGB_NV21",
    179             "YUV2BGR_NV21",
    180 
    181             "YUV2RGBA_NV12",
    182             "YUV2BGRA_NV12",
    183             "YUV2RGBA_NV21",
    184             "YUV2BGRA_NV21",
    185 
    186             "YUV2RGB_YV12",
    187             "YUV2BGR_YV12",
    188             "YUV2RGB_IYUV",
    189             "YUV2BGR_IYUV",
    190 
    191             "YUV2RGBA_YV12",
    192             "YUV2BGRA_YV12",
    193             "YUV2RGBA_IYUV",
    194             "YUV2BGRA_IYUV",
    195 
    196             "YUV2GRAY_420",
    197 
    198             //YUV 4:2:2 formats family
    199             "YUV2RGB_UYVY",
    200             "YUV2BGR_UYVY",
    201             "YUV2RGB_VYUY",
    202             "YUV2BGR_VYUY",
    203 
    204             "YUV2RGBA_UYVY",
    205             "YUV2BGRA_UYVY",
    206             "YUV2RGBA_VYUY",
    207             "YUV2BGRA_VYUY",
    208 
    209             "YUV2RGB_YUY2",
    210             "YUV2BGR_YUY2",
    211             "YUV2RGB_YVYU",
    212             "YUV2BGR_YVYU",
    213 
    214             "YUV2RGBA_YUY2",
    215             "YUV2BGRA_YUY2",
    216             "YUV2RGBA_YVYU",
    217             "YUV2BGRA_YVYU",
    218 
    219             "YUV2GRAY_UYVY",
    220             "YUV2GRAY_YUY2",
    221 
    222             // alpha premultiplication
    223             "RGBA2mRGBA",
    224             "mRGBA2RGBA",
    225 
    226             "COLORCVT_MAX"
    227         };
    228 
    229         *os << str[info.code];
    230     }
    231 
    232     static void printOsInfo()
    233     {
    234     #if defined _WIN32
    235     #   if defined _WIN64
    236             printf("[----------]\n[ GPU INFO ] \tRun on OS Windows x64.\n[----------]\n"), fflush(stdout);
    237     #   else
    238             printf("[----------]\n[ GPU INFO ] \tRun on OS Windows x32.\n[----------]\n"), fflush(stdout);
    239     #   endif
    240     #elif defined ANDROID
    241     #   if defined _LP64 || defined __LP64__
    242             printf("[----------]\n[ GPU INFO ] \tRun on OS Android x64.\n[----------]\n"), fflush(stdout);
    243     #   else
    244             printf("[----------]\n[ GPU INFO ] \tRun on OS Android x32.\n[----------]\n"), fflush(stdout);
    245     #   endif
    246     #elif defined __APPLE__
    247     #   if defined _LP64 || defined __LP64__
    248             printf("[----------]\n[ GPU INFO ] \tRun on OS Apple x64.\n[----------]\n"), fflush(stdout);
    249     #   else
    250             printf("[----------]\n[ GPU INFO ] \tRun on OS Apple x32.\n[----------]\n"), fflush(stdout);
    251     #   endif
    252     #elif defined linux
    253     #   if defined _LP64 || defined __LP64__
    254             printf("[----------]\n[ GPU INFO ] \tRun on OS Linux x64.\n[----------]\n"), fflush(stdout);
    255     #   else
    256             printf("[----------]\n[ GPU INFO ] \tRun on OS Linux x32.\n[----------]\n"), fflush(stdout);
    257     #   endif
    258     #endif
    259 
    260     }
    261 
    262     void printCudaInfo()
    263     {
    264         printOsInfo();
    265         for (int i = 0; i < cv::cuda::getCudaEnabledDeviceCount(); i++)
    266             cv::cuda::printCudaDeviceInfo(i);
    267     }
    268 
    269     struct KeypointIdxCompare
    270     {
    271         std::vector<cv::KeyPoint>* keypoints;
    272 
    273         explicit KeypointIdxCompare(std::vector<cv::KeyPoint>* _keypoints) : keypoints(_keypoints) {}
    274 
    275         bool operator ()(size_t i1, size_t i2) const
    276         {
    277             cv::KeyPoint kp1 = (*keypoints)[i1];
    278             cv::KeyPoint kp2 = (*keypoints)[i2];
    279             if (kp1.pt.x != kp2.pt.x)
    280                 return kp1.pt.x < kp2.pt.x;
    281             if (kp1.pt.y != kp2.pt.y)
    282                 return kp1.pt.y < kp2.pt.y;
    283             if (kp1.response != kp2.response)
    284                 return kp1.response < kp2.response;
    285             return kp1.octave < kp2.octave;
    286         }
    287     };
    288 
    289     void sortKeyPoints(std::vector<cv::KeyPoint>& keypoints, cv::InputOutputArray _descriptors)
    290     {
    291         std::vector<size_t> indexies(keypoints.size());
    292         for (size_t i = 0; i < indexies.size(); ++i)
    293             indexies[i] = i;
    294 
    295         std::sort(indexies.begin(), indexies.end(), KeypointIdxCompare(&keypoints));
    296 
    297         std::vector<cv::KeyPoint> new_keypoints;
    298         cv::Mat new_descriptors;
    299 
    300         new_keypoints.resize(keypoints.size());
    301 
    302         cv::Mat descriptors;
    303         if (_descriptors.needed())
    304         {
    305             descriptors = _descriptors.getMat();
    306             new_descriptors.create(descriptors.size(), descriptors.type());
    307         }
    308 
    309         for (size_t i = 0; i < indexies.size(); ++i)
    310         {
    311             size_t new_idx = indexies[i];
    312             new_keypoints[i] = keypoints[new_idx];
    313             if (!new_descriptors.empty())
    314                 descriptors.row((int) new_idx).copyTo(new_descriptors.row((int) i));
    315         }
    316 
    317         keypoints.swap(new_keypoints);
    318         if (_descriptors.needed())
    319             new_descriptors.copyTo(_descriptors);
    320     }
    321 }
    322