util.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifndef OPENCV_STITCHING_UTIL_HPP
  43. #define OPENCV_STITCHING_UTIL_HPP
  44. #include <list>
  45. #include "opencv2/core.hpp"
  46. namespace cv {
  47. namespace detail {
  48. //! @addtogroup stitching
  49. //! @{
  50. class CV_EXPORTS DisjointSets
  51. {
  52. public:
  53. DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); }
  54. void createOneElemSets(int elem_count);
  55. int findSetByElem(int elem);
  56. int mergeSets(int set1, int set2);
  57. std::vector<int> parent;
  58. std::vector<int> size;
  59. private:
  60. std::vector<int> rank_;
  61. };
  62. struct CV_EXPORTS GraphEdge
  63. {
  64. GraphEdge(int from, int to, float weight);
  65. bool operator <(const GraphEdge& other) const { return weight < other.weight; }
  66. bool operator >(const GraphEdge& other) const { return weight > other.weight; }
  67. int from, to;
  68. float weight;
  69. };
  70. inline GraphEdge::GraphEdge(int _from, int _to, float _weight) : from(_from), to(_to), weight(_weight) {}
  71. class CV_EXPORTS Graph
  72. {
  73. public:
  74. Graph(int num_vertices = 0) { create(num_vertices); }
  75. void create(int num_vertices) { edges_.assign(num_vertices, std::list<GraphEdge>()); }
  76. int numVertices() const { return static_cast<int>(edges_.size()); }
  77. void addEdge(int from, int to, float weight);
  78. template <typename B> B forEach(B body) const;
  79. template <typename B> B walkBreadthFirst(int from, B body) const;
  80. private:
  81. std::vector< std::list<GraphEdge> > edges_;
  82. };
  83. //////////////////////////////////////////////////////////////////////////////
  84. // Auxiliary functions
  85. CV_EXPORTS_W bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi);
  86. CV_EXPORTS_W Rect resultRoi(const std::vector<Point> &corners, const std::vector<UMat> &images);
  87. CV_EXPORTS_W Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes);
  88. CV_EXPORTS_W Rect resultRoiIntersection(const std::vector<Point> &corners, const std::vector<Size> &sizes);
  89. CV_EXPORTS_W Point resultTl(const std::vector<Point> &corners);
  90. // Returns random 'count' element subset of the {0,1,...,size-1} set
  91. CV_EXPORTS_W void selectRandomSubset(int count, int size, std::vector<int> &subset);
  92. CV_EXPORTS_W int& stitchingLogLevel();
  93. //! @}
  94. } // namespace detail
  95. } // namespace cv
  96. #include "util_inl.hpp"
  97. #endif // OPENCV_STITCHING_UTIL_HPP