Home | History | Annotate | Download | only in object_tracking
      1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 // NOTE: no native object detectors are currently provided or used by the code
     17 // in this directory. This class remains mainly for historical reasons.
     18 // Detection in the TF demo is done through TensorFlowMultiBoxDetector.java.
     19 
     20 // Contains ObjectModelBase declaration.
     21 
     22 #ifndef TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_DETECTION_OBJECT_MODEL_H_
     23 #define TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_DETECTION_OBJECT_MODEL_H_
     24 
     25 #ifdef __RENDER_OPENGL__
     26 #include <GLES/gl.h>
     27 #include <GLES/glext.h>
     28 #endif
     29 
     30 #include <vector>
     31 
     32 #include "tensorflow/examples/android/jni/object_tracking/geom.h"
     33 #include "tensorflow/examples/android/jni/object_tracking/image-inl.h"
     34 #include "tensorflow/examples/android/jni/object_tracking/image.h"
     35 #include "tensorflow/examples/android/jni/object_tracking/integral_image.h"
     36 #ifdef __RENDER_OPENGL__
     37 #include "tensorflow/examples/android/jni/object_tracking/sprite.h"
     38 #endif
     39 #include "tensorflow/examples/android/jni/object_tracking/utils.h"
     40 
     41 #include "tensorflow/examples/android/jni/object_tracking/config.h"
     42 #include "tensorflow/examples/android/jni/object_tracking/image_data.h"
     43 #include "tensorflow/examples/android/jni/object_tracking/keypoint.h"
     44 
     45 namespace tf_tracking {
     46 
     47 // The ObjectModelBase class represents all the known appearance information for
     48 // an object. It is not a specific instance of the object in the world,
     49 // but just the general appearance information that enables detection. An
     50 // ObjectModelBase can be reused across multiple-instances of TrackedObjects.
     51 class ObjectModelBase {
     52  public:
     53   ObjectModelBase(const std::string& name) : name_(name) {}
     54 
     55   virtual ~ObjectModelBase() {}
     56 
     57   // Called when the next step in an ongoing track occurs.
     58   virtual void TrackStep(const BoundingBox& position,
     59                          const Image<uint8_t>& image,
     60                          const IntegralImage& integral_image,
     61                          const bool authoritative) {}
     62 
     63   // Called when an object track is lost.
     64   virtual void TrackLost() {}
     65 
     66   // Called when an object track is confirmed as legitimate.
     67   virtual void TrackConfirmed() {}
     68 
     69   virtual float GetMaxCorrelation(const Image<float>& patch_image) const = 0;
     70 
     71   virtual MatchScore GetMatchScore(
     72       const BoundingBox& position, const ImageData& image_data) const = 0;
     73 
     74   virtual void Draw(float* const depth) const = 0;
     75 
     76   inline const std::string& GetName() const {
     77     return name_;
     78   }
     79 
     80  protected:
     81   const std::string name_;
     82 
     83  private:
     84   TF_DISALLOW_COPY_AND_ASSIGN(ObjectModelBase);
     85 };
     86 
     87 template <typename DetectorType>
     88 class ObjectModel : public ObjectModelBase {
     89  public:
     90   ObjectModel<DetectorType>(const DetectorType* const detector,
     91                             const std::string& name)
     92       : ObjectModelBase(name), detector_(detector) {}
     93 
     94  protected:
     95   const DetectorType* const detector_;
     96 
     97   TF_DISALLOW_COPY_AND_ASSIGN(ObjectModel<DetectorType>);
     98 };
     99 
    100 }  // namespace tf_tracking
    101 
    102 #endif  // TENSORFLOW_EXAMPLES_ANDROID_JNI_OBJECT_TRACKING_DETECTION_OBJECT_MODEL_H_
    103