├── .classpath
├── .cproject
├── .gitignore
├── .project
├── AlogLogo.xcf
├── AndroidManifest.xml
├── README.md
├── TesseractProjection_700.gif
├── jni
├── Android.mk
├── Application.mk
├── Matcher.cpp
├── Matcher.h
├── SfMmatcher.i
├── SfMmatcher_wrap.cpp
├── SfMpipeline.i
├── SfMpipeline_wrap.cpp
├── data.pb.cpp
├── data.pb.h
├── data.proto
├── frame.cpp
├── frame.h
├── libopencv_nonfree.a
├── libprotobuf.so
├── matches.pb.cpp
├── matches.pb.h
└── matches.proto
├── libs
├── android-support-v4.jar
├── armeabi-v7a
│ ├── libpipeline_native.so
│ └── libprotobuf.so
└── protobuf-java-2.4.1.jar
├── logo_google_developers.svg
├── proguard-project.txt
├── project.properties
├── res
├── drawable-xhdpi
│ └── ic_launcher.png
├── layout
│ ├── main.xml
│ └── viewmats.xml
├── menu
│ └── main.xml
├── values-large
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
├── cvg
└── sfmPipeline
│ └── main
│ ├── FpsMeter.java
│ ├── Frame.java
│ ├── FrameProcess.java
│ ├── Matcher.java
│ ├── MatcherFLANN.java
│ ├── MatchesOutMessage.java
│ ├── PipelineActivity.java
│ ├── PipelineCom.java
│ ├── PipelineOutMessage.java
│ ├── PipelineProcess.java
│ ├── PipelineSharedData.java
│ ├── ProtoWriter.java
│ ├── SWIGTYPE_p_cv__Mat.java
│ ├── SensorService.java
│ ├── TCPread.java
│ ├── Timer.java
│ ├── UDPsend.java
│ ├── UDPthread.java
│ ├── VideoGrabber.java
│ ├── sfmmatcher.java
│ ├── sfmmatcherJNI.java
│ ├── sfmpipeline.java
│ └── sfmpipelineJNI.java
├── data.proto
└── matches.proto
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | protobuf/
15 | obj/
16 | .settings/
17 |
18 | # Local configuration file (sdk path, etc)
19 | local.properties
20 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SfMpipeline
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 |
11 |
12 |
13 |
14 |
15 | com.android.ide.eclipse.adt.ResourceManagerBuilder
16 |
17 |
18 |
19 |
20 | com.android.ide.eclipse.adt.PreCompilerBuilder
21 |
22 |
23 |
24 |
25 | org.eclipse.jdt.core.javabuilder
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.ApkBuilder
31 |
32 |
33 |
34 |
35 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
36 | full,incremental,
37 |
38 |
39 |
40 |
41 |
42 | com.android.ide.eclipse.adt.AndroidNature
43 | org.eclipse.jdt.core.javanature
44 | org.eclipse.cdt.core.cnature
45 | org.eclipse.cdt.core.ccnature
46 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
47 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
48 |
49 |
50 |
--------------------------------------------------------------------------------
/AlogLogo.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/AlogLogo.xcf
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android-SfM-client
2 | ==================
3 |
4 | Full documentation at https://wiki.cvg.ethz.ch/doku.php?id=sfm:android
5 |
6 |
7 | Application to leverage a Structure from Motion pipeline by extracting features and matching frames onboard using OpenCV 2.4.2. The data gathered along with gravity sensor data is broadcasted via UDP serialized using Google's Protobuff. Multithreaded application using native C++ openCV code for SURF detection/extraction, creating and using C++ objects from Java using SWIG.
8 |
9 | Compilation Instructions
10 | ========================
11 |
12 | In order to be able to compile the native code found in the jni/ folder, the Android NDK framework must be present, as well as OpenCV4Android > 2.4.2, on the target and host.
13 | The JNI makefile (Android.mk) has a machine-specific path for the OpenCV location, please change that line to match the location of the required file in your machine. Additionally,
14 | since starting from OpenCV4Android 2.4.2 the nonfree module is no longer included, you must add the header files manually to your OpenCV4Android header files. The compilation will
15 | refer to those files for compilation of the extraction and detection part in "frame.cpp". The actual static library is already included in the jni/ folder (libopencv_nonfree.a). This
16 | was compiled for armv7 architecture, so if you have a different architecture please recompile the OpenCV nonfree module for your specific target. To do so, download the latest OpenCV
17 | tarball for Linux, go into the android/ folder and follow the installation instructions there.
--------------------------------------------------------------------------------
/TesseractProjection_700.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/TesseractProjection_700.gif
--------------------------------------------------------------------------------
/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_MODULE := libprotobuf
5 | LOCAL_SRC_FILES := libprotobuf.so
6 |
7 | include $(PREBUILT_SHARED_LIBRARY)
8 |
9 | include $(CLEAR_VARS)
10 |
11 | LOCAL_MODULE := opencv_nonfree
12 | LOCAL_SRC_FILES := libopencv_nonfree.a
13 |
14 | include $(PREBUILT_STATIC_LIBRARY)
15 |
16 |
17 | #include protobuf/Android.mk #comment all other lines and run ndk to recompile protobuf native share library
18 |
19 | include $(CLEAR_VARS)
20 | #LOCAL_PATH := $(call my-dir)
21 | LOCAL_PATH := /home/fede/workspace2/SfMpipeline/jni
22 |
23 | OPENCV_CAMERA_MODULES:=off
24 |
25 | OPENCV_MK_PATH:=/home/fede/apps/opencvAndroid-2.4.2/sdk/native/jni/OpenCV.mk
26 | #OPENCV_MK_PATH:=/home/fede/AndroidSDK/OpenCV-2.4.1-android/OpenCV-2.4.1/share/opencv/OpenCV.mk
27 |
28 | include $(OPENCV_MK_PATH)
29 |
30 | LOCAL_MODULE := pipeline_native
31 | LOCAL_SRC_FILES := frame.cpp data.pb.cpp Matcher.cpp matches.pb.cpp SfMmatcher_wrap.cpp
32 | LOCAL_CFLAGS := -frtti -g
33 | LOCAL_STATIC_LIBRARIES := opencv_nonfree
34 | LOCAL_LDLIBS += -llog -ldl jni/libprotobuf.so
35 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/../protobuf/src
36 | APP_OPTIM = debug
37 |
38 | include $(BUILD_SHARED_LIBRARY)
39 |
--------------------------------------------------------------------------------
/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := gnustl_static
2 | APP_CPPFLAGS := -frtti -fexceptions
3 | APP_ABI := armeabi-v7a
4 | APP_MODULES := pipeline_native libprotobuf
5 |
--------------------------------------------------------------------------------
/jni/Matcher.cpp:
--------------------------------------------------------------------------------
1 | #include "Matcher.h"
2 | #include "matches.pb.h"
3 |
4 | MatcherFLANN::MatcherFLANN(Frame & frame1, Frame & frame2)
5 | {
6 | first = frame1;
7 | second = frame2;
8 | }
9 |
10 | void MatcherFLANN::match(const cv::Mat &preDesc, const cv::Mat &curDesc,
11 | std::vector& matches)
12 | {
13 | matches.clear();
14 |
15 | std::vector< cv::DMatch > raw_matches;
16 |
17 | cv::FlannBasedMatcher flannMatcher;
18 | flannMatcher.match(preDesc, curDesc, raw_matches);
19 | double max_dist = 0; double min_dist = 100;
20 |
21 | //-- Quick calculation of max and min distances between keypoints
22 | for( int i = 0; i < preDesc.rows; i++ )
23 | {
24 | double dist = raw_matches[i].distance;
25 | if( dist < min_dist ) min_dist = dist;
26 | if( dist > max_dist ) max_dist = dist;
27 | }
28 |
29 | for( int i = 0; i < preDesc.rows; i++ )
30 | {
31 | if( raw_matches[i].distance < 5*min_dist )
32 | matches.push_back( raw_matches[i]);
33 | }
34 | }
35 |
36 |
37 | bool MatcherFLANN::matchFrames(int seq1, int seq2)
38 | {
39 | if(first.Descriptors.rows > 0 && second.Descriptors.rows > 0)
40 | {
41 | firstId = seq1;
42 | secondId = seq2;
43 | match(first.Descriptors, second.Descriptors, matchesFrames);
44 | return matchesFrames.size() > 0;
45 | }else
46 | return false;
47 | }
48 |
49 | bool MatcherFLANN::buildMatchProtoMessage()
50 | {
51 | if(matchesFrames.size() > 0)
52 | {
53 | sfm::MatchesProto matchProto;
54 | matchProto.set_imagelseq(firstId);
55 | matchProto.set_imagerseq(secondId);
56 | for(int i(0); i < matchesFrames.size(); i++)
57 | {
58 | sfm::DMatches * protoDMatches = matchProto.add_matches();
59 | protoDMatches->set_distance(matchesFrames[i].distance);
60 | protoDMatches->set_imgidx(matchesFrames[i].imgIdx);
61 | protoDMatches->set_queryidx(matchesFrames[i].queryIdx);
62 | protoDMatches->set_trainidx(matchesFrames[i].trainIdx);
63 | }
64 | int size = matchProto.ByteSize();
65 | signed char * buffer = new signed char[size];
66 | bool protoGood = matchProto.SerializeToArray(buffer, size);
67 | outMatch = buffer;
68 | sizeOut = (size_t)size;
69 |
70 | return protoGood;
71 | }else
72 | return false;
73 | }
74 |
--------------------------------------------------------------------------------
/jni/Matcher.h:
--------------------------------------------------------------------------------
1 | #ifndef MATCHER_H_
2 | #define MATCHER_H_
3 |
4 | #include
5 | #include
6 |
7 | #include "frame.h"
8 |
9 | class Matcher
10 | {
11 |
12 | };
13 |
14 | class MatcherFLANN : public Matcher
15 | {
16 | private:
17 | Frame first;
18 | Frame second;
19 | int firstId;
20 | int secondId;
21 | std::vector matchesFrames;
22 | size_t sizeOut;
23 | signed char * outMatch;
24 | void match(const cv::Mat &, const cv::Mat &, std::vector& );
25 |
26 | public:
27 | MatcherFLANN(Frame &, Frame &);
28 | bool matchFrames(int, int);
29 | bool buildMatchProtoMessage();
30 | signed char * getMatches(size_t *len){*len = sizeOut; return outMatch;}
31 | };
32 |
33 | #endif /* MATCHER_H_ */
34 |
--------------------------------------------------------------------------------
/jni/SfMmatcher.i:
--------------------------------------------------------------------------------
1 | %module sfmmatcher
2 |
3 | %{
4 |
5 | #include "Matcher.h"
6 | #include "frame.h"
7 | %}
8 |
9 | %typemap(jni) signed char *getMatches "jbyteArray"
10 | %typemap(jtype) signed char *getMatches "byte[]"
11 | %typemap(jstype) signed char *getMatches "byte[]"
12 | %typemap(javaout) signed char *getMatches {
13 | return $jnicall;
14 | }
15 | %typemap(in,numinputs=0,noblock=1) size_t *len {
16 | size_t length=0;
17 | $1 = &length;
18 | }
19 | %typemap(out) signed char *getMatches {
20 | $result = JCALL1(NewByteArray, jenv, length);
21 | JCALL4(SetByteArrayRegion, jenv, $result, 0, length, $1);
22 | }
23 |
24 | %typemap(jni) signed char *getFrame "jbyteArray"
25 | %typemap(jtype) signed char *getFrame "byte[]"
26 | %typemap(jstype) signed char *getFrame "byte[]"
27 | %typemap(javaout) signed char *getFrame {
28 | return $jnicall;
29 | }
30 | %typemap(in,numinputs=0,noblock=1) size_t *len {
31 | size_t length=0;
32 | $1 = &length;
33 | }
34 | %typemap(out) signed char *getFrame {
35 | $result = JCALL1(NewByteArray, jenv, length);
36 | JCALL4(SetByteArrayRegion, jenv, $result, 0, length, $1);
37 | }
38 |
39 | %include "Matcher.h"
40 | %include "frame.h"
--------------------------------------------------------------------------------
/jni/SfMmatcher_wrap.cpp:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * This file is not intended to be easily readable and contains a number of
6 | * coding conventions designed to improve portability and efficiency. Do not make
7 | * changes to this file unless you know what you are doing--modify the SWIG
8 | * interface file instead.
9 | * ----------------------------------------------------------------------------- */
10 |
11 | #define SWIGJAVA
12 |
13 |
14 | #ifdef __cplusplus
15 | /* SwigValueWrapper is described in swig.swg */
16 | template class SwigValueWrapper {
17 | struct SwigMovePointer {
18 | T *ptr;
19 | SwigMovePointer(T *p) : ptr(p) { }
20 | ~SwigMovePointer() { delete ptr; }
21 | SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
22 | } pointer;
23 | SwigValueWrapper& operator=(const SwigValueWrapper& rhs);
24 | SwigValueWrapper(const SwigValueWrapper& rhs);
25 | public:
26 | SwigValueWrapper() : pointer(0) { }
27 | SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
28 | operator T&() const { return *pointer.ptr; }
29 | T *operator&() { return pointer.ptr; }
30 | };
31 |
32 | template T SwigValueInit() {
33 | return T();
34 | }
35 | #endif
36 |
37 | /* -----------------------------------------------------------------------------
38 | * This section contains generic SWIG labels for method/variable
39 | * declarations/attributes, and other compiler dependent labels.
40 | * ----------------------------------------------------------------------------- */
41 |
42 | /* template workaround for compilers that cannot correctly implement the C++ standard */
43 | #ifndef SWIGTEMPLATEDISAMBIGUATOR
44 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
45 | # define SWIGTEMPLATEDISAMBIGUATOR template
46 | # elif defined(__HP_aCC)
47 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
48 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
49 | # define SWIGTEMPLATEDISAMBIGUATOR template
50 | # else
51 | # define SWIGTEMPLATEDISAMBIGUATOR
52 | # endif
53 | #endif
54 |
55 | /* inline attribute */
56 | #ifndef SWIGINLINE
57 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
58 | # define SWIGINLINE inline
59 | # else
60 | # define SWIGINLINE
61 | # endif
62 | #endif
63 |
64 | /* attribute recognised by some compilers to avoid 'unused' warnings */
65 | #ifndef SWIGUNUSED
66 | # if defined(__GNUC__)
67 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
68 | # define SWIGUNUSED __attribute__ ((__unused__))
69 | # else
70 | # define SWIGUNUSED
71 | # endif
72 | # elif defined(__ICC)
73 | # define SWIGUNUSED __attribute__ ((__unused__))
74 | # else
75 | # define SWIGUNUSED
76 | # endif
77 | #endif
78 |
79 | #ifndef SWIG_MSC_UNSUPPRESS_4505
80 | # if defined(_MSC_VER)
81 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */
82 | # endif
83 | #endif
84 |
85 | #ifndef SWIGUNUSEDPARM
86 | # ifdef __cplusplus
87 | # define SWIGUNUSEDPARM(p)
88 | # else
89 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED
90 | # endif
91 | #endif
92 |
93 | /* internal SWIG method */
94 | #ifndef SWIGINTERN
95 | # define SWIGINTERN static SWIGUNUSED
96 | #endif
97 |
98 | /* internal inline SWIG method */
99 | #ifndef SWIGINTERNINLINE
100 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
101 | #endif
102 |
103 | /* exporting methods */
104 | #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
105 | # ifndef GCC_HASCLASSVISIBILITY
106 | # define GCC_HASCLASSVISIBILITY
107 | # endif
108 | #endif
109 |
110 | #ifndef SWIGEXPORT
111 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
112 | # if defined(STATIC_LINKED)
113 | # define SWIGEXPORT
114 | # else
115 | # define SWIGEXPORT __declspec(dllexport)
116 | # endif
117 | # else
118 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
119 | # define SWIGEXPORT __attribute__ ((visibility("default")))
120 | # else
121 | # define SWIGEXPORT
122 | # endif
123 | # endif
124 | #endif
125 |
126 | /* calling conventions for Windows */
127 | #ifndef SWIGSTDCALL
128 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
129 | # define SWIGSTDCALL __stdcall
130 | # else
131 | # define SWIGSTDCALL
132 | # endif
133 | #endif
134 |
135 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
136 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
137 | # define _CRT_SECURE_NO_DEPRECATE
138 | #endif
139 |
140 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
141 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
142 | # define _SCL_SECURE_NO_DEPRECATE
143 | #endif
144 |
145 |
146 |
147 | /* Fix for jlong on some versions of gcc on Windows */
148 | #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
149 | typedef long long __int64;
150 | #endif
151 |
152 | /* Fix for jlong on 64-bit x86 Solaris */
153 | #if defined(__x86_64)
154 | # ifdef _LP64
155 | # undef _LP64
156 | # endif
157 | #endif
158 |
159 | #include
160 | #include
161 | #include
162 |
163 |
164 | /* Support for throwing Java exceptions */
165 | typedef enum {
166 | SWIG_JavaOutOfMemoryError = 1,
167 | SWIG_JavaIOException,
168 | SWIG_JavaRuntimeException,
169 | SWIG_JavaIndexOutOfBoundsException,
170 | SWIG_JavaArithmeticException,
171 | SWIG_JavaIllegalArgumentException,
172 | SWIG_JavaNullPointerException,
173 | SWIG_JavaDirectorPureVirtual,
174 | SWIG_JavaUnknownError
175 | } SWIG_JavaExceptionCodes;
176 |
177 | typedef struct {
178 | SWIG_JavaExceptionCodes code;
179 | const char *java_exception;
180 | } SWIG_JavaExceptions_t;
181 |
182 |
183 | static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
184 | jclass excep;
185 | static const SWIG_JavaExceptions_t java_exceptions[] = {
186 | { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
187 | { SWIG_JavaIOException, "java/io/IOException" },
188 | { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
189 | { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
190 | { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
191 | { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
192 | { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
193 | { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
194 | { SWIG_JavaUnknownError, "java/lang/UnknownError" },
195 | { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
196 | };
197 | const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
198 |
199 | while (except_ptr->code != code && except_ptr->code)
200 | except_ptr++;
201 |
202 | jenv->ExceptionClear();
203 | excep = jenv->FindClass(except_ptr->java_exception);
204 | if (excep)
205 | jenv->ThrowNew(excep, msg);
206 | }
207 |
208 |
209 | /* Contract support */
210 |
211 | #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
212 |
213 |
214 |
215 | #include "Matcher.h"
216 | #include "frame.h"
217 |
218 |
219 | #ifdef __cplusplus
220 | extern "C" {
221 | #endif
222 |
223 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_new_1Matcher(JNIEnv *jenv, jclass jcls) {
224 | jlong jresult = 0 ;
225 | Matcher *result = 0 ;
226 |
227 | (void)jenv;
228 | (void)jcls;
229 | result = (Matcher *)new Matcher();
230 | *(Matcher **)&jresult = result;
231 | return jresult;
232 | }
233 |
234 |
235 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_delete_1Matcher(JNIEnv *jenv, jclass jcls, jlong jarg1) {
236 | Matcher *arg1 = (Matcher *) 0 ;
237 |
238 | (void)jenv;
239 | (void)jcls;
240 | arg1 = *(Matcher **)&jarg1;
241 | delete arg1;
242 | }
243 |
244 |
245 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_new_1MatcherFLANN(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
246 | jlong jresult = 0 ;
247 | Frame arg1 ;
248 | Frame arg2 ;
249 | Frame *argp1 ;
250 | Frame *argp2 ;
251 | MatcherFLANN *result = 0 ;
252 |
253 | (void)jenv;
254 | (void)jcls;
255 | (void)jarg1_;
256 | (void)jarg2_;
257 | argp1 = *(Frame **)&jarg1;
258 | if (!argp1) {
259 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null Frame");
260 | return 0;
261 | }
262 | arg1 = *argp1;
263 | argp2 = *(Frame **)&jarg2;
264 | if (!argp2) {
265 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null Frame");
266 | return 0;
267 | }
268 | arg2 = *argp2;
269 | result = (MatcherFLANN *)new MatcherFLANN(arg1,arg2);
270 | *(MatcherFLANN **)&jresult = result;
271 | return jresult;
272 | }
273 |
274 |
275 | SWIGEXPORT jboolean JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_MatcherFLANN_1matchFrames(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jint jarg3) {
276 | jboolean jresult = 0 ;
277 | MatcherFLANN *arg1 = (MatcherFLANN *) 0 ;
278 | int arg2 ;
279 | int arg3 ;
280 | bool result;
281 |
282 | (void)jenv;
283 | (void)jcls;
284 | (void)jarg1_;
285 | arg1 = *(MatcherFLANN **)&jarg1;
286 | arg2 = (int)jarg2;
287 | arg3 = (int)jarg3;
288 | result = (bool)(arg1)->matchFrames(arg2,arg3);
289 | jresult = (jboolean)result;
290 | return jresult;
291 | }
292 |
293 |
294 | SWIGEXPORT jboolean JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_MatcherFLANN_1buildMatchProtoMessage(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
295 | jboolean jresult = 0 ;
296 | MatcherFLANN *arg1 = (MatcherFLANN *) 0 ;
297 | bool result;
298 |
299 | (void)jenv;
300 | (void)jcls;
301 | (void)jarg1_;
302 | arg1 = *(MatcherFLANN **)&jarg1;
303 | result = (bool)(arg1)->buildMatchProtoMessage();
304 | jresult = (jboolean)result;
305 | return jresult;
306 | }
307 |
308 |
309 | SWIGEXPORT jbyteArray JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_MatcherFLANN_1getMatches(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
310 | jbyteArray jresult = 0 ;
311 | MatcherFLANN *arg1 = (MatcherFLANN *) 0 ;
312 | size_t *arg2 = (size_t *) 0 ;
313 | signed char *result = 0 ;
314 |
315 | (void)jenv;
316 | (void)jcls;
317 | size_t length=0;
318 | arg2 = &length;
319 | (void)jarg1_;
320 | arg1 = *(MatcherFLANN **)&jarg1;
321 | result = (signed char *)(arg1)->getMatches(arg2);
322 | {
323 | jresult = jenv->NewByteArray(length);
324 | jenv->SetByteArrayRegion(jresult, 0, length, result);
325 | }
326 | return jresult;
327 | }
328 |
329 |
330 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_delete_1MatcherFLANN(JNIEnv *jenv, jclass jcls, jlong jarg1) {
331 | MatcherFLANN *arg1 = (MatcherFLANN *) 0 ;
332 |
333 | (void)jenv;
334 | (void)jcls;
335 | arg1 = *(MatcherFLANN **)&jarg1;
336 | delete arg1;
337 | }
338 |
339 |
340 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_new_1Frame_1_1SWIG_10(JNIEnv *jenv, jclass jcls) {
341 | jlong jresult = 0 ;
342 | Frame *result = 0 ;
343 |
344 | (void)jenv;
345 | (void)jcls;
346 | result = (Frame *)new Frame();
347 | *(Frame **)&jresult = result;
348 | return jresult;
349 | }
350 |
351 |
352 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_new_1Frame_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1) {
353 | jlong jresult = 0 ;
354 | cv::Mat *arg1 = 0 ;
355 | Frame *result = 0 ;
356 |
357 | (void)jenv;
358 | (void)jcls;
359 | arg1 = *(cv::Mat **)&jarg1;
360 | if (!arg1) {
361 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "cv::Mat & reference is null");
362 | return 0;
363 | }
364 | result = (Frame *)new Frame(*arg1);
365 | *(Frame **)&jresult = result;
366 | return jresult;
367 | }
368 |
369 |
370 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_Frame_1extractFeatures(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
371 | Frame *arg1 = (Frame *) 0 ;
372 |
373 | (void)jenv;
374 | (void)jcls;
375 | (void)jarg1_;
376 | arg1 = *(Frame **)&jarg1;
377 | (arg1)->extractFeatures();
378 | }
379 |
380 |
381 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_Frame_1addFrame(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
382 | Frame *arg1 = (Frame *) 0 ;
383 | cv::Mat *arg2 = 0 ;
384 |
385 | (void)jenv;
386 | (void)jcls;
387 | (void)jarg1_;
388 | arg1 = *(Frame **)&jarg1;
389 | arg2 = *(cv::Mat **)&jarg2;
390 | if (!arg2) {
391 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "cv::Mat & reference is null");
392 | return ;
393 | }
394 | (arg1)->addFrame(*arg2);
395 | }
396 |
397 |
398 | SWIGEXPORT jboolean JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_Frame_1buildFrameProtoMessage(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jboolean jarg2) {
399 | jboolean jresult = 0 ;
400 | Frame *arg1 = (Frame *) 0 ;
401 | bool arg2 ;
402 | bool result;
403 |
404 | (void)jenv;
405 | (void)jcls;
406 | (void)jarg1_;
407 | arg1 = *(Frame **)&jarg1;
408 | arg2 = jarg2 ? true : false;
409 | result = (bool)(arg1)->buildFrameProtoMessage(arg2);
410 | jresult = (jboolean)result;
411 | return jresult;
412 | }
413 |
414 |
415 | SWIGEXPORT jbyteArray JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_Frame_1getFrame(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
416 | jbyteArray jresult = 0 ;
417 | Frame *arg1 = (Frame *) 0 ;
418 | size_t *arg2 = (size_t *) 0 ;
419 | signed char *result = 0 ;
420 |
421 | (void)jenv;
422 | (void)jcls;
423 | size_t length=0;
424 | arg2 = &length;
425 | (void)jarg1_;
426 | arg1 = *(Frame **)&jarg1;
427 | result = (signed char *)(arg1)->getFrame(arg2);
428 | {
429 | jresult = jenv->NewByteArray(length);
430 | jenv->SetByteArrayRegion(jresult, 0, length, result);
431 | }
432 | return jresult;
433 | }
434 |
435 |
436 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_Frame_1Descriptors_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
437 | Frame *arg1 = (Frame *) 0 ;
438 | cv::Mat arg2 ;
439 | cv::Mat *argp2 ;
440 |
441 | (void)jenv;
442 | (void)jcls;
443 | (void)jarg1_;
444 | arg1 = *(Frame **)&jarg1;
445 | argp2 = *(cv::Mat **)&jarg2;
446 | if (!argp2) {
447 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null cv::Mat");
448 | return ;
449 | }
450 | arg2 = *argp2;
451 | if (arg1) (arg1)->Descriptors = arg2;
452 | }
453 |
454 |
455 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_Frame_1Descriptors_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
456 | jlong jresult = 0 ;
457 | Frame *arg1 = (Frame *) 0 ;
458 | cv::Mat result;
459 |
460 | (void)jenv;
461 | (void)jcls;
462 | (void)jarg1_;
463 | arg1 = *(Frame **)&jarg1;
464 | result = ((arg1)->Descriptors);
465 | *(cv::Mat **)&jresult = new cv::Mat((const cv::Mat &)result);
466 | return jresult;
467 | }
468 |
469 |
470 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_delete_1Frame(JNIEnv *jenv, jclass jcls, jlong jarg1) {
471 | Frame *arg1 = (Frame *) 0 ;
472 |
473 | (void)jenv;
474 | (void)jcls;
475 | arg1 = *(Frame **)&jarg1;
476 | delete arg1;
477 | }
478 |
479 |
480 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmmatcherJNI_MatcherFLANN_1SWIGUpcast(JNIEnv *jenv, jclass jcls, jlong jarg1) {
481 | jlong baseptr = 0;
482 | (void)jenv;
483 | (void)jcls;
484 | *(Matcher **)&baseptr = *(MatcherFLANN **)&jarg1;
485 | return baseptr;
486 | }
487 |
488 | #ifdef __cplusplus
489 | }
490 | #endif
491 |
492 |
--------------------------------------------------------------------------------
/jni/SfMpipeline.i:
--------------------------------------------------------------------------------
1 | %module sfmpipeline
2 |
3 | %{
4 | #include "frame.h"
5 | %}
6 |
7 | %typemap(jni) signed char *getFrame "jbyteArray"
8 | %typemap(jtype) signed char *getFrame "byte[]"
9 | %typemap(jstype) signed char *getFrame "byte[]"
10 | %typemap(javaout) signed char *getFrame {
11 | return $jnicall;
12 | }
13 | %typemap(in,numinputs=0,noblock=1) size_t *len {
14 | size_t length=0;
15 | $1 = &length;
16 | }
17 | %typemap(out) signed char *getFrame {
18 | $result = JCALL1(NewByteArray, jenv, length);
19 | JCALL4(SetByteArrayRegion, jenv, $result, 0, length, $1);
20 | }
21 |
22 |
23 | %include "frame.h"
--------------------------------------------------------------------------------
/jni/SfMpipeline_wrap.cpp:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * This file is not intended to be easily readable and contains a number of
6 | * coding conventions designed to improve portability and efficiency. Do not make
7 | * changes to this file unless you know what you are doing--modify the SWIG
8 | * interface file instead.
9 | * ----------------------------------------------------------------------------- */
10 |
11 | #define SWIGJAVA
12 |
13 |
14 | #ifdef __cplusplus
15 | /* SwigValueWrapper is described in swig.swg */
16 | template class SwigValueWrapper {
17 | struct SwigMovePointer {
18 | T *ptr;
19 | SwigMovePointer(T *p) : ptr(p) { }
20 | ~SwigMovePointer() { delete ptr; }
21 | SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
22 | } pointer;
23 | SwigValueWrapper& operator=(const SwigValueWrapper& rhs);
24 | SwigValueWrapper(const SwigValueWrapper& rhs);
25 | public:
26 | SwigValueWrapper() : pointer(0) { }
27 | SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
28 | operator T&() const { return *pointer.ptr; }
29 | T *operator&() { return pointer.ptr; }
30 | };
31 |
32 | template T SwigValueInit() {
33 | return T();
34 | }
35 | #endif
36 |
37 | /* -----------------------------------------------------------------------------
38 | * This section contains generic SWIG labels for method/variable
39 | * declarations/attributes, and other compiler dependent labels.
40 | * ----------------------------------------------------------------------------- */
41 |
42 | /* template workaround for compilers that cannot correctly implement the C++ standard */
43 | #ifndef SWIGTEMPLATEDISAMBIGUATOR
44 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
45 | # define SWIGTEMPLATEDISAMBIGUATOR template
46 | # elif defined(__HP_aCC)
47 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
48 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
49 | # define SWIGTEMPLATEDISAMBIGUATOR template
50 | # else
51 | # define SWIGTEMPLATEDISAMBIGUATOR
52 | # endif
53 | #endif
54 |
55 | /* inline attribute */
56 | #ifndef SWIGINLINE
57 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
58 | # define SWIGINLINE inline
59 | # else
60 | # define SWIGINLINE
61 | # endif
62 | #endif
63 |
64 | /* attribute recognised by some compilers to avoid 'unused' warnings */
65 | #ifndef SWIGUNUSED
66 | # if defined(__GNUC__)
67 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
68 | # define SWIGUNUSED __attribute__ ((__unused__))
69 | # else
70 | # define SWIGUNUSED
71 | # endif
72 | # elif defined(__ICC)
73 | # define SWIGUNUSED __attribute__ ((__unused__))
74 | # else
75 | # define SWIGUNUSED
76 | # endif
77 | #endif
78 |
79 | #ifndef SWIG_MSC_UNSUPPRESS_4505
80 | # if defined(_MSC_VER)
81 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */
82 | # endif
83 | #endif
84 |
85 | #ifndef SWIGUNUSEDPARM
86 | # ifdef __cplusplus
87 | # define SWIGUNUSEDPARM(p)
88 | # else
89 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED
90 | # endif
91 | #endif
92 |
93 | /* internal SWIG method */
94 | #ifndef SWIGINTERN
95 | # define SWIGINTERN static SWIGUNUSED
96 | #endif
97 |
98 | /* internal inline SWIG method */
99 | #ifndef SWIGINTERNINLINE
100 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
101 | #endif
102 |
103 | /* exporting methods */
104 | #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
105 | # ifndef GCC_HASCLASSVISIBILITY
106 | # define GCC_HASCLASSVISIBILITY
107 | # endif
108 | #endif
109 |
110 | #ifndef SWIGEXPORT
111 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
112 | # if defined(STATIC_LINKED)
113 | # define SWIGEXPORT
114 | # else
115 | # define SWIGEXPORT __declspec(dllexport)
116 | # endif
117 | # else
118 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
119 | # define SWIGEXPORT __attribute__ ((visibility("default")))
120 | # else
121 | # define SWIGEXPORT
122 | # endif
123 | # endif
124 | #endif
125 |
126 | /* calling conventions for Windows */
127 | #ifndef SWIGSTDCALL
128 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
129 | # define SWIGSTDCALL __stdcall
130 | # else
131 | # define SWIGSTDCALL
132 | # endif
133 | #endif
134 |
135 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
136 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
137 | # define _CRT_SECURE_NO_DEPRECATE
138 | #endif
139 |
140 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
141 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
142 | # define _SCL_SECURE_NO_DEPRECATE
143 | #endif
144 |
145 |
146 |
147 | /* Fix for jlong on some versions of gcc on Windows */
148 | #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
149 | typedef long long __int64;
150 | #endif
151 |
152 | /* Fix for jlong on 64-bit x86 Solaris */
153 | #if defined(__x86_64)
154 | # ifdef _LP64
155 | # undef _LP64
156 | # endif
157 | #endif
158 |
159 | #include
160 | #include
161 | #include
162 |
163 |
164 | /* Support for throwing Java exceptions */
165 | typedef enum {
166 | SWIG_JavaOutOfMemoryError = 1,
167 | SWIG_JavaIOException,
168 | SWIG_JavaRuntimeException,
169 | SWIG_JavaIndexOutOfBoundsException,
170 | SWIG_JavaArithmeticException,
171 | SWIG_JavaIllegalArgumentException,
172 | SWIG_JavaNullPointerException,
173 | SWIG_JavaDirectorPureVirtual,
174 | SWIG_JavaUnknownError
175 | } SWIG_JavaExceptionCodes;
176 |
177 | typedef struct {
178 | SWIG_JavaExceptionCodes code;
179 | const char *java_exception;
180 | } SWIG_JavaExceptions_t;
181 |
182 |
183 | static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
184 | jclass excep;
185 | static const SWIG_JavaExceptions_t java_exceptions[] = {
186 | { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
187 | { SWIG_JavaIOException, "java/io/IOException" },
188 | { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
189 | { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
190 | { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
191 | { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
192 | { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
193 | { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
194 | { SWIG_JavaUnknownError, "java/lang/UnknownError" },
195 | { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
196 | };
197 | const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
198 |
199 | while (except_ptr->code != code && except_ptr->code)
200 | except_ptr++;
201 |
202 | jenv->ExceptionClear();
203 | excep = jenv->FindClass(except_ptr->java_exception);
204 | if (excep)
205 | jenv->ThrowNew(excep, msg);
206 | }
207 |
208 |
209 | /* Contract support */
210 |
211 | #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
212 |
213 |
214 | #include "frame.h"
215 |
216 |
217 | #ifdef __cplusplus
218 | extern "C" {
219 | #endif
220 |
221 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_new_1Frame_1_1SWIG_10(JNIEnv *jenv, jclass jcls) {
222 | jlong jresult = 0 ;
223 | Frame *result = 0 ;
224 |
225 | (void)jenv;
226 | (void)jcls;
227 | result = (Frame *)new Frame();
228 | *(Frame **)&jresult = result;
229 | return jresult;
230 | }
231 |
232 |
233 | SWIGEXPORT jlong JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_new_1Frame_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1) {
234 | jlong jresult = 0 ;
235 | cv::Mat *arg1 = 0 ;
236 | Frame *result = 0 ;
237 |
238 | (void)jenv;
239 | (void)jcls;
240 | arg1 = *(cv::Mat **)&jarg1;
241 | if (!arg1) {
242 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "cv::Mat & reference is null");
243 | return 0;
244 | }
245 | result = (Frame *)new Frame(*arg1);
246 | *(Frame **)&jresult = result;
247 | return jresult;
248 | }
249 |
250 |
251 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_Frame_1extractFeatures(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
252 | Frame *arg1 = (Frame *) 0 ;
253 |
254 | (void)jenv;
255 | (void)jcls;
256 | (void)jarg1_;
257 | arg1 = *(Frame **)&jarg1;
258 | (arg1)->extractFeatures();
259 | }
260 |
261 |
262 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_Frame_1addFrame(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
263 | Frame *arg1 = (Frame *) 0 ;
264 | cv::Mat *arg2 = 0 ;
265 |
266 | (void)jenv;
267 | (void)jcls;
268 | (void)jarg1_;
269 | arg1 = *(Frame **)&jarg1;
270 | arg2 = *(cv::Mat **)&jarg2;
271 | if (!arg2) {
272 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "cv::Mat & reference is null");
273 | return ;
274 | }
275 | (arg1)->addFrame(*arg2);
276 | }
277 |
278 |
279 | SWIGEXPORT jboolean JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_Frame_1buildFrameProtoMessage(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jboolean jarg2) {
280 | jboolean jresult = 0 ;
281 | Frame *arg1 = (Frame *) 0 ;
282 | bool arg2 ;
283 | bool result;
284 |
285 | (void)jenv;
286 | (void)jcls;
287 | (void)jarg1_;
288 | arg1 = *(Frame **)&jarg1;
289 | arg2 = jarg2 ? true : false;
290 | result = (bool)(arg1)->buildFrameProtoMessage(arg2);
291 | jresult = (jboolean)result;
292 | return jresult;
293 | }
294 |
295 |
296 | SWIGEXPORT jbyteArray JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_Frame_1getFrame(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
297 | jbyteArray jresult = 0 ;
298 | Frame *arg1 = (Frame *) 0 ;
299 | size_t *arg2 = (size_t *) 0 ;
300 | signed char *result = 0 ;
301 |
302 | (void)jenv;
303 | (void)jcls;
304 | size_t length=0;
305 | arg2 = &length;
306 | (void)jarg1_;
307 | arg1 = *(Frame **)&jarg1;
308 | result = (signed char *)(arg1)->getFrame(arg2);
309 | {
310 | jresult = jenv->NewByteArray(length);
311 | jenv->SetByteArrayRegion(jresult, 0, length, result);
312 | }
313 | return jresult;
314 | }
315 |
316 |
317 | SWIGEXPORT void JNICALL Java_cvg_sfmPipeline_main_sfmpipelineJNI_delete_1Frame(JNIEnv *jenv, jclass jcls, jlong jarg1) {
318 | Frame *arg1 = (Frame *) 0 ;
319 |
320 | (void)jenv;
321 | (void)jcls;
322 | arg1 = *(Frame **)&jarg1;
323 | delete arg1;
324 | }
325 |
326 |
327 | #ifdef __cplusplus
328 | }
329 | #endif
330 |
331 |
--------------------------------------------------------------------------------
/jni/data.proto:
--------------------------------------------------------------------------------
1 | package sfm;
2 |
3 | option java_package = "cvg.sfmPipeline.main";
4 | option java_outer_classname = "PipelineOutMessage";
5 |
6 | message CvMatDimProto {
7 | optional int32 size = 1;
8 | optional int32 step = 2;
9 | }
10 |
11 | message cvMatProto {
12 | optional int32 n_dims = 1;
13 | repeated CvMatDimProto dims = 2;
14 | optional int32 type = 3;
15 | optional bytes bytedata = 4;
16 | enum ImageType {
17 | cvMat = 0;
18 | JPEG = 1;
19 | RAW = 2;
20 | }
21 | optional ImageType format = 5 [default = cvMat];
22 | }
23 |
24 | message Keypoints {
25 | message cvKeypoint{
26 | optional float ptX = 1;
27 | optional float ptY = 2;
28 | optional float size = 3;
29 | optional float angle = 4 [default = -1];
30 | optional float response = 5;
31 | optional int32 octave = 6;
32 | optional int32 class_id = 7;
33 | }
34 | repeated cvKeypoint keypoints = 1;
35 | }
36 |
37 | message CameraMatrixProto {
38 | repeated float data = 1;
39 | }
40 |
41 | message CameraBodyTransProto {
42 | repeated float data = 1;
43 | }
44 |
45 | message MetadataProto {
46 | optional float ang_x = 1;
47 | optional float ang_y = 2;
48 | optional float ang_z = 3;
49 | optional float pos_x = 4;
50 | optional float pos_y = 5;
51 | optional float pos_z = 6;
52 |
53 | enum SensorType {
54 | ACCEL = 0;
55 | GYRO = 1;
56 | MAGNETO = 2;
57 | LINACCEL = 3;
58 | ORIENTATION = 4;
59 | GRAVITY = 5;
60 | ROTVECT = 6;
61 | }
62 |
63 | optional fixed64 timestamp = 7;
64 | optional float val_0 = 8;
65 | optional float val_1 = 9;
66 | optional float val_2 = 10;
67 | optional SensorType type = 11 [default = GRAVITY];
68 | }
69 |
70 | message CvRectProto {
71 | optional int32 x = 1;
72 | optional int32 y = 2;
73 | optional int32 width = 3;
74 | optional int32 height = 4;
75 | }
76 |
77 | message FrameProto {
78 | repeated cvMatProto images = 1;
79 | optional CameraMatrixProto cameraMatrix = 2;
80 | optional CameraBodyTransProto cameraBodyTrans = 3;
81 | optional MetadataProto metadata = 4;
82 | optional fixed64 id = 5;
83 | optional fixed64 seq = 6;
84 | optional float baseline = 8;
85 | optional CvRectProto roi = 9;
86 | optional Keypoints keypoints = 10;
87 | optional cvMatProto descriptors = 11;
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/jni/frame.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Copyright (C) 2012
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 |
20 | #include "frame.h"
21 | #include
22 | #include
23 | #include
24 |
25 | Frame::Frame()
26 | {
27 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Constructor 1");
28 | // initialization of some fields
29 | x_subs = 3;
30 | y_subs = 3;
31 | for (size_t i = 0; i < x_subs*y_subs; i++)
32 | {
33 | curr_hess_thresholds.push_back(3);
34 | }
35 |
36 | }
37 |
38 | Frame::Frame(cv::Mat & input)
39 | {
40 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Constructor 2");
41 | input.copyTo(image);
42 | }
43 |
44 | void
45 | Frame::addFrame(cv::Mat & input)
46 | {
47 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Add image method.");
48 |
49 | if(!image.empty())
50 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Image will be overwritten");
51 |
52 | input.copyTo(image);
53 | }
54 |
55 | void
56 | Frame::extractFeatures(){
57 | double tic = (double)cv::getCPUTickCount();
58 | // cv::Mat imageIn = image;
59 | // float hess_thresholds[] = { 25, 50, 100, 200, 300, 400, 600, 800, 1000, 1500, 2000, 4000, 8000, 12000, 16000 };
60 | // size_t max_thresholds = sizeof(hess_thresholds) / sizeof(hess_thresholds[0]);
61 | //
62 | // std::vector detectors(x_subs*y_subs);
63 | //
64 | // for (size_t i = 0; i < detectors.size(); i++)
65 | // {
66 | // std::vector keypoints;
67 | // detectors[i] = cv::SurfFeatureDetector(hess_thresholds[curr_hess_thresholds[i]]);
68 | // int xstart = 0 + (i%x_subs)*imageIn.cols/x_subs - (i%x_subs)*20;
69 | // int xend = 0 + ((i%x_subs)+1)*imageIn.cols/x_subs;
70 | // int ystart = 0 + (i/y_subs)*imageIn.rows/y_subs - (i/y_subs)*20;
71 | // int yend = 0 + ((i/y_subs)+1)*imageIn.rows/y_subs;
72 | // cv::Mat detImage = imageIn(cv::Range(ystart, yend), cv::Range(xstart, xend));
73 | //
74 | // detectors[i].detect(detImage, keypoints);
75 | //
76 | // if (keypoints.size() > 100) curr_hess_thresholds[i] = (curr_hess_thresholds[i] + 1 < max_thresholds ? curr_hess_thresholds[i] + 1 : curr_hess_thresholds[i]);
77 | // if (keypoints.size() < 60) curr_hess_thresholds[i] = (curr_hess_thresholds[i] - 1 > 0 ? curr_hess_thresholds[i] - 1 : curr_hess_thresholds[i]);
78 | //
79 | // for (size_t k = 0; k < keypoints.size(); k++)
80 | // {
81 | // keypoints[k].pt.x += xstart;
82 | // keypoints[k].pt.y += ystart;
83 | // if (keypoints.at(k).pt.x > 0 && keypoints.at(k).pt.x < imageIn.cols && keypoints.at(k).pt.y > 0 && keypoints.at(k).pt.y < imageIn.cols)
84 | // {
85 | // Keypoints.push_back(keypoints.at(k));
86 | // }
87 | // }
88 | // }
89 | // cv::SurfDescriptorExtractor extractor;
90 | // extractor.compute(imageIn, Keypoints, Descriptors);
91 |
92 | cv::SURF surfObj = cv::SURF(500); // extended SURF
93 | // surfObj.detect(image, Keypoints);
94 | surfObj.operator ()(image, cv::noArray(), Keypoints, Descriptors, false);
95 |
96 | double toc = ((double)cv::getCPUTickCount() - tic)/cv::getTickFrequency();
97 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Keypoints %d, computed in %lf ms", Keypoints.size(), toc*1000);
98 | }
99 |
100 |
101 | void
102 | Frame::writeProtoMat(sfm::cvMatProto & proto, cv::Mat & mat)
103 | {
104 | proto.set_n_dims(mat.dims);
105 | size_t databytes = 0;
106 | for (int i = 0; i < mat.dims; i++)
107 | {
108 | sfm::CvMatDimProto *cur_dim = proto.add_dims();
109 | cur_dim->set_size(mat.size.p[i]);
110 | cur_dim->set_step(mat.step.p[i]);
111 | databytes += mat.size.p[i]*mat.step.p[i];
112 | }
113 | proto.set_type(mat.type());
114 | proto.set_bytedata((char *)(mat.data), databytes);
115 | }
116 |
117 |
118 | /**
119 | * Will build a regular proto message using the last image data
120 | * */
121 | bool
122 | Frame::buildFrameProtoMessage(bool doJPEG)
123 | { sfm::FrameProto frameProto;
124 | __android_log_print(ANDROID_LOG_ERROR, "Native","Building protobuf message");
125 | bool jpegGood = true;
126 | bool protoGood = true;
127 | if (Keypoints.size() > 0 && Descriptors.rows > 0)
128 | {
129 | __android_log_print(ANDROID_LOG_ERROR, "Native", "First kpt: %f", Keypoints[0].pt.x);
130 | sfm::cvMatProto * descriptorsProto = frameProto.mutable_descriptors();
131 | writeProtoMat(*descriptorsProto, Descriptors);
132 | sfm::Keypoints * keypointsProto = frameProto.mutable_keypoints();
133 | for (int i = 0; i < Keypoints.size(); i++)
134 | {
135 | sfm::Keypoints_cvKeypoint * keypointPb = keypointsProto->add_keypoints();
136 | cv::KeyPoint keypointCV = Keypoints[i];
137 | keypointPb->set_ptx(keypointCV.pt.x);
138 | keypointPb->set_pty(keypointCV.pt.y);
139 | keypointPb->set_angle(keypointCV.angle);
140 | keypointPb->set_octave(keypointCV.octave);
141 | keypointPb->set_size(keypointCV.size);
142 | keypointPb->set_response(keypointCV.response);
143 | }
144 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Keypoints length bytes: %d, descr in bytes : %d",
145 | keypointsProto->ByteSize(), descriptorsProto->ByteSize());
146 | }
147 |
148 | if(doJPEG)
149 | {
150 | double tic = (double)cv::getCPUTickCount();
151 | sfm::cvMatProto * imgJPEG = frameProto.add_images();
152 | imgJPEG->set_type(sfm::cvMatProto_ImageType_JPEG);
153 | std::vector buffer;
154 | std::vector params;
155 | params.push_back(CV_IMWRITE_JPEG_QUALITY);
156 | params.push_back(75);
157 | jpegGood = cv::imencode(".jpg", image, buffer, params );
158 | imgJPEG->set_bytedata((void *)&buffer[0], buffer.size());
159 | double toc = ((double)cv::getCPUTickCount() - tic)/cv::getTickFrequency();
160 | __android_log_print(ANDROID_LOG_ERROR, "Native", "Compression done in %lf ms",toc*1000);
161 | }
162 |
163 | int size = frameProto.ByteSize();
164 | signed char * buffer = new signed char[size];
165 | protoGood = frameProto.SerializeToArray(buffer, size);
166 | outFrame = buffer;
167 | sizeOut = (size_t)size;
168 |
169 | return jpegGood && protoGood;
170 |
171 | }
172 |
173 | Frame::~Frame()
174 | {
175 |
176 | }
177 |
178 |
--------------------------------------------------------------------------------
/jni/frame.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Copyright (C) 2012
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 |
20 | #ifndef FRAME_H
21 | #define FRAME_H
22 |
23 | #include
24 |
25 |
26 | #include
27 | #include
28 |
29 | #include "data.pb.h"
30 |
31 | class Frame
32 | {
33 | private:
34 | size_t x_subs;
35 | size_t y_subs;
36 | std::vector curr_hess_thresholds;
37 | cv::Mat image;
38 | std::vector Keypoints;
39 | signed char * outFrame;
40 | size_t sizeOut;
41 | void writeProtoMat(sfm::cvMatProto &, cv::Mat &);
42 |
43 | public:
44 | Frame();
45 | Frame(cv::Mat &);
46 | void extractFeatures();
47 | void addFrame(cv::Mat &);
48 | bool buildFrameProtoMessage(bool doJPEG);
49 | signed char * getFrame(size_t * len){*len = sizeOut;return outFrame;}
50 | cv::Mat Descriptors;
51 | virtual ~Frame();
52 |
53 | };
54 |
55 | #endif // FRAME_H
56 |
--------------------------------------------------------------------------------
/jni/libopencv_nonfree.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/jni/libopencv_nonfree.a
--------------------------------------------------------------------------------
/jni/libprotobuf.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/jni/libprotobuf.so
--------------------------------------------------------------------------------
/jni/matches.pb.cpp:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 |
3 | #define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
4 | #include "matches.pb.h"
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | // @@protoc_insertion_point(includes)
15 |
16 | namespace sfm {
17 |
18 | namespace {
19 |
20 | const ::google::protobuf::Descriptor* DMatches_descriptor_ = NULL;
21 | const ::google::protobuf::internal::GeneratedMessageReflection*
22 | DMatches_reflection_ = NULL;
23 | const ::google::protobuf::Descriptor* MatchesProto_descriptor_ = NULL;
24 | const ::google::protobuf::internal::GeneratedMessageReflection*
25 | MatchesProto_reflection_ = NULL;
26 |
27 | } // namespace
28 |
29 |
30 | void protobuf_AssignDesc_matches_2eproto() {
31 | protobuf_AddDesc_matches_2eproto();
32 | const ::google::protobuf::FileDescriptor* file =
33 | ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
34 | "matches.proto");
35 | GOOGLE_CHECK(file != NULL);
36 | DMatches_descriptor_ = file->message_type(0);
37 | static const int DMatches_offsets_[4] = {
38 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DMatches, queryidx_),
39 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DMatches, trainidx_),
40 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DMatches, imgidx_),
41 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DMatches, distance_),
42 | };
43 | DMatches_reflection_ =
44 | new ::google::protobuf::internal::GeneratedMessageReflection(
45 | DMatches_descriptor_,
46 | DMatches::default_instance_,
47 | DMatches_offsets_,
48 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DMatches, _has_bits_[0]),
49 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DMatches, _unknown_fields_),
50 | -1,
51 | ::google::protobuf::DescriptorPool::generated_pool(),
52 | ::google::protobuf::MessageFactory::generated_factory(),
53 | sizeof(DMatches));
54 | MatchesProto_descriptor_ = file->message_type(1);
55 | static const int MatchesProto_offsets_[3] = {
56 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MatchesProto, imagelseq_),
57 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MatchesProto, imagerseq_),
58 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MatchesProto, matches_),
59 | };
60 | MatchesProto_reflection_ =
61 | new ::google::protobuf::internal::GeneratedMessageReflection(
62 | MatchesProto_descriptor_,
63 | MatchesProto::default_instance_,
64 | MatchesProto_offsets_,
65 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MatchesProto, _has_bits_[0]),
66 | GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MatchesProto, _unknown_fields_),
67 | -1,
68 | ::google::protobuf::DescriptorPool::generated_pool(),
69 | ::google::protobuf::MessageFactory::generated_factory(),
70 | sizeof(MatchesProto));
71 | }
72 |
73 | namespace {
74 |
75 | GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
76 | inline void protobuf_AssignDescriptorsOnce() {
77 | ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
78 | &protobuf_AssignDesc_matches_2eproto);
79 | }
80 |
81 | void protobuf_RegisterTypes(const ::std::string&) {
82 | protobuf_AssignDescriptorsOnce();
83 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
84 | DMatches_descriptor_, &DMatches::default_instance());
85 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
86 | MatchesProto_descriptor_, &MatchesProto::default_instance());
87 | }
88 |
89 | } // namespace
90 |
91 | void protobuf_ShutdownFile_matches_2eproto() {
92 | delete DMatches::default_instance_;
93 | delete DMatches_reflection_;
94 | delete MatchesProto::default_instance_;
95 | delete MatchesProto_reflection_;
96 | }
97 |
98 | void protobuf_AddDesc_matches_2eproto() {
99 | static bool already_here = false;
100 | if (already_here) return;
101 | already_here = true;
102 | GOOGLE_PROTOBUF_VERIFY_VERSION;
103 |
104 | ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
105 | "\n\rmatches.proto\022\003sfm\"P\n\010DMatches\022\020\n\010quer"
106 | "yIdx\030\001 \001(\r\022\020\n\010trainIdx\030\002 \001(\r\022\016\n\006imgIdx\030\003"
107 | " \001(\r\022\020\n\010distance\030\004 \001(\002\"T\n\014MatchesProto\022\021"
108 | "\n\timageLseq\030\001 \001(\006\022\021\n\timageRseq\030\002 \001(\006\022\036\n\007"
109 | "matches\030\003 \003(\0132\r.sfm.DMatchesB)\n\024cvg.sfmP"
110 | "ipeline.mainB\021MatchesOutMessage", 231);
111 | ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
112 | "matches.proto", &protobuf_RegisterTypes);
113 | DMatches::default_instance_ = new DMatches();
114 | MatchesProto::default_instance_ = new MatchesProto();
115 | DMatches::default_instance_->InitAsDefaultInstance();
116 | MatchesProto::default_instance_->InitAsDefaultInstance();
117 | ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_matches_2eproto);
118 | }
119 |
120 | // Force AddDescriptors() to be called at static initialization time.
121 | struct StaticDescriptorInitializer_matches_2eproto {
122 | StaticDescriptorInitializer_matches_2eproto() {
123 | protobuf_AddDesc_matches_2eproto();
124 | }
125 | } static_descriptor_initializer_matches_2eproto_;
126 |
127 |
128 | // ===================================================================
129 |
130 | #ifndef _MSC_VER
131 | const int DMatches::kQueryIdxFieldNumber;
132 | const int DMatches::kTrainIdxFieldNumber;
133 | const int DMatches::kImgIdxFieldNumber;
134 | const int DMatches::kDistanceFieldNumber;
135 | #endif // !_MSC_VER
136 |
137 | DMatches::DMatches()
138 | : ::google::protobuf::Message() {
139 | SharedCtor();
140 | }
141 |
142 | void DMatches::InitAsDefaultInstance() {
143 | }
144 |
145 | DMatches::DMatches(const DMatches& from)
146 | : ::google::protobuf::Message() {
147 | SharedCtor();
148 | MergeFrom(from);
149 | }
150 |
151 | void DMatches::SharedCtor() {
152 | _cached_size_ = 0;
153 | queryidx_ = 0u;
154 | trainidx_ = 0u;
155 | imgidx_ = 0u;
156 | distance_ = 0;
157 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
158 | }
159 |
160 | DMatches::~DMatches() {
161 | SharedDtor();
162 | }
163 |
164 | void DMatches::SharedDtor() {
165 | if (this != default_instance_) {
166 | }
167 | }
168 |
169 | void DMatches::SetCachedSize(int size) const {
170 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
171 | _cached_size_ = size;
172 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
173 | }
174 | const ::google::protobuf::Descriptor* DMatches::descriptor() {
175 | protobuf_AssignDescriptorsOnce();
176 | return DMatches_descriptor_;
177 | }
178 |
179 | const DMatches& DMatches::default_instance() {
180 | if (default_instance_ == NULL) protobuf_AddDesc_matches_2eproto(); return *default_instance_;
181 | }
182 |
183 | DMatches* DMatches::default_instance_ = NULL;
184 |
185 | DMatches* DMatches::New() const {
186 | return new DMatches;
187 | }
188 |
189 | void DMatches::Clear() {
190 | if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
191 | queryidx_ = 0u;
192 | trainidx_ = 0u;
193 | imgidx_ = 0u;
194 | distance_ = 0;
195 | }
196 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
197 | mutable_unknown_fields()->Clear();
198 | }
199 |
200 | bool DMatches::MergePartialFromCodedStream(
201 | ::google::protobuf::io::CodedInputStream* input) {
202 | #define DO_(EXPRESSION) if (!(EXPRESSION)) return false
203 | ::google::protobuf::uint32 tag;
204 | while ((tag = input->ReadTag()) != 0) {
205 | switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
206 | // optional uint32 queryIdx = 1;
207 | case 1: {
208 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
209 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
210 | DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
211 | ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
212 | input, &queryidx_)));
213 | set_has_queryidx();
214 | } else {
215 | goto handle_uninterpreted;
216 | }
217 | if (input->ExpectTag(16)) goto parse_trainIdx;
218 | break;
219 | }
220 |
221 | // optional uint32 trainIdx = 2;
222 | case 2: {
223 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
224 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
225 | parse_trainIdx:
226 | DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
227 | ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
228 | input, &trainidx_)));
229 | set_has_trainidx();
230 | } else {
231 | goto handle_uninterpreted;
232 | }
233 | if (input->ExpectTag(24)) goto parse_imgIdx;
234 | break;
235 | }
236 |
237 | // optional uint32 imgIdx = 3;
238 | case 3: {
239 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
240 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) {
241 | parse_imgIdx:
242 | DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
243 | ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
244 | input, &imgidx_)));
245 | set_has_imgidx();
246 | } else {
247 | goto handle_uninterpreted;
248 | }
249 | if (input->ExpectTag(37)) goto parse_distance;
250 | break;
251 | }
252 |
253 | // optional float distance = 4;
254 | case 4: {
255 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
256 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_FIXED32) {
257 | parse_distance:
258 | DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
259 | float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>(
260 | input, &distance_)));
261 | set_has_distance();
262 | } else {
263 | goto handle_uninterpreted;
264 | }
265 | if (input->ExpectAtEnd()) return true;
266 | break;
267 | }
268 |
269 | default: {
270 | handle_uninterpreted:
271 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
272 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
273 | return true;
274 | }
275 | DO_(::google::protobuf::internal::WireFormat::SkipField(
276 | input, tag, mutable_unknown_fields()));
277 | break;
278 | }
279 | }
280 | }
281 | return true;
282 | #undef DO_
283 | }
284 |
285 | void DMatches::SerializeWithCachedSizes(
286 | ::google::protobuf::io::CodedOutputStream* output) const {
287 | // optional uint32 queryIdx = 1;
288 | if (has_queryidx()) {
289 | ::google::protobuf::internal::WireFormatLite::WriteUInt32(1, this->queryidx(), output);
290 | }
291 |
292 | // optional uint32 trainIdx = 2;
293 | if (has_trainidx()) {
294 | ::google::protobuf::internal::WireFormatLite::WriteUInt32(2, this->trainidx(), output);
295 | }
296 |
297 | // optional uint32 imgIdx = 3;
298 | if (has_imgidx()) {
299 | ::google::protobuf::internal::WireFormatLite::WriteUInt32(3, this->imgidx(), output);
300 | }
301 |
302 | // optional float distance = 4;
303 | if (has_distance()) {
304 | ::google::protobuf::internal::WireFormatLite::WriteFloat(4, this->distance(), output);
305 | }
306 |
307 | if (!unknown_fields().empty()) {
308 | ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
309 | unknown_fields(), output);
310 | }
311 | }
312 |
313 | ::google::protobuf::uint8* DMatches::SerializeWithCachedSizesToArray(
314 | ::google::protobuf::uint8* target) const {
315 | // optional uint32 queryIdx = 1;
316 | if (has_queryidx()) {
317 | target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(1, this->queryidx(), target);
318 | }
319 |
320 | // optional uint32 trainIdx = 2;
321 | if (has_trainidx()) {
322 | target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(2, this->trainidx(), target);
323 | }
324 |
325 | // optional uint32 imgIdx = 3;
326 | if (has_imgidx()) {
327 | target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(3, this->imgidx(), target);
328 | }
329 |
330 | // optional float distance = 4;
331 | if (has_distance()) {
332 | target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(4, this->distance(), target);
333 | }
334 |
335 | if (!unknown_fields().empty()) {
336 | target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
337 | unknown_fields(), target);
338 | }
339 | return target;
340 | }
341 |
342 | int DMatches::ByteSize() const {
343 | int total_size = 0;
344 |
345 | if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
346 | // optional uint32 queryIdx = 1;
347 | if (has_queryidx()) {
348 | total_size += 1 +
349 | ::google::protobuf::internal::WireFormatLite::UInt32Size(
350 | this->queryidx());
351 | }
352 |
353 | // optional uint32 trainIdx = 2;
354 | if (has_trainidx()) {
355 | total_size += 1 +
356 | ::google::protobuf::internal::WireFormatLite::UInt32Size(
357 | this->trainidx());
358 | }
359 |
360 | // optional uint32 imgIdx = 3;
361 | if (has_imgidx()) {
362 | total_size += 1 +
363 | ::google::protobuf::internal::WireFormatLite::UInt32Size(
364 | this->imgidx());
365 | }
366 |
367 | // optional float distance = 4;
368 | if (has_distance()) {
369 | total_size += 1 + 4;
370 | }
371 |
372 | }
373 | if (!unknown_fields().empty()) {
374 | total_size +=
375 | ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
376 | unknown_fields());
377 | }
378 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
379 | _cached_size_ = total_size;
380 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
381 | return total_size;
382 | }
383 |
384 | void DMatches::MergeFrom(const ::google::protobuf::Message& from) {
385 | GOOGLE_CHECK_NE(&from, this);
386 | const DMatches* source =
387 | ::google::protobuf::internal::dynamic_cast_if_available(
388 | &from);
389 | if (source == NULL) {
390 | ::google::protobuf::internal::ReflectionOps::Merge(from, this);
391 | } else {
392 | MergeFrom(*source);
393 | }
394 | }
395 |
396 | void DMatches::MergeFrom(const DMatches& from) {
397 | GOOGLE_CHECK_NE(&from, this);
398 | if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
399 | if (from.has_queryidx()) {
400 | set_queryidx(from.queryidx());
401 | }
402 | if (from.has_trainidx()) {
403 | set_trainidx(from.trainidx());
404 | }
405 | if (from.has_imgidx()) {
406 | set_imgidx(from.imgidx());
407 | }
408 | if (from.has_distance()) {
409 | set_distance(from.distance());
410 | }
411 | }
412 | mutable_unknown_fields()->MergeFrom(from.unknown_fields());
413 | }
414 |
415 | void DMatches::CopyFrom(const ::google::protobuf::Message& from) {
416 | if (&from == this) return;
417 | Clear();
418 | MergeFrom(from);
419 | }
420 |
421 | void DMatches::CopyFrom(const DMatches& from) {
422 | if (&from == this) return;
423 | Clear();
424 | MergeFrom(from);
425 | }
426 |
427 | bool DMatches::IsInitialized() const {
428 |
429 | return true;
430 | }
431 |
432 | void DMatches::Swap(DMatches* other) {
433 | if (other != this) {
434 | std::swap(queryidx_, other->queryidx_);
435 | std::swap(trainidx_, other->trainidx_);
436 | std::swap(imgidx_, other->imgidx_);
437 | std::swap(distance_, other->distance_);
438 | std::swap(_has_bits_[0], other->_has_bits_[0]);
439 | _unknown_fields_.Swap(&other->_unknown_fields_);
440 | std::swap(_cached_size_, other->_cached_size_);
441 | }
442 | }
443 |
444 | ::google::protobuf::Metadata DMatches::GetMetadata() const {
445 | protobuf_AssignDescriptorsOnce();
446 | ::google::protobuf::Metadata metadata;
447 | metadata.descriptor = DMatches_descriptor_;
448 | metadata.reflection = DMatches_reflection_;
449 | return metadata;
450 | }
451 |
452 |
453 | // ===================================================================
454 |
455 | #ifndef _MSC_VER
456 | const int MatchesProto::kImageLseqFieldNumber;
457 | const int MatchesProto::kImageRseqFieldNumber;
458 | const int MatchesProto::kMatchesFieldNumber;
459 | #endif // !_MSC_VER
460 |
461 | MatchesProto::MatchesProto()
462 | : ::google::protobuf::Message() {
463 | SharedCtor();
464 | }
465 |
466 | void MatchesProto::InitAsDefaultInstance() {
467 | }
468 |
469 | MatchesProto::MatchesProto(const MatchesProto& from)
470 | : ::google::protobuf::Message() {
471 | SharedCtor();
472 | MergeFrom(from);
473 | }
474 |
475 | void MatchesProto::SharedCtor() {
476 | _cached_size_ = 0;
477 | imagelseq_ = GOOGLE_ULONGLONG(0);
478 | imagerseq_ = GOOGLE_ULONGLONG(0);
479 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
480 | }
481 |
482 | MatchesProto::~MatchesProto() {
483 | SharedDtor();
484 | }
485 |
486 | void MatchesProto::SharedDtor() {
487 | if (this != default_instance_) {
488 | }
489 | }
490 |
491 | void MatchesProto::SetCachedSize(int size) const {
492 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
493 | _cached_size_ = size;
494 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
495 | }
496 | const ::google::protobuf::Descriptor* MatchesProto::descriptor() {
497 | protobuf_AssignDescriptorsOnce();
498 | return MatchesProto_descriptor_;
499 | }
500 |
501 | const MatchesProto& MatchesProto::default_instance() {
502 | if (default_instance_ == NULL) protobuf_AddDesc_matches_2eproto(); return *default_instance_;
503 | }
504 |
505 | MatchesProto* MatchesProto::default_instance_ = NULL;
506 |
507 | MatchesProto* MatchesProto::New() const {
508 | return new MatchesProto;
509 | }
510 |
511 | void MatchesProto::Clear() {
512 | if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
513 | imagelseq_ = GOOGLE_ULONGLONG(0);
514 | imagerseq_ = GOOGLE_ULONGLONG(0);
515 | }
516 | matches_.Clear();
517 | ::memset(_has_bits_, 0, sizeof(_has_bits_));
518 | mutable_unknown_fields()->Clear();
519 | }
520 |
521 | bool MatchesProto::MergePartialFromCodedStream(
522 | ::google::protobuf::io::CodedInputStream* input) {
523 | #define DO_(EXPRESSION) if (!(EXPRESSION)) return false
524 | ::google::protobuf::uint32 tag;
525 | while ((tag = input->ReadTag()) != 0) {
526 | switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
527 | // optional fixed64 imageLseq = 1;
528 | case 1: {
529 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
530 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_FIXED64) {
531 | DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
532 | ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_FIXED64>(
533 | input, &imagelseq_)));
534 | set_has_imagelseq();
535 | } else {
536 | goto handle_uninterpreted;
537 | }
538 | if (input->ExpectTag(17)) goto parse_imageRseq;
539 | break;
540 | }
541 |
542 | // optional fixed64 imageRseq = 2;
543 | case 2: {
544 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
545 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_FIXED64) {
546 | parse_imageRseq:
547 | DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
548 | ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_FIXED64>(
549 | input, &imagerseq_)));
550 | set_has_imagerseq();
551 | } else {
552 | goto handle_uninterpreted;
553 | }
554 | if (input->ExpectTag(26)) goto parse_matches;
555 | break;
556 | }
557 |
558 | // repeated .sfm.DMatches matches = 3;
559 | case 3: {
560 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
561 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
562 | parse_matches:
563 | DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
564 | input, add_matches()));
565 | } else {
566 | goto handle_uninterpreted;
567 | }
568 | if (input->ExpectTag(26)) goto parse_matches;
569 | if (input->ExpectAtEnd()) return true;
570 | break;
571 | }
572 |
573 | default: {
574 | handle_uninterpreted:
575 | if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
576 | ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
577 | return true;
578 | }
579 | DO_(::google::protobuf::internal::WireFormat::SkipField(
580 | input, tag, mutable_unknown_fields()));
581 | break;
582 | }
583 | }
584 | }
585 | return true;
586 | #undef DO_
587 | }
588 |
589 | void MatchesProto::SerializeWithCachedSizes(
590 | ::google::protobuf::io::CodedOutputStream* output) const {
591 | // optional fixed64 imageLseq = 1;
592 | if (has_imagelseq()) {
593 | ::google::protobuf::internal::WireFormatLite::WriteFixed64(1, this->imagelseq(), output);
594 | }
595 |
596 | // optional fixed64 imageRseq = 2;
597 | if (has_imagerseq()) {
598 | ::google::protobuf::internal::WireFormatLite::WriteFixed64(2, this->imagerseq(), output);
599 | }
600 |
601 | // repeated .sfm.DMatches matches = 3;
602 | for (int i = 0; i < this->matches_size(); i++) {
603 | ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
604 | 3, this->matches(i), output);
605 | }
606 |
607 | if (!unknown_fields().empty()) {
608 | ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
609 | unknown_fields(), output);
610 | }
611 | }
612 |
613 | ::google::protobuf::uint8* MatchesProto::SerializeWithCachedSizesToArray(
614 | ::google::protobuf::uint8* target) const {
615 | // optional fixed64 imageLseq = 1;
616 | if (has_imagelseq()) {
617 | target = ::google::protobuf::internal::WireFormatLite::WriteFixed64ToArray(1, this->imagelseq(), target);
618 | }
619 |
620 | // optional fixed64 imageRseq = 2;
621 | if (has_imagerseq()) {
622 | target = ::google::protobuf::internal::WireFormatLite::WriteFixed64ToArray(2, this->imagerseq(), target);
623 | }
624 |
625 | // repeated .sfm.DMatches matches = 3;
626 | for (int i = 0; i < this->matches_size(); i++) {
627 | target = ::google::protobuf::internal::WireFormatLite::
628 | WriteMessageNoVirtualToArray(
629 | 3, this->matches(i), target);
630 | }
631 |
632 | if (!unknown_fields().empty()) {
633 | target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
634 | unknown_fields(), target);
635 | }
636 | return target;
637 | }
638 |
639 | int MatchesProto::ByteSize() const {
640 | int total_size = 0;
641 |
642 | if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
643 | // optional fixed64 imageLseq = 1;
644 | if (has_imagelseq()) {
645 | total_size += 1 + 8;
646 | }
647 |
648 | // optional fixed64 imageRseq = 2;
649 | if (has_imagerseq()) {
650 | total_size += 1 + 8;
651 | }
652 |
653 | }
654 | // repeated .sfm.DMatches matches = 3;
655 | total_size += 1 * this->matches_size();
656 | for (int i = 0; i < this->matches_size(); i++) {
657 | total_size +=
658 | ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
659 | this->matches(i));
660 | }
661 |
662 | if (!unknown_fields().empty()) {
663 | total_size +=
664 | ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
665 | unknown_fields());
666 | }
667 | GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
668 | _cached_size_ = total_size;
669 | GOOGLE_SAFE_CONCURRENT_WRITES_END();
670 | return total_size;
671 | }
672 |
673 | void MatchesProto::MergeFrom(const ::google::protobuf::Message& from) {
674 | GOOGLE_CHECK_NE(&from, this);
675 | const MatchesProto* source =
676 | ::google::protobuf::internal::dynamic_cast_if_available(
677 | &from);
678 | if (source == NULL) {
679 | ::google::protobuf::internal::ReflectionOps::Merge(from, this);
680 | } else {
681 | MergeFrom(*source);
682 | }
683 | }
684 |
685 | void MatchesProto::MergeFrom(const MatchesProto& from) {
686 | GOOGLE_CHECK_NE(&from, this);
687 | matches_.MergeFrom(from.matches_);
688 | if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
689 | if (from.has_imagelseq()) {
690 | set_imagelseq(from.imagelseq());
691 | }
692 | if (from.has_imagerseq()) {
693 | set_imagerseq(from.imagerseq());
694 | }
695 | }
696 | mutable_unknown_fields()->MergeFrom(from.unknown_fields());
697 | }
698 |
699 | void MatchesProto::CopyFrom(const ::google::protobuf::Message& from) {
700 | if (&from == this) return;
701 | Clear();
702 | MergeFrom(from);
703 | }
704 |
705 | void MatchesProto::CopyFrom(const MatchesProto& from) {
706 | if (&from == this) return;
707 | Clear();
708 | MergeFrom(from);
709 | }
710 |
711 | bool MatchesProto::IsInitialized() const {
712 |
713 | return true;
714 | }
715 |
716 | void MatchesProto::Swap(MatchesProto* other) {
717 | if (other != this) {
718 | std::swap(imagelseq_, other->imagelseq_);
719 | std::swap(imagerseq_, other->imagerseq_);
720 | matches_.Swap(&other->matches_);
721 | std::swap(_has_bits_[0], other->_has_bits_[0]);
722 | _unknown_fields_.Swap(&other->_unknown_fields_);
723 | std::swap(_cached_size_, other->_cached_size_);
724 | }
725 | }
726 |
727 | ::google::protobuf::Metadata MatchesProto::GetMetadata() const {
728 | protobuf_AssignDescriptorsOnce();
729 | ::google::protobuf::Metadata metadata;
730 | metadata.descriptor = MatchesProto_descriptor_;
731 | metadata.reflection = MatchesProto_reflection_;
732 | return metadata;
733 | }
734 |
735 |
736 | // @@protoc_insertion_point(namespace_scope)
737 |
738 | } // namespace sfm
739 |
740 | // @@protoc_insertion_point(global_scope)
741 |
--------------------------------------------------------------------------------
/jni/matches.pb.h:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: matches.proto
3 |
4 | #ifndef PROTOBUF_matches_2eproto__INCLUDED
5 | #define PROTOBUF_matches_2eproto__INCLUDED
6 |
7 | #include
8 |
9 | #include
10 |
11 | #if GOOGLE_PROTOBUF_VERSION < 2004000
12 | #error This file was generated by a newer version of protoc which is
13 | #error incompatible with your Protocol Buffer headers. Please update
14 | #error your headers.
15 | #endif
16 | #if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
17 | #error This file was generated by an older version of protoc which is
18 | #error incompatible with your Protocol Buffer headers. Please
19 | #error regenerate this file with a newer version of protoc.
20 | #endif
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | // @@protoc_insertion_point(includes)
27 |
28 | namespace sfm {
29 |
30 | // Internal implementation detail -- do not call these.
31 | void protobuf_AddDesc_matches_2eproto();
32 | void protobuf_AssignDesc_matches_2eproto();
33 | void protobuf_ShutdownFile_matches_2eproto();
34 |
35 | class DMatches;
36 | class MatchesProto;
37 |
38 | // ===================================================================
39 |
40 | class DMatches : public ::google::protobuf::Message {
41 | public:
42 | DMatches();
43 | virtual ~DMatches();
44 |
45 | DMatches(const DMatches& from);
46 |
47 | inline DMatches& operator=(const DMatches& from) {
48 | CopyFrom(from);
49 | return *this;
50 | }
51 |
52 | inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
53 | return _unknown_fields_;
54 | }
55 |
56 | inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
57 | return &_unknown_fields_;
58 | }
59 |
60 | static const ::google::protobuf::Descriptor* descriptor();
61 | static const DMatches& default_instance();
62 |
63 | void Swap(DMatches* other);
64 |
65 | // implements Message ----------------------------------------------
66 |
67 | DMatches* New() const;
68 | void CopyFrom(const ::google::protobuf::Message& from);
69 | void MergeFrom(const ::google::protobuf::Message& from);
70 | void CopyFrom(const DMatches& from);
71 | void MergeFrom(const DMatches& from);
72 | void Clear();
73 | bool IsInitialized() const;
74 |
75 | int ByteSize() const;
76 | bool MergePartialFromCodedStream(
77 | ::google::protobuf::io::CodedInputStream* input);
78 | void SerializeWithCachedSizes(
79 | ::google::protobuf::io::CodedOutputStream* output) const;
80 | ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
81 | int GetCachedSize() const { return _cached_size_; }
82 | private:
83 | void SharedCtor();
84 | void SharedDtor();
85 | void SetCachedSize(int size) const;
86 | public:
87 |
88 | ::google::protobuf::Metadata GetMetadata() const;
89 |
90 | // nested types ----------------------------------------------------
91 |
92 | // accessors -------------------------------------------------------
93 |
94 | // optional uint32 queryIdx = 1;
95 | inline bool has_queryidx() const;
96 | inline void clear_queryidx();
97 | static const int kQueryIdxFieldNumber = 1;
98 | inline ::google::protobuf::uint32 queryidx() const;
99 | inline void set_queryidx(::google::protobuf::uint32 value);
100 |
101 | // optional uint32 trainIdx = 2;
102 | inline bool has_trainidx() const;
103 | inline void clear_trainidx();
104 | static const int kTrainIdxFieldNumber = 2;
105 | inline ::google::protobuf::uint32 trainidx() const;
106 | inline void set_trainidx(::google::protobuf::uint32 value);
107 |
108 | // optional uint32 imgIdx = 3;
109 | inline bool has_imgidx() const;
110 | inline void clear_imgidx();
111 | static const int kImgIdxFieldNumber = 3;
112 | inline ::google::protobuf::uint32 imgidx() const;
113 | inline void set_imgidx(::google::protobuf::uint32 value);
114 |
115 | // optional float distance = 4;
116 | inline bool has_distance() const;
117 | inline void clear_distance();
118 | static const int kDistanceFieldNumber = 4;
119 | inline float distance() const;
120 | inline void set_distance(float value);
121 |
122 | // @@protoc_insertion_point(class_scope:sfm.DMatches)
123 | private:
124 | inline void set_has_queryidx();
125 | inline void clear_has_queryidx();
126 | inline void set_has_trainidx();
127 | inline void clear_has_trainidx();
128 | inline void set_has_imgidx();
129 | inline void clear_has_imgidx();
130 | inline void set_has_distance();
131 | inline void clear_has_distance();
132 |
133 | ::google::protobuf::UnknownFieldSet _unknown_fields_;
134 |
135 | ::google::protobuf::uint32 queryidx_;
136 | ::google::protobuf::uint32 trainidx_;
137 | ::google::protobuf::uint32 imgidx_;
138 | float distance_;
139 |
140 | mutable int _cached_size_;
141 | ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32];
142 |
143 | friend void protobuf_AddDesc_matches_2eproto();
144 | friend void protobuf_AssignDesc_matches_2eproto();
145 | friend void protobuf_ShutdownFile_matches_2eproto();
146 |
147 | void InitAsDefaultInstance();
148 | static DMatches* default_instance_;
149 | };
150 | // -------------------------------------------------------------------
151 |
152 | class MatchesProto : public ::google::protobuf::Message {
153 | public:
154 | MatchesProto();
155 | virtual ~MatchesProto();
156 |
157 | MatchesProto(const MatchesProto& from);
158 |
159 | inline MatchesProto& operator=(const MatchesProto& from) {
160 | CopyFrom(from);
161 | return *this;
162 | }
163 |
164 | inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
165 | return _unknown_fields_;
166 | }
167 |
168 | inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
169 | return &_unknown_fields_;
170 | }
171 |
172 | static const ::google::protobuf::Descriptor* descriptor();
173 | static const MatchesProto& default_instance();
174 |
175 | void Swap(MatchesProto* other);
176 |
177 | // implements Message ----------------------------------------------
178 |
179 | MatchesProto* New() const;
180 | void CopyFrom(const ::google::protobuf::Message& from);
181 | void MergeFrom(const ::google::protobuf::Message& from);
182 | void CopyFrom(const MatchesProto& from);
183 | void MergeFrom(const MatchesProto& from);
184 | void Clear();
185 | bool IsInitialized() const;
186 |
187 | int ByteSize() const;
188 | bool MergePartialFromCodedStream(
189 | ::google::protobuf::io::CodedInputStream* input);
190 | void SerializeWithCachedSizes(
191 | ::google::protobuf::io::CodedOutputStream* output) const;
192 | ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
193 | int GetCachedSize() const { return _cached_size_; }
194 | private:
195 | void SharedCtor();
196 | void SharedDtor();
197 | void SetCachedSize(int size) const;
198 | public:
199 |
200 | ::google::protobuf::Metadata GetMetadata() const;
201 |
202 | // nested types ----------------------------------------------------
203 |
204 | // accessors -------------------------------------------------------
205 |
206 | // optional fixed64 imageLseq = 1;
207 | inline bool has_imagelseq() const;
208 | inline void clear_imagelseq();
209 | static const int kImageLseqFieldNumber = 1;
210 | inline ::google::protobuf::uint64 imagelseq() const;
211 | inline void set_imagelseq(::google::protobuf::uint64 value);
212 |
213 | // optional fixed64 imageRseq = 2;
214 | inline bool has_imagerseq() const;
215 | inline void clear_imagerseq();
216 | static const int kImageRseqFieldNumber = 2;
217 | inline ::google::protobuf::uint64 imagerseq() const;
218 | inline void set_imagerseq(::google::protobuf::uint64 value);
219 |
220 | // repeated .sfm.DMatches matches = 3;
221 | inline int matches_size() const;
222 | inline void clear_matches();
223 | static const int kMatchesFieldNumber = 3;
224 | inline const ::sfm::DMatches& matches(int index) const;
225 | inline ::sfm::DMatches* mutable_matches(int index);
226 | inline ::sfm::DMatches* add_matches();
227 | inline const ::google::protobuf::RepeatedPtrField< ::sfm::DMatches >&
228 | matches() const;
229 | inline ::google::protobuf::RepeatedPtrField< ::sfm::DMatches >*
230 | mutable_matches();
231 |
232 | // @@protoc_insertion_point(class_scope:sfm.MatchesProto)
233 | private:
234 | inline void set_has_imagelseq();
235 | inline void clear_has_imagelseq();
236 | inline void set_has_imagerseq();
237 | inline void clear_has_imagerseq();
238 |
239 | ::google::protobuf::UnknownFieldSet _unknown_fields_;
240 |
241 | ::google::protobuf::uint64 imagelseq_;
242 | ::google::protobuf::uint64 imagerseq_;
243 | ::google::protobuf::RepeatedPtrField< ::sfm::DMatches > matches_;
244 |
245 | mutable int _cached_size_;
246 | ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32];
247 |
248 | friend void protobuf_AddDesc_matches_2eproto();
249 | friend void protobuf_AssignDesc_matches_2eproto();
250 | friend void protobuf_ShutdownFile_matches_2eproto();
251 |
252 | void InitAsDefaultInstance();
253 | static MatchesProto* default_instance_;
254 | };
255 | // ===================================================================
256 |
257 |
258 | // ===================================================================
259 |
260 | // DMatches
261 |
262 | // optional uint32 queryIdx = 1;
263 | inline bool DMatches::has_queryidx() const {
264 | return (_has_bits_[0] & 0x00000001u) != 0;
265 | }
266 | inline void DMatches::set_has_queryidx() {
267 | _has_bits_[0] |= 0x00000001u;
268 | }
269 | inline void DMatches::clear_has_queryidx() {
270 | _has_bits_[0] &= ~0x00000001u;
271 | }
272 | inline void DMatches::clear_queryidx() {
273 | queryidx_ = 0u;
274 | clear_has_queryidx();
275 | }
276 | inline ::google::protobuf::uint32 DMatches::queryidx() const {
277 | return queryidx_;
278 | }
279 | inline void DMatches::set_queryidx(::google::protobuf::uint32 value) {
280 | set_has_queryidx();
281 | queryidx_ = value;
282 | }
283 |
284 | // optional uint32 trainIdx = 2;
285 | inline bool DMatches::has_trainidx() const {
286 | return (_has_bits_[0] & 0x00000002u) != 0;
287 | }
288 | inline void DMatches::set_has_trainidx() {
289 | _has_bits_[0] |= 0x00000002u;
290 | }
291 | inline void DMatches::clear_has_trainidx() {
292 | _has_bits_[0] &= ~0x00000002u;
293 | }
294 | inline void DMatches::clear_trainidx() {
295 | trainidx_ = 0u;
296 | clear_has_trainidx();
297 | }
298 | inline ::google::protobuf::uint32 DMatches::trainidx() const {
299 | return trainidx_;
300 | }
301 | inline void DMatches::set_trainidx(::google::protobuf::uint32 value) {
302 | set_has_trainidx();
303 | trainidx_ = value;
304 | }
305 |
306 | // optional uint32 imgIdx = 3;
307 | inline bool DMatches::has_imgidx() const {
308 | return (_has_bits_[0] & 0x00000004u) != 0;
309 | }
310 | inline void DMatches::set_has_imgidx() {
311 | _has_bits_[0] |= 0x00000004u;
312 | }
313 | inline void DMatches::clear_has_imgidx() {
314 | _has_bits_[0] &= ~0x00000004u;
315 | }
316 | inline void DMatches::clear_imgidx() {
317 | imgidx_ = 0u;
318 | clear_has_imgidx();
319 | }
320 | inline ::google::protobuf::uint32 DMatches::imgidx() const {
321 | return imgidx_;
322 | }
323 | inline void DMatches::set_imgidx(::google::protobuf::uint32 value) {
324 | set_has_imgidx();
325 | imgidx_ = value;
326 | }
327 |
328 | // optional float distance = 4;
329 | inline bool DMatches::has_distance() const {
330 | return (_has_bits_[0] & 0x00000008u) != 0;
331 | }
332 | inline void DMatches::set_has_distance() {
333 | _has_bits_[0] |= 0x00000008u;
334 | }
335 | inline void DMatches::clear_has_distance() {
336 | _has_bits_[0] &= ~0x00000008u;
337 | }
338 | inline void DMatches::clear_distance() {
339 | distance_ = 0;
340 | clear_has_distance();
341 | }
342 | inline float DMatches::distance() const {
343 | return distance_;
344 | }
345 | inline void DMatches::set_distance(float value) {
346 | set_has_distance();
347 | distance_ = value;
348 | }
349 |
350 | // -------------------------------------------------------------------
351 |
352 | // MatchesProto
353 |
354 | // optional fixed64 imageLseq = 1;
355 | inline bool MatchesProto::has_imagelseq() const {
356 | return (_has_bits_[0] & 0x00000001u) != 0;
357 | }
358 | inline void MatchesProto::set_has_imagelseq() {
359 | _has_bits_[0] |= 0x00000001u;
360 | }
361 | inline void MatchesProto::clear_has_imagelseq() {
362 | _has_bits_[0] &= ~0x00000001u;
363 | }
364 | inline void MatchesProto::clear_imagelseq() {
365 | imagelseq_ = GOOGLE_ULONGLONG(0);
366 | clear_has_imagelseq();
367 | }
368 | inline ::google::protobuf::uint64 MatchesProto::imagelseq() const {
369 | return imagelseq_;
370 | }
371 | inline void MatchesProto::set_imagelseq(::google::protobuf::uint64 value) {
372 | set_has_imagelseq();
373 | imagelseq_ = value;
374 | }
375 |
376 | // optional fixed64 imageRseq = 2;
377 | inline bool MatchesProto::has_imagerseq() const {
378 | return (_has_bits_[0] & 0x00000002u) != 0;
379 | }
380 | inline void MatchesProto::set_has_imagerseq() {
381 | _has_bits_[0] |= 0x00000002u;
382 | }
383 | inline void MatchesProto::clear_has_imagerseq() {
384 | _has_bits_[0] &= ~0x00000002u;
385 | }
386 | inline void MatchesProto::clear_imagerseq() {
387 | imagerseq_ = GOOGLE_ULONGLONG(0);
388 | clear_has_imagerseq();
389 | }
390 | inline ::google::protobuf::uint64 MatchesProto::imagerseq() const {
391 | return imagerseq_;
392 | }
393 | inline void MatchesProto::set_imagerseq(::google::protobuf::uint64 value) {
394 | set_has_imagerseq();
395 | imagerseq_ = value;
396 | }
397 |
398 | // repeated .sfm.DMatches matches = 3;
399 | inline int MatchesProto::matches_size() const {
400 | return matches_.size();
401 | }
402 | inline void MatchesProto::clear_matches() {
403 | matches_.Clear();
404 | }
405 | inline const ::sfm::DMatches& MatchesProto::matches(int index) const {
406 | return matches_.Get(index);
407 | }
408 | inline ::sfm::DMatches* MatchesProto::mutable_matches(int index) {
409 | return matches_.Mutable(index);
410 | }
411 | inline ::sfm::DMatches* MatchesProto::add_matches() {
412 | return matches_.Add();
413 | }
414 | inline const ::google::protobuf::RepeatedPtrField< ::sfm::DMatches >&
415 | MatchesProto::matches() const {
416 | return matches_;
417 | }
418 | inline ::google::protobuf::RepeatedPtrField< ::sfm::DMatches >*
419 | MatchesProto::mutable_matches() {
420 | return &matches_;
421 | }
422 |
423 |
424 | // @@protoc_insertion_point(namespace_scope)
425 |
426 | } // namespace sfm
427 |
428 | #ifndef SWIG
429 | namespace google {
430 | namespace protobuf {
431 |
432 |
433 | } // namespace google
434 | } // namespace protobuf
435 | #endif // SWIG
436 |
437 | // @@protoc_insertion_point(global_scope)
438 |
439 | #endif // PROTOBUF_matches_2eproto__INCLUDED
440 |
--------------------------------------------------------------------------------
/jni/matches.proto:
--------------------------------------------------------------------------------
1 | package sfm;
2 |
3 | option java_package = "cvg.sfmPipeline.main";
4 | option java_outer_classname = "MatchesOutMessage";
5 |
6 | message DMatches {
7 | optional uint32 queryIdx = 1;
8 | optional uint32 trainIdx = 2;
9 | optional uint32 imgIdx = 3;
10 | optional float distance =4;
11 | }
12 |
13 | message MatchesProto {
14 | optional fixed64 imageLseq = 1;
15 | optional fixed64 imageRseq = 2;
16 | repeated DMatches matches = 3;
17 | }
18 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libpipeline_native.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/libs/armeabi-v7a/libpipeline_native.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libprotobuf.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/libs/armeabi-v7a/libprotobuf.so
--------------------------------------------------------------------------------
/libs/protobuf-java-2.4.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/libs/protobuf-java-2.4.1.jar
--------------------------------------------------------------------------------
/logo_google_developers.svg:
--------------------------------------------------------------------------------
1 |
2 |
268 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-15
15 | android.library.reference.1=../../apps/opencvAndroid-2.4.2/sdk/java
16 |
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/danylaksono/Android-SfM-client/a53e818f2d70215f66b39c2f78b53d27b377546b/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
12 |
13 |
21 |
22 |
23 |
24 |
28 |
29 |
33 |
34 |
41 |
42 |
45 |
46 |
51 |
52 |
53 |
60 |
61 |
67 |
68 |
75 |
76 |
83 |
84 |
85 |
86 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/res/layout/viewmats.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
14 |
15 |
18 |
19 |
20 |
23 |
24 |
29 |
30 |
37 |
38 |
39 |
44 |
45 |
49 |
50 |
57 |
58 |
64 |
65 |
72 |
73 |
79 |
80 |
87 |
88 |
89 |
90 |
95 |
96 |
100 |
101 |
108 |
109 |
115 |
116 |
123 |
124 |
130 |
131 |
138 |
139 |
140 |
141 |
146 |
147 |
151 |
152 |
159 |
160 |
166 |
167 |
174 |
175 |
181 |
182 |
189 |
190 |
191 |
192 |
193 |
196 |
197 |
200 |
201 |
206 |
207 |
214 |
215 |
216 |
221 |
222 |
226 |
227 |
234 |
235 |
241 |
242 |
249 |
250 |
256 |
257 |
264 |
265 |
266 |
267 |
272 |
273 |
277 |
278 |
285 |
286 |
292 |
293 |
300 |
301 |
307 |
308 |
315 |
316 |
317 |
318 |
323 |
324 |
328 |
329 |
336 |
337 |
343 |
344 |
351 |
352 |
358 |
359 |
366 |
367 |
368 |
369 |
370 |
373 |
374 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
41 |
--------------------------------------------------------------------------------
/res/values-large/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 8dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 8dp
4 | 8dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | SfMpipeline
4 | Settings
5 | Android SfM
6 |
7 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/FpsMeter.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import java.text.DecimalFormat;
4 |
5 | import org.opencv.core.Core;
6 |
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.util.Log;
11 |
12 | public class FpsMeter {
13 | private static final String TAG = "mainSFM::FpsMeter";
14 | int step;
15 | int framesCouner;
16 | double freq;
17 | long prevFrameTime;
18 | String strfps;
19 | DecimalFormat twoPlaces = new DecimalFormat("0.00");
20 | Paint paint;
21 |
22 | public void init() {
23 | step = 20;
24 | framesCouner = 0;
25 | freq = Core.getTickFrequency();
26 | prevFrameTime = Core.getTickCount();
27 | strfps = "";
28 |
29 | paint = new Paint();
30 | paint.setColor(Color.BLUE);
31 | paint.setTextSize(30);
32 | }
33 |
34 | public void measure() {
35 | framesCouner++;
36 | if (framesCouner % step == 0) {
37 | long time = Core.getTickCount();
38 | double fps = step * freq / (time - prevFrameTime);
39 | prevFrameTime = time;
40 | DecimalFormat twoPlaces = new DecimalFormat("0.00");
41 | strfps = twoPlaces.format(fps) + " FPS";
42 | }
43 | }
44 |
45 | public void draw(Canvas canvas, float offsetx, float offsety) {
46 | canvas.drawText(strfps, 20 + offsetx, 30 + offsety, paint);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/Frame.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class Frame {
12 | private long swigCPtr;
13 | protected boolean swigCMemOwn;
14 |
15 | public Frame(long cPtr, boolean cMemoryOwn) {
16 | swigCMemOwn = cMemoryOwn;
17 | swigCPtr = cPtr;
18 | }
19 |
20 | public static long getCPtr(Frame obj) {
21 | return (obj == null) ? 0 : obj.swigCPtr;
22 | }
23 |
24 | protected void finalize() {
25 | delete();
26 | }
27 |
28 | public synchronized void delete() {
29 | if (swigCPtr != 0) {
30 | if (swigCMemOwn) {
31 | swigCMemOwn = false;
32 | sfmmatcherJNI.delete_Frame(swigCPtr);
33 | }
34 | swigCPtr = 0;
35 | }
36 | }
37 |
38 | public Frame() {
39 | this(sfmmatcherJNI.new_Frame__SWIG_0(), true);
40 | }
41 |
42 | public Frame(SWIGTYPE_p_cv__Mat arg0) {
43 | this(sfmmatcherJNI.new_Frame__SWIG_1(SWIGTYPE_p_cv__Mat.getCPtr(arg0)), true);
44 | }
45 |
46 | public void extractFeatures() {
47 | sfmmatcherJNI.Frame_extractFeatures(swigCPtr, this);
48 | }
49 |
50 | public void addFrame(SWIGTYPE_p_cv__Mat arg0) {
51 | sfmmatcherJNI.Frame_addFrame(swigCPtr, this, SWIGTYPE_p_cv__Mat.getCPtr(arg0));
52 | }
53 |
54 | public boolean buildFrameProtoMessage(boolean doJPEG) {
55 | return sfmmatcherJNI.Frame_buildFrameProtoMessage(swigCPtr, this, doJPEG);
56 | }
57 |
58 | public byte[] getFrame() {
59 | return sfmmatcherJNI.Frame_getFrame(swigCPtr, this);
60 | }
61 |
62 | public void setDescriptors(SWIGTYPE_p_cv__Mat value) {
63 | sfmmatcherJNI.Frame_Descriptors_set(swigCPtr, this, SWIGTYPE_p_cv__Mat.getCPtr(value));
64 | }
65 |
66 | public SWIGTYPE_p_cv__Mat getDescriptors() {
67 | return new SWIGTYPE_p_cv__Mat(sfmmatcherJNI.Frame_Descriptors_get(swigCPtr, this), true);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/FrameProcess.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import org.opencv.android.Utils;
4 | import org.opencv.core.Mat;
5 | import org.opencv.highgui.Highgui;
6 | import org.opencv.highgui.VideoCapture;
7 |
8 | import android.content.Context;
9 | import android.graphics.Bitmap;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.SurfaceHolder;
13 |
14 | public class FrameProcess extends VideoGrabber {
15 | private final String TAG = "FrameProcess";
16 | private Mat mGray;
17 |
18 | public FrameProcess(Context context, AttributeSet attrs) {
19 | super(context, attrs);
20 | }
21 |
22 | @Override
23 | public void surfaceCreated(SurfaceHolder holder) {
24 | synchronized (this) {
25 | mGray = new Mat();
26 | }
27 | super.surfaceCreated(holder);
28 | }
29 |
30 | @Override
31 | protected Bitmap processFrame(VideoCapture capture) {
32 | capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
33 |
34 | Bitmap bmp = Bitmap.createBitmap(mGray.cols(), mGray.rows(), Bitmap.Config.ARGB_8888);
35 |
36 | // store the pointer to the latest image
37 | PipelineSharedData.setLastImage(mGray.getNativeObjAddr());
38 |
39 | try {
40 | Utils.matToBitmap(mGray, bmp);
41 | } catch(Exception e) {
42 | Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage());
43 | bmp.recycle();
44 | bmp = null;
45 | }
46 | return bmp;
47 | }
48 |
49 | @Override
50 | public void run() {
51 | super.run();
52 |
53 | synchronized (this) {
54 | if (mGray != null)
55 | mGray.release();
56 | mGray = null;
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/Matcher.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class Matcher {
12 | private long swigCPtr;
13 | protected boolean swigCMemOwn;
14 |
15 | public Matcher(long cPtr, boolean cMemoryOwn) {
16 | swigCMemOwn = cMemoryOwn;
17 | swigCPtr = cPtr;
18 | }
19 |
20 | public static long getCPtr(Matcher obj) {
21 | return (obj == null) ? 0 : obj.swigCPtr;
22 | }
23 |
24 | protected void finalize() {
25 | delete();
26 | }
27 |
28 | public synchronized void delete() {
29 | if (swigCPtr != 0) {
30 | if (swigCMemOwn) {
31 | swigCMemOwn = false;
32 | sfmmatcherJNI.delete_Matcher(swigCPtr);
33 | }
34 | swigCPtr = 0;
35 | }
36 | }
37 |
38 | public Matcher() {
39 | this(sfmmatcherJNI.new_Matcher(), true);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/MatcherFLANN.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class MatcherFLANN extends Matcher {
12 | private long swigCPtr;
13 |
14 | public MatcherFLANN(long cPtr, boolean cMemoryOwn) {
15 | super(sfmmatcherJNI.MatcherFLANN_SWIGUpcast(cPtr), cMemoryOwn);
16 | swigCPtr = cPtr;
17 | }
18 |
19 | public static long getCPtr(MatcherFLANN obj) {
20 | return (obj == null) ? 0 : obj.swigCPtr;
21 | }
22 |
23 | protected void finalize() {
24 | delete();
25 | }
26 |
27 | public synchronized void delete() {
28 | if (swigCPtr != 0) {
29 | if (swigCMemOwn) {
30 | swigCMemOwn = false;
31 | sfmmatcherJNI.delete_MatcherFLANN(swigCPtr);
32 | }
33 | swigCPtr = 0;
34 | }
35 | super.delete();
36 | }
37 |
38 | public MatcherFLANN(Frame arg0, Frame arg1) {
39 | this(sfmmatcherJNI.new_MatcherFLANN(Frame.getCPtr(arg0), arg0, Frame.getCPtr(arg1), arg1), true);
40 | }
41 |
42 | public boolean matchFrames(int arg0, int arg1) {
43 | return sfmmatcherJNI.MatcherFLANN_matchFrames(swigCPtr, this, arg0, arg1);
44 | }
45 |
46 | public boolean buildMatchProtoMessage() {
47 | return sfmmatcherJNI.MatcherFLANN_buildMatchProtoMessage(swigCPtr, this);
48 | }
49 |
50 | public byte[] getMatches() {
51 | return sfmmatcherJNI.MatcherFLANN_getMatches(swigCPtr, this);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/PipelineActivity.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.IOException;
7 | import java.io.ObjectInputStream;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import org.opencv.android.BaseLoaderCallback;
12 | import org.opencv.android.LoaderCallbackInterface;
13 | import org.opencv.android.OpenCVLoader;
14 |
15 | import android.net.wifi.WifiManager;
16 | import android.os.AsyncTask;
17 | import android.os.Bundle;
18 | import android.os.Environment;
19 | import android.app.Activity;
20 | import android.app.AlertDialog;
21 | import android.content.DialogInterface;
22 | import android.content.Intent;
23 | import android.content.pm.PackageManager;
24 | import android.util.Log;
25 | import android.view.Menu;
26 | import android.view.MenuItem;
27 | import android.view.View;
28 | import android.widget.Button;
29 | import android.widget.ScrollView;
30 | import android.widget.TextView;
31 | import android.widget.Toast;
32 | import android.widget.ToggleButton;
33 |
34 |
35 | public class PipelineActivity extends Activity {
36 |
37 | private String TAG = "PipelineActivity";
38 | private boolean isCalibrated = false;
39 | private FrameProcess mView;
40 | private PipelineCom sfmComm;
41 | public static TextView console;
42 | private String serverIP = "192.168.0.30";
43 | private int UDPport = 60000;
44 | public static Button grabFrame;
45 | private ToggleButton start;
46 | private ScrollView scroller;
47 | private MenuItem frameOptions;
48 |
49 | private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
50 | @Override
51 | public void onManagerConnected(int status) {
52 | switch (status) {
53 | case LoaderCallbackInterface.SUCCESS:
54 | {
55 |
56 | setContentView(R.layout.main);
57 |
58 | Log.i(TAG, "Native Libraries loaded successfully");
59 |
60 | mView = (FrameProcess) findViewById(R.id.camPreview);
61 | console = (TextView) findViewById(R.id.console);
62 | grabFrame = (Button) findViewById(R.id.grabFrame);
63 | grabFrame.setEnabled(false);
64 | start = (ToggleButton) findViewById(R.id.startSFM);
65 |
66 | start.setOnClickListener(clickStart);
67 | grabFrame.setOnClickListener(grabClick);
68 | scroller = (ScrollView) PipelineActivity.this.findViewById(R.id.scrollView1);
69 | if( !mView.openCamera() ) {
70 | AlertDialog ad = new AlertDialog.Builder(mAppContext).create();
71 | ad.setCancelable(false);
72 | ad.setMessage("Fatal error: can't open camera!");
73 | ad.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
74 | public void onClick(DialogInterface dialog, int which) {
75 | dialog.dismiss();
76 | finish();
77 | }
78 | });
79 | ad.show();
80 | }
81 | } break;
82 | default:
83 | {
84 | super.onManagerConnected(status);
85 | } break;
86 | }
87 | }
88 | };
89 |
90 | private View.OnClickListener grabClick = new View.OnClickListener() {
91 |
92 | @Override
93 | public void onClick(View v) {
94 | frameOptions.setEnabled(false); // once started, options cannot be changed
95 | grabFrame.setEnabled(false);
96 | new PipelineProcess().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
97 | scroller.post(new Runnable() {
98 | @Override
99 | public void run() {
100 | scroller.smoothScrollBy(0, console.getBottom());
101 | }
102 | });
103 | }
104 | };
105 |
106 | private View.OnClickListener clickStart = new View.OnClickListener() {
107 | @Override
108 | public void onClick(View v) {
109 | if(start.isChecked()){
110 | if(isCalibrated){
111 | // start the communication processes
112 | console.append("starting wireless communications");
113 | sfmComm = new PipelineCom(PipelineActivity.this.getApplicationContext(), serverIP, UDPport);
114 | startService(new Intent(PipelineActivity.this, SensorService.class));
115 | console.append("\nsensor service started: gravity sensor");
116 | grabFrame.setEnabled(true);
117 | }
118 | else{
119 | Toast.makeText(getApplicationContext(),
120 | "Calibration data not found. Perform application first!",
121 | Toast.LENGTH_SHORT).show();
122 | start.setChecked(false);
123 | }
124 | }else{
125 | // stop communication processes (if any)
126 | console.append("\nstopped wireless communications");
127 | sfmComm.closeTCP();
128 | stopService(new Intent(PipelineActivity.this, SensorService.class));
129 | console.append("\nsensor service stopped");
130 | grabFrame.setEnabled(false);
131 | }
132 | scroller.post(new Runnable() {
133 | @Override
134 | public void run() {
135 | scroller.smoothScrollBy(0, console.getBottom());
136 | }
137 | });
138 |
139 | }
140 | };
141 |
142 | @Override
143 | public void onCreate(Bundle savedInstanceState) {
144 | super.onCreate(savedInstanceState);
145 | Log.i(TAG, "Trying to load OpenCV library");
146 | PipelineSharedData.setLocalIpAddress((WifiManager)getSystemService(WIFI_SERVICE));
147 | PipelineSharedData.noFrames = 0l;
148 |
149 | if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
150 | Log.e(TAG, "Cannot connect to OpenCV Manager");
151 |
152 | }
153 |
154 |
155 | @Override
156 | protected void onResume() {
157 | if(PipelineSharedData.calibDone){
158 | isCalibrated = loadCalib();
159 | PipelineSharedData.calibDone = false;
160 | }
161 | super.onResume();
162 | if( mView != null && !mView.openCamera() ) {
163 | AlertDialog ad = new AlertDialog.Builder(this).create();
164 | ad.setCancelable(false); // This blocks the 'BACK' button
165 | ad.setMessage("Fatal error: can't open camera!");
166 | ad.setButton(AlertDialog.BUTTON_POSITIVE,"OK", new DialogInterface.OnClickListener() {
167 | public void onClick(DialogInterface dialog, int which) {
168 | dialog.dismiss();
169 | finish();
170 | }
171 | });
172 | ad.show();
173 | }
174 | }
175 |
176 | @Override
177 | protected void onDestroy() {
178 | String mess = "EXIT";
179 | new UDPsend().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mess.getBytes());
180 | stopService(new Intent(PipelineActivity.this, SensorService.class));
181 | super.onDestroy();
182 | }
183 |
184 | @Override
185 | public boolean onCreateOptionsMenu(Menu menu) {
186 | getMenuInflater().inflate(R.menu.main, menu);
187 | frameOptions = menu.findItem(R.id.frameProcesOpts);
188 | return true;
189 | }
190 |
191 | @Override
192 | public boolean onOptionsItemSelected(MenuItem item) {
193 | switch (item.getItemId()){
194 | case R.id.loadCalib:
195 | isCalibrated = loadCalib();
196 | break;
197 | case R.id.doCalib:{
198 | Intent intent = new Intent(Intent.ACTION_MAIN);
199 | PackageManager manager = PipelineActivity.this.getPackageManager();
200 | intent = manager.getLaunchIntentForPackage("cvg.sfmPipeline.calibration");
201 | if(intent == null)
202 | showToast("Please install Calibration app first!", false);
203 | else{
204 | intent.addCategory("android.intent.category.LAUNCHER");
205 | startActivity(intent);
206 | PipelineSharedData.calibDone = true;
207 | }
208 | break;
209 | }
210 | case R.id.viewRecon:
211 | showToast("Not yet implemented!", true);
212 | break;
213 |
214 | case R.id.sendJPEG:
215 | if (item.isChecked())
216 | item.setChecked(false);
217 | else
218 | item.setChecked(true);
219 | PipelineSharedData.sendJPEG = item.isChecked();
220 | break;
221 | case R.id.doMatching:
222 | if (item.isChecked())
223 | item.setChecked(false);
224 | else
225 | item.setChecked(true);
226 | PipelineSharedData.doMatching = item.isChecked();
227 | break;
228 | case R.id.doSURF:
229 | if (item.isChecked())
230 | item.setChecked(false);
231 | else
232 | item.setChecked(true);
233 | PipelineSharedData.doSURF = item.isChecked();
234 | break;
235 |
236 | case R.id.camInfo:
237 | if(isCalibrated)
238 | showParams();
239 | else
240 | showToast("Calibration data not found. Perform application first!", true);
241 | break;
242 | case R.id.sfmOpts:
243 | break;
244 | }
245 | return true;
246 | }
247 |
248 | private void showParams() {
249 | View newlay = getLayoutInflater().inflate(R.layout.viewmats, null);
250 | List params = new ArrayList();
251 | List params2 = new ArrayList();
252 | params.add((TextView) newlay.findViewById(R.id.matrix_1_1));
253 | params.add((TextView) newlay.findViewById(R.id.matrix_1_2));
254 | params.add((TextView) newlay.findViewById(R.id.matrix_1_3));
255 | params.add((TextView) newlay.findViewById(R.id.matrix_2_1));
256 | params.add((TextView) newlay.findViewById(R.id.matrix_2_2));
257 | params.add((TextView) newlay.findViewById(R.id.matrix_2_3));
258 | params.add((TextView) newlay.findViewById(R.id.matrix_3_1));
259 | params.add((TextView) newlay.findViewById(R.id.matrix_3_2));
260 | params.add((TextView) newlay.findViewById(R.id.matrix_3_3));
261 |
262 | params2.add((TextView) newlay.findViewById(R.id.imatrix_1_1));
263 | params2.add((TextView) newlay.findViewById(R.id.imatrix_1_2));
264 | params2.add((TextView) newlay.findViewById(R.id.imatrix_1_3));
265 | params2.add((TextView) newlay.findViewById(R.id.imatrix_2_1));
266 | params2.add((TextView) newlay.findViewById(R.id.imatrix_2_2));
267 | params2.add((TextView) newlay.findViewById(R.id.imatrix_2_3));
268 | params2.add((TextView) newlay.findViewById(R.id.imatrix_3_1));
269 | params2.add((TextView) newlay.findViewById(R.id.imatrix_3_2));
270 | params2.add((TextView) newlay.findViewById(R.id.imatrix_3_3));
271 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
272 | builder.setView(newlay);
273 | builder.create().show();
274 | int i = 0;
275 | for (TextView textView : params) {
276 | textView.setText(numberDisplayFormatter(PipelineSharedData.getCamera2body()[i]));
277 | i++;
278 | }
279 | int j = 0;
280 | for (TextView textView : params2) {
281 | textView.setText(numberDisplayFormatter(PipelineSharedData.getCameraMatrix()[j]));
282 | j++;
283 | }
284 |
285 | }
286 |
287 | private static String numberDisplayFormatter(float value) {
288 | String displayedText = String.format("%.3f", value);
289 | if (value >= 0) {
290 | displayedText = " " + displayedText;
291 | }
292 | if (displayedText.length() > 6) {
293 | displayedText = displayedText.substring(0, 6);
294 | }
295 | while (displayedText.length() < 6) {
296 | displayedText = displayedText + " ";
297 | }
298 | return displayedText;
299 | }
300 |
301 | private boolean loadCalib(){
302 | String path = Environment.getExternalStorageDirectory().getPath()
303 | + "/CalibrationData/";
304 | File fileK = new File(path + "camMatrix.dat");
305 | File fileC2B = new File(path + "rotCam2imu.dat");
306 | float[] K = {0,0,0,0,0,0,0,0,0};
307 | float[] C2B = {0,0,0,0,0,0,0,0,0};
308 | if (fileK.exists() && fileC2B.exists()){
309 | try {
310 | FileInputStream fisK = new FileInputStream(fileK);
311 | FileInputStream fisC2B = new FileInputStream(fileC2B);
312 |
313 | ObjectInputStream oiiK = new ObjectInputStream(fisK);
314 | ObjectInputStream oiiC2B = new ObjectInputStream(fisC2B);
315 | for(int i = 0; i < 9; i ++)
316 | K[i] = (float)oiiK.readDouble();
317 | for(int i = 0; i < 9; i ++)
318 | C2B[i] = (float)oiiC2B.readDouble();
319 | fisK.close();
320 | fisC2B.close();
321 | } catch (FileNotFoundException e) {
322 | e.printStackTrace();
323 | } catch (IOException e) {
324 | e.printStackTrace();
325 | }
326 |
327 | PipelineSharedData.setCameraMatrix(K);
328 | PipelineSharedData.setCamera2body(C2B);
329 | showToast("Calibration data successfully loaded!", true);
330 | return true;
331 | }
332 | else{
333 | showToast("Calibration data not found. Perform application first!", false);
334 | return false;
335 | }
336 | }
337 |
338 | private void showToast(String message, boolean isShort){
339 | int len = Toast.LENGTH_LONG;
340 | if (isShort)
341 | len = Toast.LENGTH_SHORT;
342 |
343 | Toast.makeText(getApplicationContext(), message, len).show();
344 | }
345 |
346 | @Override
347 | public void onBackPressed() {
348 | if (!start.isChecked())
349 | super.onBackPressed();
350 | }
351 |
352 |
353 | }
354 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/PipelineCom.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import android.content.Context;
4 | import android.os.AsyncTask;
5 |
6 | /**
7 | * @author Federico Camposeco
8 | * Class to seamlessly initialize the communication process for
9 | * the application. UDP will be transmitted containing sensor
10 | * data, SURF/SIFT features from the latest frame, and optiona-
11 | * lly the image itself.
12 | */
13 | public class PipelineCom {
14 |
15 | private TCPread tcpRead;
16 |
17 | public PipelineCom(Context ui, String serverIP, int comPort){
18 | tcpRead = new TCPread(ui, serverIP, comPort);
19 |
20 | // start the TCP thread
21 | tcpRead.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
22 | }
23 | public void closeTCP(){
24 | tcpRead.cancel(true);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/PipelineProcess.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import com.google.protobuf.InvalidProtocolBufferException;
4 |
5 | import cvg.sfmPipeline.main.PipelineOutMessage.FrameProto;
6 | import cvg.sfmPipeline.main.MatchesOutMessage.MatchesProto;
7 |
8 | import android.os.AsyncTask;
9 | import android.util.Log;
10 |
11 | public class PipelineProcess extends AsyncTask{
12 |
13 | private UDPsend sendFrame;
14 | private UDPsend sendMatches;
15 | private FrameProto.Builder protoFrame;
16 | private boolean sendMatchesF = false;
17 |
18 | public PipelineProcess() {
19 | sendFrame = new UDPsend();
20 | sendMatches = new UDPsend();
21 | }
22 |
23 | @Override
24 | protected Void doInBackground(Void... params) {
25 |
26 | if(protoFrame != null)
27 | protoFrame.clear();
28 |
29 | protoFrame = FrameProto.newBuilder();
30 |
31 | PipelineSharedData.secondFrame = new Frame(); // native object
32 | // PipelineSharedData.addFrame(frame);
33 |
34 | if(PipelineSharedData.doSURF){
35 | PipelineSharedData.secondFrame.addFrame(new SWIGTYPE_p_cv__Mat( PipelineSharedData.getLastImage(), true));
36 | PipelineSharedData.secondFrame.extractFeatures();
37 | if (PipelineSharedData.doMatching && PipelineSharedData.noFrames > 0){
38 | MatcherFLANN matcher = new MatcherFLANN(PipelineSharedData.firstFrame, PipelineSharedData.secondFrame);
39 | matcher.matchFrames((int)PipelineSharedData.noFrames-1, (int)PipelineSharedData.noFrames);
40 | if(matcher.buildMatchProtoMessage()){
41 | // message is already built, ready to be sent
42 | PipelineSharedData.matchesProtoMessage = matcher.getMatches();
43 | sendMatchesF = true;
44 | Log.e("raw", "Matches length: " + PipelineSharedData.matchesProtoMessage.length);
45 | }
46 |
47 | }
48 | }
49 |
50 | if (PipelineSharedData.secondFrame.buildFrameProtoMessage(PipelineSharedData.sendJPEG)){
51 | byte[] data = PipelineSharedData.secondFrame.getFrame();
52 | Log.e("raw", "Received length: " + data.length);
53 | try {
54 | protoFrame.mergeFrom(data);
55 | } catch (InvalidProtocolBufferException e) {
56 | e.printStackTrace();
57 | }
58 | }
59 |
60 | ProtoWriter.buildMessage(protoFrame);
61 | PipelineSharedData.noFrames++;
62 |
63 | PipelineSharedData.firstFrame = PipelineSharedData.secondFrame;
64 |
65 | return null;
66 | }
67 |
68 | @Override
69 | protected void onPostExecute(Void result) {
70 | sendFrame.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ProtoWriter.getData());
71 | if(sendMatchesF){
72 | sendMatches.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, PipelineSharedData.matchesProtoMessage);
73 | Log.e("raw", "Matches length sent to UDP: " + PipelineSharedData.matchesProtoMessage.length);
74 | }
75 | super.onPostExecute(result);
76 | }
77 |
78 |
79 | static{
80 | System.loadLibrary("protobuf");
81 | System.loadLibrary("pipeline_native");
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/PipelineSharedData.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 |
4 | import android.net.wifi.WifiManager;
5 | import android.text.format.Formatter;
6 | import android.util.Log;
7 | import cvg.sfmPipeline.main.PipelineOutMessage.Keypoints;
8 | import cvg.sfmPipeline.main.PipelineOutMessage.cvMatProto;
9 | import cvg.sfmPipeline.main.PipelineOutMessage.MetadataProto.SensorType;
10 | /**
11 | * Shared data for the pipeline bundled into a static class.
12 | * Contains various fields relevant to the reconstruction.
13 | * */
14 | public final class PipelineSharedData {
15 |
16 | //-- Data Fields ---------------------------------------------------------------
17 | static private float[] lastSensor = {0,0,0};
18 | static private float[] lastGroundTr = {0,0,0,0,0,0};
19 | static private byte[] image;
20 | static private long lastImage;
21 | static private float[] cameraMatrix = {0,0,0,0,0,0,0,0,0};
22 | static private float[] camera2body = {0,0,0,0,0,0,0,0,0};
23 | static private SensorType sensorType = SensorType.GRAVITY;
24 | static public long noFrames = 0l;
25 | static private long timestamp;
26 | static private int camera = 0;
27 | static private String ipAddress = "0";
28 | static public volatile boolean ready2send = true;
29 | static public boolean ready2snap = true;
30 | static public boolean calibDone = false;
31 | static public boolean doSURF = true;
32 | static public boolean doMatching = false;
33 | static public boolean sendJPEG = false;
34 | static public Frame firstFrame;
35 | static public Frame secondFrame;
36 | static public byte[] matchesProtoMessage;
37 |
38 | public static void addFrame(Frame newFrame){
39 | if (noFrames > 1){
40 | firstFrame = secondFrame;
41 | secondFrame = newFrame;
42 | return;
43 | }
44 | if (noFrames == 1){
45 | secondFrame = newFrame;
46 | return;
47 | }
48 |
49 | if (noFrames == 0){
50 | firstFrame = newFrame;
51 | return;
52 | }
53 | }
54 |
55 | public static void setDefaults() {
56 | camera = 0;
57 | ipAddress = "0";
58 | ready2send = true;
59 | ready2snap = true;
60 | noFrames = 0l;
61 | }
62 |
63 | private PipelineSharedData(){}
64 |
65 | public static int getCam(){
66 | return camera;
67 | }
68 |
69 | public static void setCam(int c){
70 | camera = c;
71 | }
72 |
73 | public static String getLocalIpAddress() {
74 | return ipAddress;
75 | }
76 |
77 | @SuppressWarnings("deprecation")
78 | public static void setLocalIpAddress(WifiManager wim){
79 | ipAddress = Formatter.formatIpAddress(wim.getConnectionInfo().getIpAddress());
80 | }
81 |
82 |
83 | public static long getLastImage() {
84 | return lastImage;
85 | }
86 |
87 | public static void setLastImage(long lastImage) {
88 | PipelineSharedData.lastImage = lastImage;
89 | }
90 |
91 | public static float[] getLastGroundTr() {
92 | return lastGroundTr;
93 | }
94 |
95 | public static void setLastGroundTr(float[] lastGroundTr) {
96 | PipelineSharedData.lastGroundTr = lastGroundTr;
97 | }
98 |
99 | public static float[] getCameraMatrix() {
100 | return cameraMatrix;
101 | }
102 |
103 | public static void setCameraMatrix(float[] cameraMatrix) {
104 | PipelineSharedData.cameraMatrix = cameraMatrix;
105 | }
106 |
107 | public static float[] getCamera2body() {
108 | return camera2body;
109 | }
110 |
111 | public static void setCamera2body(float[] camera2body) {
112 | PipelineSharedData.camera2body = camera2body;
113 | }
114 |
115 | public static SensorType getSensorType() {
116 | return sensorType;
117 | }
118 |
119 | public static void setSensorType(SensorType sensorType) {
120 | PipelineSharedData.sensorType = sensorType;
121 | }
122 |
123 | public static float[] getLastSensor() {
124 | return lastSensor;
125 | }
126 |
127 | public static void setLastSensor(float[] lastSensor) {
128 | PipelineSharedData.lastSensor = lastSensor;
129 | }
130 |
131 |
132 | public static byte[] getImage() {
133 | return image;
134 | }
135 |
136 | public static void setImage(byte[] image) {
137 | PipelineSharedData.image = image;
138 | }
139 |
140 | public static long getTimestamp() {
141 | return timestamp;
142 | }
143 |
144 | public static void setTimestamp(long timestamp) {
145 | PipelineSharedData.timestamp = timestamp;
146 | }
147 |
148 |
149 |
150 |
151 |
152 | }
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/ProtoWriter.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import cvg.sfmPipeline.main.PipelineOutMessage.CameraBodyTransProto;
4 | import cvg.sfmPipeline.main.PipelineOutMessage.CameraMatrixProto;
5 | import cvg.sfmPipeline.main.PipelineOutMessage.FrameProto;
6 | import cvg.sfmPipeline.main.PipelineOutMessage.MetadataProto;
7 |
8 | public class ProtoWriter {
9 | static private final String TAG = "ProtoLog::Writer";
10 |
11 | private ProtoWriter(){
12 | }
13 |
14 | static private byte[] data;
15 |
16 |
17 |
18 | public static byte[] getData() {
19 | return data;
20 | }
21 |
22 |
23 |
24 | public static void setData(byte[] data) {
25 | ProtoWriter.data = data;
26 | }
27 |
28 |
29 |
30 | static public void buildMessage(FrameProto.Builder frame){
31 | //-- Add image metadata
32 | MetadataProto.Builder meta = MetadataProto.newBuilder();
33 |
34 | /**
35 | * If ground truth vicon data wants to be actually collected,
36 | * then please used the included UDPthread class to do so. For
37 | * now, because of comatibility with the python server, the
38 | * vicon data is still packed, but its only zeros.
39 | * */
40 |
41 | meta.setAngX( PipelineSharedData.getLastGroundTr()[0]);
42 | meta.setAngY( PipelineSharedData.getLastGroundTr()[1]);
43 | meta.setAngZ( PipelineSharedData.getLastGroundTr()[2]);
44 | meta.setPosX( PipelineSharedData.getLastGroundTr()[3]);
45 | meta.setPosY( PipelineSharedData.getLastGroundTr()[4]);
46 | meta.setPosZ( PipelineSharedData.getLastGroundTr()[5]);
47 |
48 | meta.setVal0( PipelineSharedData.getLastSensor()[0]);
49 | meta.setVal1( PipelineSharedData.getLastSensor()[1]);
50 | meta.setVal2( PipelineSharedData.getLastSensor()[2]);
51 | meta.setType( PipelineSharedData.getSensorType());
52 |
53 | meta.setTimestamp(PipelineSharedData.getTimestamp());
54 |
55 | //-- Add calibration data
56 | CameraMatrixProto.Builder K = CameraMatrixProto.newBuilder();
57 |
58 | float[] Kf = PipelineSharedData.getCameraMatrix();
59 | for (int i = 0; i < Kf.length; i++)
60 | K.addData(Kf[i]);
61 | CameraBodyTransProto.Builder C2B = CameraBodyTransProto.newBuilder();
62 | float[] C2Bf = PipelineSharedData.getCamera2body();
63 | for (int i = 0; i < C2Bf.length; i++)
64 | C2B.addData(C2Bf[i]);
65 |
66 | //-- Bundle everything
67 |
68 | frame.setMetadata(meta.build());
69 | frame.setCameraMatrix(K.build());
70 | frame.setCameraBodyTrans(C2B.build());
71 | frame.setId(3l); // should contain an identifier for the device! TODO
72 | frame.setSeq(PipelineSharedData.noFrames);
73 |
74 | setData( frame.build().toByteArray() );
75 | }
76 |
77 | }
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/SWIGTYPE_p_cv__Mat.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class SWIGTYPE_p_cv__Mat {
12 | private long swigCPtr;
13 |
14 | protected SWIGTYPE_p_cv__Mat(long cPtr, boolean futureUse) {
15 | swigCPtr = cPtr;
16 | }
17 |
18 | protected SWIGTYPE_p_cv__Mat() {
19 | swigCPtr = 0;
20 | }
21 |
22 | protected static long getCPtr(SWIGTYPE_p_cv__Mat obj) {
23 | return (obj == null) ? 0 : obj.swigCPtr;
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/SensorService.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.hardware.Sensor;
6 | import android.hardware.SensorEvent;
7 | import android.hardware.SensorEventListener;
8 | import android.hardware.SensorManager;
9 | import android.os.IBinder;
10 |
11 | import cvg.sfmPipeline.main.PipelineOutMessage.MetadataProto.SensorType;
12 |
13 | public class SensorService extends Service implements SensorEventListener{
14 |
15 | //-- Members
16 | private SensorManager manager;
17 | private Sensor sensor;
18 | private int sensorType;
19 |
20 |
21 | //-- Service
22 | @Override
23 | public IBinder onBind(Intent intent) {
24 | return null;
25 | }
26 |
27 | @Override
28 | public void onDestroy() {
29 | manager.unregisterListener(this);
30 | super.onDestroy();
31 | }
32 |
33 | @Override
34 | public int onStartCommand(Intent intent, int flags, int startId) {
35 | sensorType = Sensor.TYPE_GRAVITY; // FIXME: do not hardcode
36 | PipelineSharedData.setSensorType(SensorType.GRAVITY);
37 | manager = (SensorManager)getSystemService(SENSOR_SERVICE);
38 | sensor = manager.getDefaultSensor(sensorType);
39 | manager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
40 | TimeStamp.restart();
41 | return super.onStartCommand(intent, flags, startId);
42 | }
43 |
44 |
45 | //-- SensorEvenListener
46 | @Override
47 | public void onAccuracyChanged(Sensor sensor, int accuracy) {}
48 |
49 | @Override
50 | public void onSensorChanged(SensorEvent event) {
51 | Sensor sensor = event.sensor;
52 | // avoid google's implementations of the value estimation
53 | // to get only the iNemo values.
54 | if (!sensor.getVendor().equalsIgnoreCase("Google Inc.")){
55 | PipelineSharedData.setLastSensor(event.values);
56 | TimeStamp.updateTime(event.timestamp);
57 | }
58 | }
59 |
60 | private static class TimeStamp {
61 | private static long timestamp;
62 | private static long startime;
63 | private static boolean started = false;
64 |
65 | private TimeStamp(){}
66 |
67 | /**
68 | * Update the timestamp field using the latest sensor timestamp acquired.
69 | * */
70 | public static void updateTime(long t){
71 | if (started){
72 | timestamp = t - startime;
73 | PipelineSharedData.setTimestamp(timestamp/1000000); // return milliseconds
74 | }else{
75 | startime = t;
76 | timestamp = 0;
77 | started = true;
78 | }
79 | }
80 |
81 | public static void restart(){
82 | started = false;
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/TCPread.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.DataInputStream;
5 | import java.io.IOException;
6 | import java.io.InputStreamReader;
7 | import java.net.Socket;
8 | import java.net.UnknownHostException;
9 |
10 | import android.content.Context;
11 | import android.os.AsyncTask;
12 | import android.widget.Toast;
13 |
14 | public class TCPread extends AsyncTask{
15 |
16 | private String IPadd;
17 | private int port;
18 | private Context UIcontext;
19 |
20 | public TCPread(Context ui, String IPhost, int comPort){
21 | IPadd = IPhost;
22 | port = comPort;
23 | UIcontext = ui;
24 | }
25 |
26 | @Override
27 | protected Void doInBackground(Void... params) {
28 | Socket socket = null;
29 | DataInputStream dataInputStream = null;
30 | try {
31 | socket = new Socket(IPadd, port);
32 | publishProgress("connection");
33 | String line = "";
34 | BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
35 | while(!isCancelled()){
36 | line = in.readLine();
37 | if(line != null)
38 | publishProgress(line);
39 | }
40 | } catch (UnknownHostException e) {
41 | e.printStackTrace();
42 | } catch (IOException e) {
43 | // the server is probably not available yet
44 | publishProgress("host_not_found_123456");
45 | e.printStackTrace();
46 | }
47 | finally{
48 | if (socket != null){
49 | try {
50 | socket.close();
51 | } catch (IOException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 | if (dataInputStream != null){
56 | try {
57 | dataInputStream.close();
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | }
61 | }
62 | }
63 | return null;
64 | }
65 |
66 | @Override
67 | protected void onProgressUpdate(String... values) {
68 | // incoming commands (strings) from TCP are handled here.
69 | if(values[0].startsWith("snap")){
70 | PipelineActivity.grabFrame.performClick();
71 | PipelineActivity.console.append("\nremote grab frame command:");
72 | }
73 |
74 | if(values[0].contentEquals("q")){
75 | cancel(true);
76 | Toast.makeText(UIcontext,
77 | "Connection terminated.",
78 | Toast.LENGTH_LONG).show();
79 | }
80 |
81 | if(values[0].contentEquals("host_not_found_123456")){
82 | Toast.makeText(UIcontext,
83 | "Connection failed. TCP server at " + IPadd + " : " + port +" is not found.",
84 | Toast.LENGTH_LONG).show();
85 | }
86 |
87 | if(values[0].startsWith("connection"))
88 | PipelineActivity.console.append("\nTCP connected to " + IPadd + ":" + port);
89 |
90 | super.onProgressUpdate(values);
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/Timer.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import android.util.Log;
4 |
5 | public class Timer {
6 |
7 | private static long start;
8 |
9 | private Timer(){}
10 |
11 | public static void init(){
12 | start = System.nanoTime();
13 | }
14 |
15 | public static void toc(String funcName){// millis
16 | int elapsed = (int)(System.nanoTime() - start)/1000000;
17 | Log.e("Timer", elapsed + " ms in " + funcName);
18 | start = System.nanoTime();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/UDPsend.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import java.io.IOException;
4 | import java.net.DatagramPacket;
5 | import java.net.DatagramSocket;
6 | import java.net.InetAddress;
7 | import java.net.NetworkInterface;
8 | import java.util.Arrays;
9 | import java.util.zip.CRC32;
10 | import java.util.zip.Checksum;
11 | import android.os.AsyncTask;
12 | import android.util.Log;
13 |
14 | public class UDPsend extends AsyncTask {
15 |
16 | //-- Constants
17 | private static final int UDP_SERVER_PORT = 50050;
18 | private String TAG = "UDPsend::ProtoLog";
19 | private static final String IPnet = PipelineSharedData.getLocalIpAddress();
20 |
21 | //-- Members
22 | private DatagramSocket socket;
23 | public boolean send = false;
24 | private String IP;
25 | private int messlen = 0;
26 |
27 | public UDPsend(){
28 | // obtain broadcast IP from net IP
29 | String[] splitted = IPnet.split("\\.");
30 | IP = splitted[0]+"."+splitted[1]+"."+splitted[2]+".255";
31 | Log.i(TAG, "UDP broadcast at: "+IP);
32 | }
33 |
34 | @Override
35 | protected Void doInBackground(byte[]... messageA) {
36 | while(!PipelineSharedData.ready2send){
37 | try {
38 | Thread.sleep(50);
39 | } catch (InterruptedException e1) {
40 | // TODO Auto-generated catch block
41 | e1.printStackTrace();
42 | }
43 | }
44 | if(PipelineSharedData.ready2send){
45 | PipelineSharedData.ready2send = false;
46 | try {
47 | byte[] message = messageA[0];
48 | InetAddress thisAddress = InetAddress.getByName(IP);
49 | socket = new DatagramSocket();
50 | messlen = message.length;
51 | // split the message (if necessary) and send through UDP
52 | NetworkInterface ni = NetworkInterface.getByInetAddress(InetAddress.getByName(IPnet));
53 | int chunkNo = (int) Math.ceil((double)messlen / (double)ni.getMTU());
54 | String headerStr = "ProtobuffMessage_"+chunkNo;
55 | DatagramPacket header = new DatagramPacket(headerStr.getBytes(), headerStr.length(),
56 | thisAddress, UDP_SERVER_PORT);
57 | socket.send(header);
58 | for (int i = 0; i < chunkNo; i++){
59 | int start = Math.min(messlen,i * ni.getMTU());
60 | int end = Math.min(messlen, (i+1)*ni.getMTU());
61 | byte[] thisChunk = Arrays.copyOfRange(message, start, end);
62 | DatagramPacket dp = new DatagramPacket(thisChunk, thisChunk.length,
63 | thisAddress, UDP_SERVER_PORT);
64 | socket.send(dp);
65 | }
66 | Checksum check = new CRC32();
67 | check.update(message, 0, messlen);
68 | long CHKSUM = check.getValue();
69 | DatagramPacket checkPack = new DatagramPacket(String.valueOf(CHKSUM).getBytes(),
70 | String.valueOf(CHKSUM).getBytes().length, thisAddress, UDP_SERVER_PORT);
71 | socket.send(checkPack);
72 | socket.close();
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | }
76 | }
77 | return null;
78 | }
79 |
80 | @Override
81 | protected void onPostExecute(Void result) {
82 | PipelineSharedData.ready2send = true;
83 | PipelineActivity.console.append("\n"+messlen+" bytes sent");
84 | PipelineActivity.grabFrame.setEnabled(true);
85 | super.onPostExecute(result);
86 | }
87 |
88 |
89 |
90 | }
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/UDPthread.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.net.DatagramPacket;
6 | import java.net.DatagramSocket;
7 | import java.net.InetAddress;
8 | import java.net.InetSocketAddress;
9 | import java.net.InterfaceAddress;
10 | import java.net.NetworkInterface;
11 | import java.net.Socket;
12 | import java.net.SocketAddress;
13 | import java.net.SocketException;
14 | import java.nio.channels.DatagramChannel;
15 | import java.util.Enumeration;
16 |
17 | import android.os.AsyncTask;
18 | import android.util.Log;
19 | /**
20 | * This version of the app will not log the VICON data, instead the incoming data from the UDP
21 | * will be used to control the app remotely.
22 | **/
23 | public class UDPthread extends AsyncTask {
24 |
25 | //-- Constants
26 | private static final int MAX_UDP_DATAGRAM_LEN = 1024;
27 | private static final int UDP_SERVER_PORT = 50000;
28 | private static final String TAG = "ProtoLog::UDPthread";
29 | private static final String IP = "192.168.0.255";
30 |
31 | //-- Members
32 | private DatagramSocket socket;
33 | private float[] lastValue = new float[]{0.f,0.f,0.f,0.f,0.f,0.f};
34 |
35 |
36 | @Override
37 | protected Void doInBackground(Void... a) {
38 | try {
39 | DatagramChannel channel = DatagramChannel.open();
40 | InetAddress thisAddress = InetAddress.getByName(IP);
41 | socket = channel.socket();
42 | socket.setReuseAddress(true);
43 | SocketAddress add = new InetSocketAddress(thisAddress, UDP_SERVER_PORT);
44 | socket.bind(add);
45 | byte[] lMsg = new byte[MAX_UDP_DATAGRAM_LEN];
46 | DatagramPacket dp = new DatagramPacket(lMsg, lMsg.length);
47 | while(!isCancelled()){
48 | socket.receive(dp);
49 | publishProgress(new String(lMsg, 0, dp.getLength()));
50 | }
51 |
52 | } catch (IOException e) {
53 | e.printStackTrace();
54 | }
55 | return null;
56 | }
57 |
58 | @Override
59 | protected void onProgressUpdate(String... message){
60 | String[] tokens = message[0].split(", ");
61 | int i = 0;
62 | for (String s : tokens) {
63 | lastValue[i] = Float.parseFloat(s);
64 | i++;
65 | }
66 | PipelineSharedData.setLastGroundTr(lastValue);
67 | }
68 | @Override
69 | protected void onCancelled(){
70 | if (socket != null){
71 | socket.close();
72 | }
73 | }
74 |
75 | // TODO: use this instead of hardcoding the IP, port SHOULD be hardcoded
76 | private InetAddress getBroadcastAddress(){
77 | Enumeration interfaces;
78 | try {
79 | interfaces = NetworkInterface.getNetworkInterfaces();
80 | while (interfaces.hasMoreElements()) {
81 | NetworkInterface networkInterface = interfaces.nextElement();
82 | if (networkInterface.isLoopback())
83 | continue;
84 | for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) {
85 | InetAddress broadcast = interfaceAddress.getBroadcast();
86 | if (broadcast == null)
87 | continue;
88 | return broadcast;
89 | }
90 | }
91 | } catch (SocketException e1) {
92 | e1.printStackTrace();
93 | }
94 | return null;
95 | }
96 |
97 | }
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/VideoGrabber.java:
--------------------------------------------------------------------------------
1 | package cvg.sfmPipeline.main;
2 |
3 | import java.util.List;
4 |
5 | import org.opencv.core.Size;
6 | import org.opencv.highgui.VideoCapture;
7 | import org.opencv.highgui.Highgui;
8 |
9 | import android.content.Context;
10 | import android.graphics.Bitmap;
11 | import android.graphics.Canvas;
12 | import android.util.AttributeSet;
13 | import android.util.Log;
14 | import android.view.SurfaceHolder;
15 | import android.view.SurfaceView;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 |
19 | public abstract class VideoGrabber extends SurfaceView implements SurfaceHolder.Callback, Runnable {
20 | private static final String TAG = "sfmpipe::SurfaceView";
21 |
22 | private SurfaceHolder mHolder;
23 | private VideoCapture mCamera;
24 | private FpsMeter mFps;
25 |
26 | public VideoGrabber(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | mHolder = getHolder();
29 | mHolder.addCallback(this);
30 | mFps = new FpsMeter();
31 | Log.i(TAG, "Instantiated new " + this.getClass());
32 | }
33 |
34 | public boolean openCamera() {
35 | Log.i(TAG, "openCamera");
36 | synchronized (this) {
37 | releaseCamera();
38 | mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);//use Highgui.CV_CAP_ANDROID+1 for front camera
39 | if (!mCamera.isOpened()) {
40 | mCamera.release();
41 | mCamera = null;
42 | Log.e(TAG, "Failed to open native camera");
43 | return false;
44 | }
45 | }
46 | return true;
47 | }
48 |
49 | public void releaseCamera() {
50 | Log.i(TAG, "releaseCamera");
51 | synchronized (this) {
52 | if (mCamera != null) {
53 | mCamera.release();
54 | mCamera = null;
55 | }
56 | }
57 | }
58 |
59 | public void setupCamera(int width, int height) {
60 | Log.i(TAG, "setupCamera("+width+", "+height+")");
61 | synchronized (this) {
62 | if (mCamera != null && mCamera.isOpened()) {
63 | List sizes = mCamera.getSupportedPreviewSizes();
64 | int mFrameWidth = width;
65 | int mFrameHeight = height;
66 |
67 | // selecting best camera size to match width x height
68 | {
69 | double minDiff = Double.MAX_VALUE;
70 | for (Size size : sizes) {
71 | if (Math.abs(size.height - height) < minDiff) {
72 | mFrameWidth = (int) size.width;
73 | mFrameHeight = (int) size.height;
74 | minDiff = Math.abs(size.height - height);
75 | }
76 | }
77 | }
78 |
79 | mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
80 | mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
81 | // mCamera.set(Highgui.CV_CAP_ANDROID_FOCUS_MODE_INFINITY, 1);
82 | }
83 | }
84 |
85 | }
86 |
87 | public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
88 | Log.i(TAG, "surfaceChanged");
89 | // two options, try to fill the surface holder or
90 | // use the standard resolution for the pipeline (the one
91 | // used for calibration) 640x480.
92 | setupCamera(640, 480);
93 | changeSurfaceSize(640, 480);
94 | }
95 |
96 | public void surfaceCreated(SurfaceHolder holder) {
97 | Log.i(TAG, "surfaceCreated");
98 | (new Thread(this)).start();
99 | }
100 |
101 | public void surfaceDestroyed(SurfaceHolder holder) {
102 | Log.i(TAG, "surfaceDestroyed");
103 | releaseCamera();
104 | }
105 |
106 | private SurfaceView changeSurfaceSize(int width, int height){
107 | SurfaceView trueview = (SurfaceView)((View)getParent()).findViewById(R.id.camPreview);
108 | ViewGroup.LayoutParams params = trueview.getLayoutParams();
109 | params.height = height;
110 | params.width = width;
111 | trueview.setLayoutParams(params);
112 | return trueview;
113 | }
114 |
115 | /**
116 | * Main method to process the data aquired by the opencv video
117 | * capture objects. This process frame method should call the
118 | * appropriate native (or java) functions for the pipeline.
119 | * */
120 | protected abstract Bitmap processFrame(VideoCapture capture);
121 |
122 | public void run() {
123 | Log.i(TAG, "Starting processing thread");
124 | mFps.init();
125 | while (true) {
126 | Bitmap bmp = null;
127 | synchronized (this) {
128 | if (mCamera == null)
129 | break;
130 |
131 | if (!mCamera.grab()) {
132 | Log.e(TAG, "mCamera.grab() failed");
133 | break;
134 | }
135 | bmp = processFrame(mCamera);
136 | mFps.measure();
137 | }
138 |
139 | if (bmp != null) {
140 | Canvas canvas = mHolder.lockCanvas();
141 | if (canvas != null) {
142 | canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()) / 2, null);
143 | mFps.draw(canvas, (canvas.getWidth() - bmp.getWidth()) / 2, (canvas.getHeight() - bmp.getHeight()) / 2);
144 | mHolder.unlockCanvasAndPost(canvas);
145 | }
146 | bmp.recycle();
147 | }
148 | }
149 |
150 | Log.i(TAG, "Finishing processing thread");
151 | }
152 | }
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/sfmmatcher.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class sfmmatcher {
12 | }
13 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/sfmmatcherJNI.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class sfmmatcherJNI {
12 | public final static native long new_Matcher();
13 | public final static native void delete_Matcher(long jarg1);
14 | public final static native long new_MatcherFLANN(long jarg1, Frame jarg1_, long jarg2, Frame jarg2_);
15 | public final static native boolean MatcherFLANN_matchFrames(long jarg1, MatcherFLANN jarg1_, int jarg2, int jarg3);
16 | public final static native boolean MatcherFLANN_buildMatchProtoMessage(long jarg1, MatcherFLANN jarg1_);
17 | public final static native byte[] MatcherFLANN_getMatches(long jarg1, MatcherFLANN jarg1_);
18 | public final static native void delete_MatcherFLANN(long jarg1);
19 | public final static native long new_Frame__SWIG_0();
20 | public final static native long new_Frame__SWIG_1(long jarg1);
21 | public final static native void Frame_extractFeatures(long jarg1, Frame jarg1_);
22 | public final static native void Frame_addFrame(long jarg1, Frame jarg1_, long jarg2);
23 | public final static native boolean Frame_buildFrameProtoMessage(long jarg1, Frame jarg1_, boolean jarg2);
24 | public final static native byte[] Frame_getFrame(long jarg1, Frame jarg1_);
25 | public final static native void Frame_Descriptors_set(long jarg1, Frame jarg1_, long jarg2);
26 | public final static native long Frame_Descriptors_get(long jarg1, Frame jarg1_);
27 | public final static native void delete_Frame(long jarg1);
28 | public final static native long MatcherFLANN_SWIGUpcast(long jarg1);
29 | }
30 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/sfmpipeline.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class sfmpipeline {
12 | }
13 |
--------------------------------------------------------------------------------
/src/cvg/sfmPipeline/main/sfmpipelineJNI.java:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | * This file was automatically generated by SWIG (http://www.swig.org).
3 | * Version 2.0.4
4 | *
5 | * Do not make changes to this file unless you know what you are doing--modify
6 | * the SWIG interface file instead.
7 | * ----------------------------------------------------------------------------- */
8 |
9 | package cvg.sfmPipeline.main;
10 |
11 | public class sfmpipelineJNI {
12 | public final static native long new_Frame__SWIG_0();
13 | public final static native long new_Frame__SWIG_1(long jarg1);
14 | public final static native void Frame_extractFeatures(long jarg1, Frame jarg1_);
15 | public final static native void Frame_addFrame(long jarg1, Frame jarg1_, long jarg2);
16 | public final static native boolean Frame_buildFrameProtoMessage(long jarg1, Frame jarg1_, boolean jarg2);
17 | public final static native byte[] Frame_getFrame(long jarg1, Frame jarg1_);
18 | public final static native void delete_Frame(long jarg1);
19 | }
20 |
--------------------------------------------------------------------------------
/src/data.proto:
--------------------------------------------------------------------------------
1 | package sfm;
2 |
3 | option java_package = "cvg.sfmPipeline.main";
4 | option java_outer_classname = "PipelineOutMessage";
5 |
6 | message CvMatDimProto {
7 | optional int32 size = 1;
8 | optional int32 step = 2;
9 | }
10 |
11 | message cvMatProto {
12 | optional int32 n_dims = 1;
13 | repeated CvMatDimProto dims = 2;
14 | optional int32 type = 3;
15 | optional bytes bytedata = 4;
16 | enum ImageType {
17 | cvMat = 0;
18 | JPEG = 1;
19 | RAW = 2;
20 | }
21 | optional ImageType format = 5 [default = cvMat];
22 | }
23 |
24 | message Keypoints {
25 | message cvKeypoint{
26 | optional float ptX = 1;
27 | optional float ptY = 2;
28 | optional float size = 3;
29 | optional float angle = 4 [default = -1];
30 | optional float response = 5;
31 | optional int32 octave = 6;
32 | optional int32 class_id = 7;
33 | }
34 | repeated cvKeypoint keypoints = 1;
35 | }
36 |
37 | message CameraMatrixProto {
38 | repeated float data = 1;
39 | }
40 |
41 | message CameraBodyTransProto {
42 | repeated float data = 1;
43 | }
44 |
45 | message MetadataProto {
46 | optional float ang_x = 1;
47 | optional float ang_y = 2;
48 | optional float ang_z = 3;
49 | optional float pos_x = 4;
50 | optional float pos_y = 5;
51 | optional float pos_z = 6;
52 |
53 | enum SensorType {
54 | ACCEL = 0;
55 | GYRO = 1;
56 | MAGNETO = 2;
57 | LINACCEL = 3;
58 | ORIENTATION = 4;
59 | GRAVITY = 5;
60 | ROTVECT = 6;
61 | }
62 |
63 | optional fixed64 timestamp = 7;
64 | optional float val_0 = 8;
65 | optional float val_1 = 9;
66 | optional float val_2 = 10;
67 | optional SensorType type = 11 [default = GRAVITY];
68 | }
69 |
70 | message CvRectProto {
71 | optional int32 x = 1;
72 | optional int32 y = 2;
73 | optional int32 width = 3;
74 | optional int32 height = 4;
75 | }
76 |
77 | message FrameProto {
78 | repeated cvMatProto images = 1;
79 | optional CameraMatrixProto cameraMatrix = 2;
80 | optional CameraBodyTransProto cameraBodyTrans = 3;
81 | optional MetadataProto metadata = 4;
82 | optional fixed64 id = 5;
83 | optional fixed64 seq = 6;
84 | optional float baseline = 8;
85 | optional CvRectProto roi = 9;
86 | optional Keypoints keypoints = 10;
87 | optional cvMatProto descriptors = 11;
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/matches.proto:
--------------------------------------------------------------------------------
1 | package sfm;
2 |
3 | option java_package = "cvg.sfmPipeline.main";
4 | option java_outer_classname = "MatchesOutMessage";
5 |
6 | message DMatches {
7 | optional uint32 queryIdx = 1;
8 | optional uint32 trainIdx = 2;
9 | optional uint32 imgIdx = 3;
10 | optional float distance =4;
11 | }
12 |
13 | message MatchesProto {
14 | optional fixed64 imageLseq = 1;
15 | optional fixed64 imageRseq = 2;
16 | repeated DMatches matches = 3;
17 | }
18 |
--------------------------------------------------------------------------------