/ocr/ocrservice/src/com/googlecode/eyesfree/opticflow/OpticalFlow.java
Java | 92 lines | 46 code | 22 blank | 24 comment | 0 complexity | 77d908cfe259e0119be2028e1165cbc8 MD5 | raw file
1/* 2 * Copyright (C) 2011 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.googlecode.eyesfree.opticflow; 18 19import android.graphics.PointF; 20 21/** 22 * Interface to native optical flow library. 23 * 24 * Modified by Alan Viverette from Andrew Harp's original source. 25 * 26 * @author Andrew Harp 27 * @author alanv@google.com (Alan Viverette) 28 */ 29public class OpticalFlow { 30 static { 31 System.loadLibrary("lept"); 32 System.loadLibrary("opticalflow"); 33 } 34 35 @Override 36 protected void finalize() { 37 resetNative(); 38 } 39 40 public void initialize(int width, int height, int downsampleFactor) { 41 initNative(width, height, downsampleFactor); 42 } 43 44 public void setImage(byte[] data, long timestamp) { 45 addFrameNative(data, timestamp); 46 } 47 48 public void computeOpticalFlow() { 49 computeFeaturesNative(true); 50 computeFlowNative(); 51 printInfoNative(); 52 } 53 54 public float[] getFeatures(boolean onlyReturnCorrespondingFeatures) { 55 return getFeaturesNative(onlyReturnCorrespondingFeatures); 56 } 57 58 public PointF getAccumulatedDelta( 59 long timestamp, float positionX, float positionY, float radius) { 60 float[] delta = new float[2]; 61 62 getAccumulatedDeltaNative(timestamp, positionX, positionY, radius, delta); 63 64 return new PointF(delta[0], delta[1]); 65 } 66 67 public void addInterestRegion(int numX, int numY, int left, int top, int right, int bottom) { 68 addInterestRegionNative(numX, numY, left, top, right, bottom); 69 } 70 71 /*********************** NATIVE METHODS *************************************/ 72 73 private native void initNative(int width, int height, int downsampleFactor); 74 75 private native void addFrameNative(byte[] data, long timeStamp); 76 77 private native void computeFeaturesNative(boolean cachedOk); 78 79 private native void computeFlowNative(); 80 81 private native void printInfoNative(); 82 83 private native void getAccumulatedDeltaNative( 84 long timestamp, float positionX, float positionY, float radius, float[] delta); 85 86 private native void addInterestRegionNative( 87 int numX, int numY, float left, float top, float right, float bottom); 88 89 private native float[] getFeaturesNative(boolean onlyReturnCorrespondingFeatures); 90 91 private native void resetNative(); 92}