opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 16 //
joeverbout 0:ea44dc9ed014 17 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 18 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 19 //
joeverbout 0:ea44dc9ed014 20 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 21 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 22 //
joeverbout 0:ea44dc9ed014 23 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 24 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 25 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 26 //
joeverbout 0:ea44dc9ed014 27 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 28 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 29 //
joeverbout 0:ea44dc9ed014 30 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 31 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 33 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 34 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 35 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 36 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 37 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 38 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 39 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 40 //
joeverbout 0:ea44dc9ed014 41 //M*/
joeverbout 0:ea44dc9ed014 42
joeverbout 0:ea44dc9ed014 43 #ifndef __OPENCV_STITCHING_UTIL_HPP__
joeverbout 0:ea44dc9ed014 44 #define __OPENCV_STITCHING_UTIL_HPP__
joeverbout 0:ea44dc9ed014 45
joeverbout 0:ea44dc9ed014 46 #include <list>
joeverbout 0:ea44dc9ed014 47 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 48
joeverbout 0:ea44dc9ed014 49 #ifndef ENABLE_LOG
joeverbout 0:ea44dc9ed014 50 #define ENABLE_LOG 0
joeverbout 0:ea44dc9ed014 51 #endif
joeverbout 0:ea44dc9ed014 52
joeverbout 0:ea44dc9ed014 53 // TODO remove LOG macros, add logging class
joeverbout 0:ea44dc9ed014 54 #if ENABLE_LOG
joeverbout 0:ea44dc9ed014 55 #ifdef ANDROID
joeverbout 0:ea44dc9ed014 56 #include <iostream>
joeverbout 0:ea44dc9ed014 57 #include <sstream>
joeverbout 0:ea44dc9ed014 58 #include <android/log.h>
joeverbout 0:ea44dc9ed014 59 #define LOG_STITCHING_MSG(msg) \
joeverbout 0:ea44dc9ed014 60 do { \
joeverbout 0:ea44dc9ed014 61 Stringstream _os; \
joeverbout 0:ea44dc9ed014 62 _os << msg; \
joeverbout 0:ea44dc9ed014 63 __android_log_print(ANDROID_LOG_DEBUG, "STITCHING", "%s", _os.str().c_str()); \
joeverbout 0:ea44dc9ed014 64 } while(0);
joeverbout 0:ea44dc9ed014 65 #else
joeverbout 0:ea44dc9ed014 66 #include <iostream>
joeverbout 0:ea44dc9ed014 67 #define LOG_STITCHING_MSG(msg) for(;;) { std::cout << msg; std::cout.flush(); break; }
joeverbout 0:ea44dc9ed014 68 #endif
joeverbout 0:ea44dc9ed014 69 #else
joeverbout 0:ea44dc9ed014 70 #define LOG_STITCHING_MSG(msg)
joeverbout 0:ea44dc9ed014 71 #endif
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 #define LOG_(_level, _msg) \
joeverbout 0:ea44dc9ed014 74 for(;;) \
joeverbout 0:ea44dc9ed014 75 { \
joeverbout 0:ea44dc9ed014 76 using namespace std; \
joeverbout 0:ea44dc9ed014 77 if ((_level) >= ::cv::detail::stitchingLogLevel()) \
joeverbout 0:ea44dc9ed014 78 { \
joeverbout 0:ea44dc9ed014 79 LOG_STITCHING_MSG(_msg); \
joeverbout 0:ea44dc9ed014 80 } \
joeverbout 0:ea44dc9ed014 81 break; \
joeverbout 0:ea44dc9ed014 82 }
joeverbout 0:ea44dc9ed014 83
joeverbout 0:ea44dc9ed014 84
joeverbout 0:ea44dc9ed014 85 #define LOG(msg) LOG_(1, msg)
joeverbout 0:ea44dc9ed014 86 #define LOG_CHAT(msg) LOG_(0, msg)
joeverbout 0:ea44dc9ed014 87
joeverbout 0:ea44dc9ed014 88 #define LOGLN(msg) LOG(msg << std::endl)
joeverbout 0:ea44dc9ed014 89 #define LOGLN_CHAT(msg) LOG_CHAT(msg << std::endl)
joeverbout 0:ea44dc9ed014 90
joeverbout 0:ea44dc9ed014 91 //#if DEBUG_LOG_CHAT
joeverbout 0:ea44dc9ed014 92 // #define LOG_CHAT(msg) LOG(msg)
joeverbout 0:ea44dc9ed014 93 // #define LOGLN_CHAT(msg) LOGLN(msg)
joeverbout 0:ea44dc9ed014 94 //#else
joeverbout 0:ea44dc9ed014 95 // #define LOG_CHAT(msg) do{}while(0)
joeverbout 0:ea44dc9ed014 96 // #define LOGLN_CHAT(msg) do{}while(0)
joeverbout 0:ea44dc9ed014 97 //#endif
joeverbout 0:ea44dc9ed014 98
joeverbout 0:ea44dc9ed014 99 namespace cv {
joeverbout 0:ea44dc9ed014 100 namespace detail {
joeverbout 0:ea44dc9ed014 101
joeverbout 0:ea44dc9ed014 102 //! @addtogroup stitching
joeverbout 0:ea44dc9ed014 103 //! @{
joeverbout 0:ea44dc9ed014 104
joeverbout 0:ea44dc9ed014 105 class CV_EXPORTS DisjointSets
joeverbout 0:ea44dc9ed014 106 {
joeverbout 0:ea44dc9ed014 107 public:
joeverbout 0:ea44dc9ed014 108 DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); }
joeverbout 0:ea44dc9ed014 109
joeverbout 0:ea44dc9ed014 110 void createOneElemSets(int elem_count);
joeverbout 0:ea44dc9ed014 111 int findSetByElem(int elem);
joeverbout 0:ea44dc9ed014 112 int mergeSets(int set1, int set2);
joeverbout 0:ea44dc9ed014 113
joeverbout 0:ea44dc9ed014 114 std::vector<int> parent;
joeverbout 0:ea44dc9ed014 115 std::vector<int> size;
joeverbout 0:ea44dc9ed014 116
joeverbout 0:ea44dc9ed014 117 private:
joeverbout 0:ea44dc9ed014 118 std::vector<int> rank_;
joeverbout 0:ea44dc9ed014 119 };
joeverbout 0:ea44dc9ed014 120
joeverbout 0:ea44dc9ed014 121
joeverbout 0:ea44dc9ed014 122 struct CV_EXPORTS GraphEdge
joeverbout 0:ea44dc9ed014 123 {
joeverbout 0:ea44dc9ed014 124 GraphEdge(int from, int to, float weight);
joeverbout 0:ea44dc9ed014 125 bool operator <(const GraphEdge& other) const { return weight < other.weight; }
joeverbout 0:ea44dc9ed014 126 bool operator >(const GraphEdge& other) const { return weight > other.weight; }
joeverbout 0:ea44dc9ed014 127
joeverbout 0:ea44dc9ed014 128 int from, to;
joeverbout 0:ea44dc9ed014 129 float weight;
joeverbout 0:ea44dc9ed014 130 };
joeverbout 0:ea44dc9ed014 131
joeverbout 0:ea44dc9ed014 132 inline GraphEdge::GraphEdge(int _from, int _to, float _weight) : from(_from), to(_to), weight(_weight) {}
joeverbout 0:ea44dc9ed014 133
joeverbout 0:ea44dc9ed014 134
joeverbout 0:ea44dc9ed014 135 class CV_EXPORTS Graph
joeverbout 0:ea44dc9ed014 136 {
joeverbout 0:ea44dc9ed014 137 public:
joeverbout 0:ea44dc9ed014 138 Graph(int num_vertices = 0) { create(num_vertices); }
joeverbout 0:ea44dc9ed014 139 void create(int num_vertices) { edges_.assign(num_vertices, std::list<GraphEdge>()); }
joeverbout 0:ea44dc9ed014 140 int numVertices() const { return static_cast<int>(edges_.size()); }
joeverbout 0:ea44dc9ed014 141 void addEdge(int from, int to, float weight);
joeverbout 0:ea44dc9ed014 142 template <typename B> B forEach(B body) const;
joeverbout 0:ea44dc9ed014 143 template <typename B> B walkBreadthFirst(int from, B body) const;
joeverbout 0:ea44dc9ed014 144
joeverbout 0:ea44dc9ed014 145 private:
joeverbout 0:ea44dc9ed014 146 std::vector< std::list<GraphEdge> > edges_;
joeverbout 0:ea44dc9ed014 147 };
joeverbout 0:ea44dc9ed014 148
joeverbout 0:ea44dc9ed014 149
joeverbout 0:ea44dc9ed014 150 //////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 151 // Auxiliary functions
joeverbout 0:ea44dc9ed014 152
joeverbout 0:ea44dc9ed014 153 CV_EXPORTS bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi);
joeverbout 0:ea44dc9ed014 154 CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<UMat> &images);
joeverbout 0:ea44dc9ed014 155 CV_EXPORTS Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes);
joeverbout 0:ea44dc9ed014 156 CV_EXPORTS Rect resultRoiIntersection(const std::vector<Point> &corners, const std::vector<Size> &sizes);
joeverbout 0:ea44dc9ed014 157 CV_EXPORTS Point resultTl(const std::vector<Point> &corners);
joeverbout 0:ea44dc9ed014 158
joeverbout 0:ea44dc9ed014 159 // Returns random 'count' element subset of the {0,1,...,size-1} set
joeverbout 0:ea44dc9ed014 160 CV_EXPORTS void selectRandomSubset(int count, int size, std::vector<int> &subset);
joeverbout 0:ea44dc9ed014 161
joeverbout 0:ea44dc9ed014 162 CV_EXPORTS int& stitchingLogLevel();
joeverbout 0:ea44dc9ed014 163
joeverbout 0:ea44dc9ed014 164 //! @}
joeverbout 0:ea44dc9ed014 165
joeverbout 0:ea44dc9ed014 166 } // namespace detail
joeverbout 0:ea44dc9ed014 167 } // namespace cv
joeverbout 0:ea44dc9ed014 168
joeverbout 0:ea44dc9ed014 169 #include "util_inl.hpp"
joeverbout 0:ea44dc9ed014 170
joeverbout 0:ea44dc9ed014 171 #endif // __OPENCV_STITCHING_UTIL_HPP__
joeverbout 0:ea44dc9ed014 172