├── app
├── .gitignore
├── libs
│ ├── facetracking.jar
│ ├── android-extend.jar
│ ├── armeabi
│ │ ├── libcache.so
│ │ ├── libimage.so
│ │ ├── libmpbase.so
│ │ ├── librender.so
│ │ ├── libserial.so
│ │ ├── libvideo.so
│ │ └── libArcSoft_FTEngine.so
│ └── armeabi-v7a
│ │ ├── libcache.so
│ │ ├── libimage.so
│ │ ├── libmpbase.so
│ │ ├── librender.so
│ │ ├── libserial.so
│ │ ├── libvideo.so
│ │ └── libArcSoft_FTEngine.so
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── icon.jpg
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── icon.jpg
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── icon.jpg
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── icon.jpg
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── icon.jpg
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ ├── bluetooth_main.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── activity_camera.xml
│ │ │ └── bluetooth_fragment.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ └── com
│ │ │ └── hitsz
│ │ │ └── autotrack
│ │ │ ├── Params.java
│ │ │ ├── Application.java
│ │ │ ├── FaceDB.java
│ │ │ ├── PermissionAcitivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── DetecterActivity.java
│ │ │ └── BluetoothFragment.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── images
├── show.gif
└── Screenshot.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── local.properties
├── gradle.properties
├── AutoTrack.iml
├── README.md
├── LICENSE
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/images/show.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/images/show.gif
--------------------------------------------------------------------------------
/images/Screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/images/Screenshot.png
--------------------------------------------------------------------------------
/app/libs/facetracking.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/facetracking.jar
--------------------------------------------------------------------------------
/app/libs/android-extend.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/android-extend.jar
--------------------------------------------------------------------------------
/app/libs/armeabi/libcache.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/libcache.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libimage.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/libimage.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libmpbase.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/libmpbase.so
--------------------------------------------------------------------------------
/app/libs/armeabi/librender.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/librender.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libserial.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/libserial.so
--------------------------------------------------------------------------------
/app/libs/armeabi/libvideo.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/libvideo.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libcache.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/libcache.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libimage.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/libimage.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libmpbase.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/libmpbase.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/librender.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/librender.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libserial.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/libserial.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libvideo.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/libvideo.so
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AutoTrack
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/libs/armeabi/libArcSoft_FTEngine.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi/libArcSoft_FTEngine.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-hdpi/icon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-mdpi/icon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xhdpi/icon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xxhdpi/icon.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xxxhdpi/icon.jpg
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/libArcSoft_FTEngine.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/libs/armeabi-v7a/libArcSoft_FTEngine.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imuncle/AutoTrack/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/Params.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | public class Params {
4 | public static final int DETECT_CONNECT = 8;
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jul 27 10:38:59 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/Application.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | public class Application extends android.app.Application {
4 | static FaceDB mFaceDB;
5 |
6 | @Override
7 | public void onCreate() {
8 | super.onCreate();
9 | mFaceDB = new FaceDB(this.getExternalCacheDir().getPath());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/FaceDB.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | public class FaceDB {
4 |
5 | public static String appid = "CGJj3PzqWp9QccMUxLy3DRXfUHkBfdx7gLHoNUv2qQzE";
6 | public static String ft_key = "A58T5CrTnjfeKH1GsY7Csgq1aVCeyLqXeEuG7QjBSwF7";
7 |
8 |
9 | String mDBPath;
10 |
11 | public FaceDB(String path) {
12 | mDBPath = path;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file must *NOT* be checked into Version Control Systems,
2 | # as it contains information specific to your local configuration.
3 | #
4 | # Location of the SDK. This is only used by Gradle.
5 | # For customization when using a Version Control System, please read the
6 | # header note.
7 | #Fri Jul 27 10:39:00 CST 2018
8 | ndk.dir=E\:\\Android\\SDK\\ndk-bundle
9 | sdk.dir=E\:\\Android\\SDK
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bluetooth_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/AutoTrack.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
18 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AutoTrack
2 |
3 | 2018年参加广东省电子设计大赛时的作品,当时拿了省一等奖。作品效果如下:
4 |
5 | 
6 |
7 | 软件界面如下:
8 |
9 | 
10 |
11 | 作品分为软件部分(Android application)和硬件部分(arduino),两者通过蓝牙连接。硬件部分很简单,只是简单地接收蓝牙数据然后控制舵机转向,运用到了一点点PID算法。
12 |
13 | 这里开源的是**软件部分**,只支持Android,不支持IOS。
14 |
15 | ## 项目详情
16 |
17 | 本项目基于Android Studio开发,这里是精简过后的文件结构,删去了build后的内容,导入Android Studio能正常使用。
18 |
19 | 其中最重要的人脸跟踪部分使用了[虹软](http://www.arcsoft.com.cn/technology/face.html)的免费so库,基于虹软自己的演示demo进行修改,删除了人脸识别功能,只保留了人脸跟踪部分的功能,另外加入了蓝牙功能。
20 |
21 | ## 通信协议
22 |
23 | 字母|含义|速度
24 | :--:|:--:|:--:
25 | a|舵机不动|0
26 | b|舵机向下转动|很慢
27 | c|舵机向下转动|慢
28 | d|舵机向下转动|快
29 | e|舵机向下转动|很快
30 | f|舵机向上转动|很慢
31 | g|舵机向上转动|慢
32 | h|舵机向上转动|快
33 | i|舵机向上转动|很快
34 | l|舵机向左转动|很慢
35 | m|舵机向左转动|慢
36 | n|舵机向左转动|快
37 | o|舵机向左转动|很快
38 | r|舵机向右转动|很慢
39 | s|舵机向右转动|慢
40 | t|舵机向右转动|快
41 | u|舵机向右转动|很快
42 |
43 | ## 遗留问题
44 |
45 | 蓝牙功能很不稳定,特别是连接蓝牙的时候极容易崩溃,目前没有改进的想法。希望借鉴者注意。
46 |
47 | ## 开源协议
48 |
49 | MIT License
50 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | defaultConfig {
6 | applicationId "com.hitsz.autotrack"
7 | minSdkVersion 21
8 | targetSdkVersion 25
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | sourceSets {
21 | main {
22 | jniLibs.srcDirs = ['libs']
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | testCompile 'junit:junit:4.12'
31 | compile 'com.android.support:appcompat-v7:25.4.0'
32 | compile 'com.android.support:design:25.4.0'
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 big_uncle
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
16 |
45 |
46 |
51 |
52 |
58 |
59 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bluetooth_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
37 |
38 |
42 |
43 |
48 |
49 |
53 |
54 |
59 |
60 |
65 |
70 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/PermissionAcitivity.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.os.Process;
10 | import android.widget.Toast;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | public class PermissionAcitivity extends Activity {
16 | public static int PERMISSION_REQ = 0x123456;
17 |
18 | private String[] mPermission = new String[] {
19 | Manifest.permission.INTERNET,
20 | Manifest.permission.CAMERA,
21 | Manifest.permission.WRITE_EXTERNAL_STORAGE
22 | };
23 |
24 | private List mRequestPermission = new ArrayList();
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | // TODO Auto-generated method stub
29 | super.onCreate(savedInstanceState);
30 |
31 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
32 | for (String one : mPermission) {
33 | if (PackageManager.PERMISSION_GRANTED != this.checkPermission(one, Process.myPid(), Process.myUid())) {
34 | mRequestPermission.add(one);
35 | }
36 | }
37 | if (!mRequestPermission.isEmpty()) {
38 | this.requestPermissions(mRequestPermission.toArray(new String[mRequestPermission.size()]), PERMISSION_REQ);
39 | return ;
40 | }
41 | }
42 | startActiviy();
43 | }
44 |
45 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
46 | // 版本兼容
47 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
48 | return;
49 | }
50 | if (requestCode == PERMISSION_REQ) {
51 | for (int i = 0; i < grantResults.length; i++) {
52 | for (String one : mPermission) {
53 | if (permissions[i].equals(one) && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
54 | mRequestPermission.remove(one);
55 | }
56 | }
57 | }
58 | startActiviy();
59 | }
60 | }
61 |
62 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
63 | if (requestCode == PERMISSION_REQ) {
64 | if (resultCode == 0) {
65 | this.finish();
66 | }
67 | }
68 | }
69 |
70 | public void startActiviy() {
71 | if (mRequestPermission.isEmpty()) {
72 | new Thread(new Runnable() {
73 | @Override
74 | public void run() {
75 | PermissionAcitivity.this.runOnUiThread(new Runnable() {
76 | @Override
77 | public void run() {
78 | Intent intent = new Intent(PermissionAcitivity.this, MainActivity.class);
79 | startActivityForResult(intent, PERMISSION_REQ);
80 | }
81 | });
82 | }
83 | }).start();
84 | } else {
85 | Toast.makeText(this, "PERMISSION DENIED!", Toast.LENGTH_LONG).show();
86 | new Handler().postDelayed(new Runnable() {
87 | @Override
88 | public void run() {
89 | PermissionAcitivity.this.finish();
90 | }
91 | }, 3000);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | import android.bluetooth.BluetoothAdapter;
4 | import android.bluetooth.BluetoothDevice;
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.IntentFilter;
9 | import android.os.Handler;
10 | import android.support.design.widget.TabLayout;
11 | import android.support.v4.app.Fragment;
12 | import android.support.v4.app.FragmentManager;
13 | import android.support.v4.app.FragmentPagerAdapter;
14 | import android.support.v4.view.ViewPager;
15 | import android.support.v7.app.AppCompatActivity;
16 | import android.os.Bundle;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | public class MainActivity extends AppCompatActivity{
22 |
23 | BluetoothFragment bluetoothFragment;
24 | DetecterActivity detecterActivity;
25 | private BlueToothStateReceiver mReceiver;//广播接收器
26 |
27 | Handler uiHandler =new Handler();
28 |
29 | public Handler getUiHandler() {
30 | return uiHandler;
31 | }
32 |
33 | public Handler getbHandler(){
34 | return bluetoothFragment.getmHandler();
35 | }
36 |
37 | TabLayout tabLayout;
38 | ViewPager viewPager;
39 | MyPagerAdapter pagerAdapter;
40 | String[] titleList=new String[]{"蓝牙连接","自追踪拍摄"};
41 | List fragmentList=new ArrayList<>();
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_main);
46 | initUI();
47 | registerRec();
48 | }
49 |
50 | /**
51 | * 初始化界面
52 | */
53 | private void initUI() {
54 | tabLayout= (TabLayout) findViewById(R.id.tab_layout);
55 | viewPager= (ViewPager) findViewById(R.id.view_pager);
56 |
57 | tabLayout.addTab(tabLayout.newTab().setText(titleList[0]));
58 | tabLayout.addTab(tabLayout.newTab().setText(titleList[1]));
59 |
60 | bluetoothFragment=new BluetoothFragment();
61 | detecterActivity = new DetecterActivity();
62 | fragmentList.add(bluetoothFragment);
63 | fragmentList.add(detecterActivity);
64 |
65 | pagerAdapter=new MyPagerAdapter(getSupportFragmentManager());
66 | viewPager.setAdapter(pagerAdapter);
67 | tabLayout.setupWithViewPager(viewPager);
68 | }
69 |
70 | /**
71 | * ViewPager 适配器
72 | */
73 | public class MyPagerAdapter extends FragmentPagerAdapter {
74 |
75 | public MyPagerAdapter(FragmentManager fm) {
76 | super(fm);
77 | }
78 |
79 | @Override
80 | public Fragment getItem(int position) {
81 | return fragmentList.get(position);
82 | }
83 |
84 | @Override
85 | public int getCount() {
86 | return fragmentList.size();
87 | }
88 |
89 | @Override
90 | public CharSequence getPageTitle(int position) {
91 | return titleList[position];
92 | }
93 | }
94 |
95 | private void registerRec() {
96 | //3.注册蓝牙广播
97 | mReceiver = new BlueToothStateReceiver();
98 | IntentFilter filter = new IntentFilter();
99 | filter.addAction(BluetoothDevice.ACTION_FOUND);//搜多到蓝牙
100 | filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);//搜索结束
101 | registerReceiver(mReceiver, filter);
102 | }
103 |
104 | @Override
105 | protected void onDestroy() {
106 | if (mReceiver != null) {
107 | unregisterReceiver(mReceiver);
108 | }
109 | super.onDestroy();
110 | }
111 |
112 | class BlueToothStateReceiver extends BroadcastReceiver {
113 | @Override
114 | public void onReceive(Context context, Intent intent) {
115 | String action = intent.getAction();
116 | switch (action) {
117 | case BluetoothDevice.ACTION_FOUND:
118 | BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
119 | if (bluetoothFragment.listView_device != null) {
120 | bluetoothFragment.addDevice(device);
121 | }
122 | break;
123 | case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
124 | bluetoothFragment.addMessage("搜索结束");
125 | break;
126 | }
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/DetecterActivity.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.ImageFormat;
5 | import android.graphics.Rect;
6 | import android.hardware.Camera;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.support.annotation.Nullable;
11 | import android.util.Log;
12 | import android.view.LayoutInflater;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.TextView;
17 | import android.support.v4.app.Fragment;
18 |
19 | import com.arcsoft.facetracking.AFT_FSDKEngine;
20 | import com.arcsoft.facetracking.AFT_FSDKError;
21 | import com.arcsoft.facetracking.AFT_FSDKFace;
22 | import com.arcsoft.facetracking.AFT_FSDKVersion;
23 | import com.guo.android_extend.tools.CameraHelper;
24 | import com.guo.android_extend.widget.CameraFrameData;
25 | import com.guo.android_extend.widget.CameraGLSurfaceView;
26 | import com.guo.android_extend.widget.CameraSurfaceView;
27 | import com.guo.android_extend.widget.CameraSurfaceView.OnCameraListener;
28 |
29 | import java.util.ArrayList;
30 | import java.util.List;
31 |
32 | public class DetecterActivity extends Fragment implements OnCameraListener, View.OnTouchListener, Camera.AutoFocusCallback {
33 | private final String TAG = this.getClass().getSimpleName();
34 |
35 | private int mWidth, mHeight, mFormat;
36 | private CameraSurfaceView mSurfaceView;
37 | private CameraGLSurfaceView mGLSurfaceView;
38 | private Camera mCamera;
39 |
40 | AFT_FSDKVersion version = new AFT_FSDKVersion();
41 | AFT_FSDKEngine engine = new AFT_FSDKEngine();
42 | List result = new ArrayList<>();
43 |
44 | byte[] mImageNV21 = null;
45 | AFT_FSDKFace mAFT_FSDKFace = null;
46 | MainActivity mainActivity;
47 | Handler mHandler;
48 | Handler blueHandler;
49 | private int right;
50 | private int bottom;
51 | private Rect rectangle;
52 | private String horizon;
53 | private String vertical;
54 | //long mill1;
55 | //long mill2;
56 |
57 | Runnable hide = new Runnable() {
58 | @Override
59 | public void run() {
60 | }
61 | };
62 |
63 | private TextView mTextView2;
64 |
65 | @Nullable
66 | @Override
67 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
68 | //Toast.makeText(getActivity(), "hhhh", Toast.LENGTH_SHORT).show();
69 | return inflater.inflate(R.layout.activity_camera,container,false);
70 | }
71 |
72 | @Override
73 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
74 | mainActivity = (MainActivity) getActivity();
75 | //Toast.makeText(getActivity(), screenHeight+","+screenWidth, Toast.LENGTH_SHORT).show();
76 | mHandler = mainActivity.getUiHandler();
77 | blueHandler = mainActivity.getbHandler();
78 | mGLSurfaceView = (CameraGLSurfaceView) view.findViewById(R.id.glsurfaceView);
79 | mGLSurfaceView.setOnTouchListener(this);
80 | mSurfaceView = (CameraSurfaceView) view.findViewById(R.id.surfaceView);
81 | mSurfaceView.setOnCameraListener(this);
82 | mSurfaceView.setupGLSurafceView(mGLSurfaceView, true, true, 270);
83 | mSurfaceView.debug_print_fps(true, false);
84 | mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
85 | mTextView2 = (TextView) view.findViewById(R.id.textView2);
86 | mWidth = 1280;
87 | mHeight = 960;
88 | mFormat = ImageFormat.NV21;
89 |
90 | AFT_FSDKError err = engine.AFT_FSDK_InitialFaceEngine(FaceDB.appid, FaceDB.ft_key, AFT_FSDKEngine.AFT_OPF_0_HIGHER_EXT, 16, 5);
91 | Log.d(TAG, "AFT_FSDK_InitialFaceEngine =" + err.getCode());
92 | //err = engine.AFT_FSDK_GetVersion(version);
93 | //Log.d(TAG, "AFT_FSDK_GetVersion:" + version.toString() + "," + err.getCode());
94 | }
95 |
96 | @Override
97 | public void onDestroy() {
98 | // TODO Auto-generated method stub
99 | super.onDestroy();
100 | AFT_FSDKError err = engine.AFT_FSDK_UninitialFaceEngine();
101 | Log.d(TAG, "AFT_FSDK_UninitialFaceEngine =" + err.getCode());
102 | }
103 |
104 | @Override
105 | public Camera setupCamera() {
106 | // TODO Auto-generated method stub
107 |
108 | try {
109 | Camera.Parameters parameters = mCamera.getParameters();
110 | parameters.setPreviewSize(mWidth, mHeight);
111 | parameters.setPreviewFormat(mFormat);
112 |
113 | for( Camera.Size size : parameters.getSupportedPreviewSizes()) {
114 | Log.d(TAG, "SIZE:" + size.width + "x" + size.height);
115 | }
116 | for( Integer format : parameters.getSupportedPreviewFormats()) {
117 | Log.d(TAG, "FORMAT:" + format);
118 | }
119 |
120 | List fps = parameters.getSupportedPreviewFpsRange();
121 | for(int[] count : fps) {
122 | Log.d(TAG, "T:");
123 | for (int data : count) {
124 | Log.d(TAG, "V=" + data);
125 | }
126 | }
127 | mCamera.setParameters(parameters);
128 | } catch (Exception e) {
129 | e.printStackTrace();
130 | }
131 | if (mCamera != null) {
132 | mWidth = mCamera.getParameters().getPreviewSize().width;
133 | mHeight = mCamera.getParameters().getPreviewSize().height;
134 | }
135 | return mCamera;
136 | }
137 |
138 | @Override
139 | public void setupChanged(int format, int width, int height) {
140 |
141 | }
142 |
143 | @Override
144 | public boolean startPreviewLater() {
145 | // TODO Auto-generated method stub
146 | return false;
147 | }
148 |
149 | @Override
150 | public Object onPreview(byte[] data, int width, int height, int format, long timestamp) {
151 | AFT_FSDKError err = engine.AFT_FSDK_FaceFeatureDetect(data, width, height, AFT_FSDKEngine.CP_PAF_NV21, result);
152 | Log.d(TAG, "AFT_FSDK_FaceFeatureDetect =" + err.getCode());
153 | Log.d(TAG, "Face=" + result.size());
154 | /*for (AFT_FSDKFace face : result) {
155 | Log.d(TAG, "Face:" + face.toString());
156 | }*/
157 | if (mImageNV21 == null) {
158 | if (!result.isEmpty()) {
159 | mAFT_FSDKFace = result.get(0).clone();
160 |
161 | mImageNV21 = data.clone();
162 | } else {
163 | mHandler.postDelayed(hide, 500);
164 | }
165 | }
166 | //copy rects
167 | Rect[] rects = new Rect[result.size()];
168 | /*mill1 = mill2;
169 | mill2 = System.currentTimeMillis();
170 | Log.d(TAG, "onPreview: "+(mill2-mill1));*/
171 | for (int i = 0; i < result.size(); i++) {
172 | rects[i] = new Rect(result.get(i).getRect());
173 | }
174 | if(result.size()!=0) {
175 | rectangle = result.get(0).getRect();
176 | right = (rectangle.left + rectangle.right) / 2;
177 | bottom = (rectangle.top + rectangle.bottom) / 2;
178 | mHandler.removeCallbacks(hide);
179 | mHandler.post(new Runnable() {
180 | @Override
181 | public void run() {
182 | mTextView2.setText("坐标值:" + right + "," + bottom);
183 | }
184 | });
185 | if(bottom > 510){
186 | if(bottom > 750){
187 | horizon = "i";
188 | }else if(bottom >650){
189 | horizon = "h";
190 | }else if(bottom > 550){
191 | horizon = "g";
192 | }else{
193 | horizon = "f";
194 | }
195 | }else if(bottom < 390){
196 | if(bottom < 150){
197 | horizon = "e";
198 | }else if(bottom < 250){
199 | horizon = "d";
200 | }else if(bottom < 350){
201 | horizon = "c";
202 | }else {
203 | horizon = "b";
204 | }
205 | }else{
206 | horizon = "a";
207 | }
208 | if(right > 660){
209 | if(right > 1000){
210 | vertical = "o";
211 | }else if(right > 900){
212 | vertical = "n";
213 | }else if(right > 750){
214 | vertical = "m";
215 | }else {
216 | vertical = "l";
217 | }
218 | }else if(right < 540){
219 | if(right < 200){
220 | vertical = "u";
221 | }else if(right < 300){
222 | vertical = "t";
223 | }else if(right < 450){
224 | vertical = "s";
225 | }else {
226 | vertical = "r";
227 | }
228 | }else{
229 | vertical = "a";
230 | }
231 | Message message = new Message();
232 | message.what = Params.DETECT_CONNECT;
233 | message.obj = horizon+""+vertical;
234 | blueHandler.sendMessage(message);
235 | }
236 | //clear result.
237 | result.clear();
238 | //return the rects for render.
239 | return rects;
240 | }
241 |
242 | @Override
243 | public void onBeforeRender(CameraFrameData data) {
244 |
245 | }
246 |
247 | @Override
248 | public void onAfterRender(CameraFrameData data) {
249 | mGLSurfaceView.getGLES2Render().draw_rect((Rect[])data.getParams(), Color.GREEN, 2);
250 | }
251 |
252 | @Override
253 | public boolean onTouch(View v, MotionEvent event) {
254 | CameraHelper.touchFocus(mCamera, event, v, this);
255 | return false;
256 | }
257 |
258 | @Override
259 | public void onAutoFocus(boolean success, Camera camera) {
260 | if (success) {
261 | Log.d(TAG, "Camera Focus SUCCESS!");
262 | }
263 | }
264 | }
265 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
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 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hitsz/autotrack/BluetoothFragment.java:
--------------------------------------------------------------------------------
1 | package com.hitsz.autotrack;
2 |
3 | import android.Manifest;
4 | import android.bluetooth.BluetoothAdapter;
5 | import android.bluetooth.BluetoothDevice;
6 | import android.bluetooth.BluetoothServerSocket;
7 | import android.bluetooth.BluetoothSocket;
8 | import android.content.Intent;
9 | import android.os.Build;
10 | import android.os.Bundle;
11 | import android.os.Handler;
12 | import android.os.Message;
13 | import android.support.annotation.Nullable;
14 | import android.support.v4.app.Fragment;
15 | import android.text.TextUtils;
16 | import android.view.LayoutInflater;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.widget.AdapterView;
20 | import android.widget.ArrayAdapter;
21 | import android.widget.Button;
22 | import android.widget.EditText;
23 | import android.widget.ListView;
24 | import android.widget.Toast;
25 |
26 | import java.io.BufferedReader;
27 | import java.io.IOException;
28 | import java.io.InputStream;
29 | import java.io.InputStreamReader;
30 | import java.io.OutputStream;
31 | import java.io.OutputStreamWriter;
32 | import java.io.PrintWriter;
33 | import java.io.UnsupportedEncodingException;
34 | import java.util.ArrayList;
35 | import java.util.List;
36 | import java.util.UUID;
37 |
38 | import static android.app.Activity.RESULT_CANCELED;
39 | import static android.app.Activity.RESULT_OK;
40 |
41 | public class BluetoothFragment extends Fragment {
42 |
43 | public List msglist;
44 | public List devicelist;
45 | public List devices;
46 |
47 | public static final int REQUEST_BT_ENABLE_CODE = 200;
48 | public static final String BT_UUID = "00001101-0000-1000-8000-00805F9B34FB";//uuid
49 |
50 | private BluetoothAdapter mBluetoothAdapter;//蓝牙适配器
51 | public ConnectThread mConnectThread; //客户端线程
52 | private AcceptThread mAcceptThread; //服务端线程
53 |
54 | public ListView listView_device;
55 | public ListView listView_msg;
56 |
57 | EditText inputEt;
58 | Button openBt;
59 | Button closeBt;
60 | Button startBt;
61 | Button stopBt;
62 | Button sendBt;
63 |
64 | private Handler mHandler = new Handler() {
65 | @Override
66 | public void dispatchMessage(Message msg) {
67 | if(msg.what == Params.DETECT_CONNECT){
68 | if(mConnectThread == null){
69 | //Toast.makeText(getActivity(), "没有连接蓝牙设备!", Toast.LENGTH_SHORT).show();
70 | }else {
71 | mConnectThread.write((String) msg.obj);
72 | //addMessage((String) msg.obj);
73 | }
74 | }else {
75 | addMessage((String) msg.obj);
76 | }
77 | }
78 | };
79 |
80 | public Handler getmHandler() {
81 | return mHandler;
82 | }
83 |
84 | @Nullable
85 | @Override
86 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
87 | return inflater.inflate(R.layout.bluetooth_fragment, container, false);
88 | }
89 |
90 | @Override
91 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
92 |
93 | msglist = new ArrayList<>();
94 | devicelist = new ArrayList<>();
95 | devices = new ArrayList<>();
96 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
97 | requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 1001);
98 | }
99 |
100 | inputEt = (EditText) view.findViewById(R.id.input);
101 | openBt = (Button) view.findViewById(R.id.open);
102 | openBt.setOnClickListener(new View.OnClickListener() {
103 | @Override
104 | public void onClick(View v) {
105 | openBT();
106 | addMessage("打开蓝牙");
107 | if (mAcceptThread == null && mBluetoothAdapter != null) {
108 | mAcceptThread = new AcceptThread();
109 | mAcceptThread.start();
110 | addMessage("启动服务线程");
111 | }
112 | }
113 | });
114 | closeBt = (Button) view.findViewById(R.id.close);
115 | closeBt.setOnClickListener(new View.OnClickListener() {
116 | @Override
117 | public void onClick(View view) {
118 | mBluetoothAdapter.disable();
119 | mConnectThread = null;
120 | }
121 | });
122 | startBt = (Button) view.findViewById(R.id.start);
123 | startBt.setOnClickListener(new View.OnClickListener() {
124 | @Override
125 | public void onClick(View view) {
126 | if (mBluetoothAdapter != null) {
127 | clearDevices();//开始搜索前清空上一次的列表
128 | mBluetoothAdapter.startDiscovery();
129 | addMessage("开始搜索蓝牙");
130 | } else {
131 | openBT();
132 | if (mBluetoothAdapter != null) {
133 | clearDevices();//开始搜索前清空上一次的列表
134 | mBluetoothAdapter.startDiscovery();
135 | addMessage("开始搜索蓝牙");
136 | }
137 | }
138 | }
139 | });
140 | stopBt = (Button) view.findViewById(R.id.stop);
141 | stopBt.setOnClickListener(new View.OnClickListener() {
142 | @Override
143 | public void onClick(View view) {
144 | if (mBluetoothAdapter != null && mBluetoothAdapter.isDiscovering()) {
145 | mBluetoothAdapter.cancelDiscovery();
146 | }
147 | }
148 | });
149 | sendBt = (Button) view.findViewById(R.id.send);
150 | sendBt.setOnClickListener(new View.OnClickListener() {
151 | @Override
152 | public void onClick(View view) {
153 | String msg = inputEt.getText().toString();
154 | if (TextUtils.isEmpty(msg)) {
155 | Toast.makeText(getActivity(), "消息为空", Toast.LENGTH_SHORT).show();
156 | return;
157 | }
158 | if (mConnectThread != null) {//证明我主动去链接别人了
159 | mConnectThread.write(msg);
160 | } else if (mAcceptThread != null) {
161 | mAcceptThread.write(msg);
162 | }
163 | addMessage("发送消息:" + msg);
164 | inputEt.setText("");
165 | }
166 | });
167 | listView_msg = (ListView) view.findViewById(R.id.msglist);
168 | listView_device = (ListView) view.findViewById(R.id.devices);
169 |
170 | listView_device.setOnItemClickListener(new AdapterView.OnItemClickListener() {
171 | @Override
172 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
173 | BluetoothDevice bluetoothDevice = devicelist.get(i);
174 | mConnectThread = new ConnectThread(bluetoothDevice);
175 | mConnectThread.start();
176 | }
177 | });
178 |
179 | }
180 |
181 | private void openBT() {
182 | if (mBluetoothAdapter == null) {
183 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
184 | }
185 | //1.设备不支持蓝牙,结束应用
186 | if (mBluetoothAdapter == null) {
187 | addMessage("该设备不支持蓝牙");
188 | return;
189 | }
190 | //2.判断蓝牙是否打开
191 | if (!mBluetoothAdapter.enable()) {
192 | //没打开请求打开
193 | Intent btEnable = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
194 | startActivityForResult(btEnable, REQUEST_BT_ENABLE_CODE);
195 | }
196 | }
197 |
198 | @Override
199 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
200 | if (requestCode == REQUEST_BT_ENABLE_CODE) {
201 | if (resultCode == RESULT_OK) {
202 | //用户允许打开蓝牙
203 | addMessage("用户同意打开蓝牙");
204 | } else if (resultCode == RESULT_CANCELED) {
205 | //用户取消打开蓝牙
206 | addMessage("用户拒绝打开蓝牙");
207 | }
208 | }
209 | super.onActivityResult(requestCode, resultCode, data);
210 | }
211 |
212 | class ConnectThread extends Thread {
213 | private BluetoothDevice mDevice;
214 | private BluetoothSocket mSocket;
215 | private InputStream btIs;
216 | private OutputStream btOs;
217 | private boolean canRecv;
218 | private PrintWriter writer;
219 |
220 | public ConnectThread(BluetoothDevice device) {
221 | mDevice = device;
222 | canRecv = true;
223 | }
224 |
225 | @Override
226 | public void run() {
227 | if (mDevice != null) {
228 | try {
229 | //获取套接字
230 | BluetoothSocket temp = mDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString(BT_UUID));
231 | //mDevice.createRfcommSocketToServiceRecord(UUID.fromString(BT_UUID));//sdk 2.3以下使用
232 | mSocket = temp;
233 | //发起连接请求
234 | if (mSocket != null) {
235 | mSocket.connect();
236 | }
237 | sendHandlerMsg("连接 " + mDevice.getName() + "成功!");
238 | //获取输入输出流
239 | btIs = mSocket.getInputStream();
240 | btOs = mSocket.getOutputStream();
241 |
242 | //通讯-接收消息
243 | BufferedReader reader = new BufferedReader(new InputStreamReader(btIs, "UTF-8"));
244 | String content = null;
245 | while (canRecv) {
246 | content = reader.readLine();
247 | sendHandlerMsg("收到消息:" + content);
248 | addMessage("收到消息:" + content);
249 | }
250 |
251 |
252 | } catch (IOException e) {
253 | e.printStackTrace();
254 | sendHandlerMsg("错误:" + e.getMessage());
255 | } finally {
256 | try {
257 | if (mSocket != null) {
258 | mSocket.close();
259 | }
260 | //btIs.close();//两个输出流都依赖socket,关闭socket即可
261 | //btOs.close();
262 | } catch (IOException e) {
263 | e.printStackTrace();
264 | sendHandlerMsg("错误:" + e.getMessage());
265 | }
266 | }
267 | }
268 | }
269 |
270 | private void sendHandlerMsg(String content) {
271 | Message msg = mHandler.obtainMessage();
272 | msg.what = 1001;
273 | msg.obj = content;
274 | mHandler.sendMessage(msg);
275 | }
276 |
277 | public void write(String msg) {
278 | if (btOs != null) {
279 | try {
280 | if (writer == null) {
281 | writer = new PrintWriter(new OutputStreamWriter(btOs, "UTF-8"), true);
282 | }
283 | writer.println(msg);
284 | } catch (UnsupportedEncodingException e) {
285 | e.printStackTrace();
286 | writer.close();
287 | sendHandlerMsg("错误:" + e.getMessage());
288 | }
289 | }
290 | }
291 | }
292 |
293 | class AcceptThread extends Thread {
294 | private BluetoothServerSocket mServerSocket;
295 | private BluetoothSocket mSocket;
296 | private InputStream btIs;
297 | private OutputStream btOs;
298 | private PrintWriter writer;
299 | private boolean canAccept;
300 | private boolean canRecv;
301 |
302 | public AcceptThread() {
303 | canAccept = true;
304 | canRecv = true;
305 | }
306 |
307 | @Override
308 | public void run() {
309 | try {
310 | //获取套接字
311 | BluetoothServerSocket temp = mBluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("TEST", UUID.fromString(BT_UUID));
312 | mServerSocket = temp;
313 | //监听连接请求 -- 作为测试,只允许连接一个设备
314 | if (mServerSocket != null) {
315 | // while (canAccept) {
316 | mSocket = mServerSocket.accept();
317 | sendHandlerMsg("有客户端连接");
318 | // }
319 | }
320 | //获取输入输出流
321 | btIs = mSocket.getInputStream();
322 | btOs = mSocket.getOutputStream();
323 | //通讯-接收消息
324 | BufferedReader reader = new BufferedReader(new InputStreamReader(btIs, "UTF-8"));
325 | String content = null;
326 | while (canRecv) {
327 | content = reader.readLine();
328 | sendHandlerMsg("收到消息:" + content);
329 | }
330 | } catch (IOException e) {
331 | e.printStackTrace();
332 | } finally {
333 | try {
334 | if (mSocket != null) {
335 | mSocket.close();
336 | }
337 | } catch (IOException e) {
338 | e.printStackTrace();
339 | sendHandlerMsg("错误:" + e.getMessage());
340 | }
341 | }
342 | }
343 |
344 | private void sendHandlerMsg(String content) {
345 | Message msg = mHandler.obtainMessage();
346 | msg.what = 1001;
347 | msg.obj = content;
348 | mHandler.sendMessage(msg);
349 | }
350 |
351 | public void write(String msg) {
352 | if (btOs != null) {
353 | try {
354 | if (writer == null) {
355 | writer = new PrintWriter(new OutputStreamWriter(btOs, "UTF-8"), true);
356 | }
357 | writer.println(msg);
358 | } catch (UnsupportedEncodingException e) {
359 | e.printStackTrace();
360 | writer.close();
361 | sendHandlerMsg("错误:" + e.getMessage());
362 | }
363 | }
364 | }
365 | }
366 |
367 | public void addMessage(String msg){
368 | msglist.add(msg);
369 | ArrayAdapter adapter = new ArrayAdapter(
370 | getActivity(),android.R.layout.simple_list_item_1,msglist
371 | );
372 | listView_msg.setAdapter(adapter);
373 | listView_msg.setSelection(adapter.getCount() - 1);
374 | }
375 |
376 | public void addDevice(BluetoothDevice device){
377 | devicelist.add(device);
378 | devices.add(device.getName());
379 | ArrayAdapter adapter = new ArrayAdapter(
380 | getActivity(),android.R.layout.simple_list_item_1,devices
381 | );
382 | listView_device.setAdapter(adapter);
383 | }
384 |
385 | public void clearDevices(){
386 | if(devicelist!=null) {
387 | devicelist.clear();
388 | devices.clear();
389 | }
390 | ArrayAdapter adapter = new ArrayAdapter(
391 | getActivity(),android.R.layout.simple_list_item_1,devices
392 | );
393 | listView_device.setAdapter(adapter);
394 | }
395 | }
396 |
--------------------------------------------------------------------------------