!6283 Add Object detection Android demo project
Merge pull request !6283 from gongdaguo/add_object_detectionpull/6283/MERGE
commit
3c1b8935d7
@ -0,0 +1,83 @@
|
||||
# MindSpore
|
||||
build/
|
||||
app/src/main/cpp/mindspore-lite*
|
||||
app/src/main/assets/model/
|
||||
mindspore/lib
|
||||
output
|
||||
*.ir
|
||||
mindspore/ccsrc/schema/inner/*
|
||||
|
||||
# Cmake files
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
CMakeCache.txt
|
||||
Makefile
|
||||
cmake-build-debug
|
||||
|
||||
# Dynamic libraries
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Static libraries
|
||||
*.la
|
||||
*.lai
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Protocol buffers
|
||||
*_pb2.py
|
||||
*.pb.h
|
||||
*.pb.cc
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
|
||||
# Editor
|
||||
.vscode
|
||||
.idea/
|
||||
|
||||
# Cquery
|
||||
.cquery_cached_index/
|
||||
compile_commands.json
|
||||
|
||||
# Ctags and cscope
|
||||
tags
|
||||
TAGS
|
||||
CTAGS
|
||||
GTAGS
|
||||
GRTAGS
|
||||
GSYMS
|
||||
GPATH
|
||||
cscope.*
|
||||
|
||||
# Python files
|
||||
*__pycache__*
|
||||
.pytest_cache
|
||||
|
||||
# Mac files
|
||||
*.DS_Store
|
||||
|
||||
# Test results
|
||||
test_temp_summary_event_file/
|
||||
*.dot
|
||||
*.dat
|
||||
*.svg
|
||||
*.perf
|
||||
*.info
|
||||
*.ckpt
|
||||
*.shp
|
||||
*.pkl
|
||||
.clangd
|
||||
mindspore/version.py
|
||||
mindspore/default_config.py
|
||||
mindspore/.commit_id
|
||||
onnx.proto
|
||||
mindspore/ccsrc/onnx.proto
|
||||
|
||||
# Android
|
||||
local.properties
|
||||
.gradle
|
||||
sdk/build
|
||||
sdk/.cxx
|
||||
app/.cxx
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
||||
/build
|
||||
/libs
|
||||
/src/main/cpp/include/
|
@ -0,0 +1,82 @@
|
||||
# For more information about using CMake with Android Studio, read the
|
||||
# documentation: https://d.android.com/studio/projects/add-native-code.html
|
||||
|
||||
# Sets the minimum version of CMake required to build the native library.
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI})
|
||||
|
||||
set(MINDSPORELITE_VERSION mindspore-lite-0.7.0-minddata-arm64-cpu)
|
||||
|
||||
# ============== Set MindSpore Dependencies. =============
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/third_party/flatbuffers/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION})
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include/ir/dtype)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/include/schema)
|
||||
|
||||
#include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include/ModelUtil)
|
||||
|
||||
add_library(mindspore-lite SHARED IMPORTED )
|
||||
add_library(minddata-lite SHARED IMPORTED )
|
||||
|
||||
set_target_properties(mindspore-lite PROPERTIES IMPORTED_LOCATION
|
||||
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libmindspore-lite.so)
|
||||
set_target_properties(minddata-lite PROPERTIES IMPORTED_LOCATION
|
||||
${CMAKE_SOURCE_DIR}/src/main/cpp/${MINDSPORELITE_VERSION}/lib/libminddata-lite.so)
|
||||
# --------------- MindSpore Lite set End. --------------------
|
||||
|
||||
# Creates and names a library, sets it as either STATIC
|
||||
# or SHARED, and provides the relative paths to its source code.
|
||||
# You can define multiple libraries, and CMake builds them for you.
|
||||
# Gradle automatically packages shared libraries with your APK.
|
||||
|
||||
file(GLOB_RECURSE cpp_src "src/main/cpp/*.cpp" "src/main/cpp/*.h")
|
||||
|
||||
add_library( # Sets the name of the library.
|
||||
mlkit-label-MS
|
||||
|
||||
# Sets the library as a shared library.
|
||||
SHARED
|
||||
|
||||
# Provides a relative path to your source file(s).
|
||||
${cpp_src})
|
||||
|
||||
|
||||
# Searches for a specified prebuilt library and stores the path as a
|
||||
# variable. Because CMake includes system libraries in the search path by
|
||||
# default, you only need to specify the name of the public NDK library
|
||||
# you want to add. CMake verifies that the library exists before
|
||||
# completing its build.
|
||||
|
||||
find_library( # Sets the name of the path variable.
|
||||
log-lib
|
||||
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
log )
|
||||
|
||||
|
||||
find_library( jnigraphics-lib jnig·raphics )
|
||||
|
||||
# Specifies libraries CMake should link to your target library. You
|
||||
# can link multiple libraries, such as libraries you define in this
|
||||
# build script, prebuilt third-party libraries, or system libraries.
|
||||
add_definitions(-DMNN_USE_LOGCAT)
|
||||
target_link_libraries( # Specifies the target library.
|
||||
mlkit-label-MS
|
||||
|
||||
# --- mindspore ---
|
||||
minddata-lite
|
||||
mindspore-lite
|
||||
|
||||
# --- other dependencies.---
|
||||
-ljnigraphics
|
||||
android
|
||||
|
||||
# Links the target library to the log library
|
||||
${log-lib}
|
||||
)
|
@ -0,0 +1,61 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
// Before gradle build.
|
||||
// To download some necessary libraries.
|
||||
apply from:'download.gradle'
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.1"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.mindspore.hiobject"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DANDROID_STL=c++_shared"
|
||||
cppFlags ""
|
||||
}
|
||||
}
|
||||
ndk {
|
||||
//abiFilters 'arm64-v8a', 'armeabi-v7a'
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
aaptOptions {
|
||||
// noCompress '.so', ".tflite", ".mnn", ".cambricon", '.mslite', 'om', 'ms'
|
||||
noCompress '.so', 'ms'
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
customDebugType {
|
||||
debuggable true
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path file('CMakeLists.txt')
|
||||
}
|
||||
}
|
||||
ndkVersion '21.3.6528147'
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* To download necessary library from HuaWei server.
|
||||
* Including mindspore-lite .so file, minddata-lite .so file and model file.
|
||||
* The libraries can be downloaded manually.
|
||||
*/
|
||||
def targetMindSporeInclude = "src/main/cpp/"
|
||||
def mindsporeLite_Version = "mindspore-lite-0.7.0-minddata-arm64-cpu"
|
||||
|
||||
def targetModelFile = "src/main/assets/model/ssd.ms"
|
||||
def mindSporeLibrary_arm64 = "src/main/cpp/${mindsporeLite_Version}.tar.gz"
|
||||
|
||||
def modelDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/ssd_mobilenetv2_lite/ssd.ms"
|
||||
def mindsporeLiteDownloadUrl = "https://download.mindspore.cn/model_zoo/official/lite/lib/mindspore%20version%201.0/${mindsporeLite_Version}.tar.gz"
|
||||
|
||||
def cleantargetMindSporeInclude = "src/main/cpp"
|
||||
|
||||
task cleanCmakeCache(type: Delete) {
|
||||
delete '.cxx/cmake/debug'
|
||||
delete '.cxx/cmake/release'
|
||||
}
|
||||
|
||||
task downloadModelFile(type: DownloadUrlTask) {
|
||||
doFirst {
|
||||
println "Downloading ${modelDownloadUrl}"
|
||||
}
|
||||
sourceUrl = "${modelDownloadUrl}"
|
||||
target = file("${targetModelFile}")
|
||||
}
|
||||
|
||||
task downloadMindSporeLibrary(type: DownloadUrlTask) {
|
||||
doFirst {
|
||||
println "Downloading ${mindsporeLiteDownloadUrl}"
|
||||
}
|
||||
sourceUrl = "${mindsporeLiteDownloadUrl}"
|
||||
target = file("${mindSporeLibrary_arm64}")
|
||||
}
|
||||
|
||||
task unzipMindSporeInclude(type: Copy, dependsOn: 'downloadMindSporeLibrary') {
|
||||
doFirst {
|
||||
println "Unzipping ${mindSporeLibrary_arm64}"
|
||||
}
|
||||
from tarTree(resources.gzip("${mindSporeLibrary_arm64}"))
|
||||
into "${targetMindSporeInclude}"
|
||||
}
|
||||
|
||||
task cleanUnusedmindsporeFiles(type: Delete, dependsOn: ['unzipMindSporeInclude']) {
|
||||
delete fileTree("${cleantargetMindSporeInclude}").matching {
|
||||
include "*.tar.gz"
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Using preBuild to download mindspore library and model file.
|
||||
* Run before gradle build.
|
||||
*/
|
||||
if (file("src/main/cpp/${mindsporeLite_Version}/lib/libmindspore-lite.so").exists()){
|
||||
downloadMindSporeLibrary.enabled = false
|
||||
unzipMindSporeInclude.enabled = false
|
||||
cleanUnusedmindsporeFiles.enabled = false
|
||||
}
|
||||
|
||||
if (file("src/main/assets/model/ssd.ms").exists()){
|
||||
downloadModelFile.enabled = false
|
||||
}
|
||||
|
||||
preBuild.dependsOn cleanCmakeCache
|
||||
preBuild.dependsOn downloadModelFile
|
||||
preBuild.dependsOn downloadMindSporeLibrary
|
||||
preBuild.dependsOn unzipMindSporeInclude
|
||||
preBuild.dependsOn cleanUnusedmindsporeFiles
|
||||
|
||||
class DownloadUrlTask extends DefaultTask {
|
||||
@Input
|
||||
String sourceUrl
|
||||
|
||||
@OutputFile
|
||||
File target
|
||||
|
||||
@TaskAction
|
||||
void download() {
|
||||
ant.get(src: sourceUrl, dest: target)
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -0,0 +1,26 @@
|
||||
package com.mindspore.hiobject;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.huawei.himindsporedemo", appContext.getPackageName());
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mindspore.hiobject"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEM" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
|
||||
<application
|
||||
android:requestLegacyExternalStorage = "true"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.mindspore.hiobject.objectdetect.DealDataActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar"/>
|
||||
<activity
|
||||
android:name="com.mindspore.hiobject.objectdetect.PhotoActivity"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar"/>
|
||||
<activity
|
||||
android:name="com.mindspore.hiobject.objectdetect.CameraActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar"/>
|
||||
<activity
|
||||
android:name="com.mindspore.hiobject.SplashActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MSNetWork.h"
|
||||
#include <android/log.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "include/errorcode.h"
|
||||
|
||||
#define MS_PRINT(format, ...) __android_log_print(ANDROID_LOG_INFO, "MSJNI", format, ##__VA_ARGS__)
|
||||
|
||||
MSNetWork::MSNetWork(void) : session_(nullptr) {}
|
||||
|
||||
MSNetWork::~MSNetWork(void) {}
|
||||
|
||||
void
|
||||
MSNetWork::CreateSessionMS(char *modelBuffer, size_t bufferLen, mindspore::lite::Context *ctx) {
|
||||
session_ = mindspore::session::LiteSession::CreateSession(ctx);
|
||||
if (session_ == nullptr) {
|
||||
MS_PRINT("Create Session failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Compile model.
|
||||
auto model = mindspore::lite::Model::Import(modelBuffer, bufferLen);
|
||||
if (model == nullptr) {
|
||||
MS_PRINT("Import model failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = session_->CompileGraph(model);
|
||||
if (ret != mindspore::lite::RET_OK) {
|
||||
MS_PRINT("CompileGraph failed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int MSNetWork::ReleaseNets(void) {
|
||||
delete session_;
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MSNETWORK_H
|
||||
#define MSNETWORK_H
|
||||
|
||||
#include <context.h>
|
||||
#include <lite_session.h>
|
||||
#include <model.h>
|
||||
#include <errorcode.h>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
struct ImgDims {
|
||||
int channel = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
/*struct SessIterm {
|
||||
std::shared_ptr<mindspore::session::LiteSession> sess = nullptr;
|
||||
};*/
|
||||
|
||||
class MSNetWork {
|
||||
public:
|
||||
MSNetWork();
|
||||
|
||||
~MSNetWork();
|
||||
|
||||
void CreateSessionMS(char *modelBuffer, size_t bufferLen, mindspore::lite::Context *ctx);
|
||||
|
||||
int ReleaseNets(void);
|
||||
|
||||
mindspore::session::LiteSession * session() const { return session_; }
|
||||
private:
|
||||
mindspore::session::LiteSession *session_;
|
||||
};
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,202 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HIMINDSPOREDEMO_SSD_UTIL_H
|
||||
#define HIMINDSPOREDEMO_SSD_UTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class SSDModelUtil {
|
||||
public:
|
||||
// Constructor.
|
||||
SSDModelUtil(int srcImageWidth, int srcImgHeight);
|
||||
|
||||
/**
|
||||
* Return the SSD model post-processing result.
|
||||
* @param branchScores
|
||||
* @param branchBoxData
|
||||
* @return
|
||||
*/
|
||||
std::string getDecodeResult(float *branchScores, float *branchBoxData);
|
||||
|
||||
// ============= variables =============.
|
||||
int inputImageHeight;
|
||||
int inputImageWidth;
|
||||
|
||||
struct NormalBox {
|
||||
float y;
|
||||
float x;
|
||||
float h;
|
||||
float w;
|
||||
};
|
||||
|
||||
struct YXBoxes {
|
||||
float ymin;
|
||||
float xmin;
|
||||
float ymax;
|
||||
float xmax;
|
||||
};
|
||||
|
||||
struct Product {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct WHBox {
|
||||
float boxw;
|
||||
float boxh;
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<struct NormalBox> mDefaultBoxes;
|
||||
|
||||
|
||||
void getDefaultBoxes();
|
||||
|
||||
void ssd_boxes_decode(const NormalBox *boxes,
|
||||
YXBoxes *const decoded_boxes,
|
||||
const float scale0 = 0.1, const float scale1 = 0.2,
|
||||
const int count = 1917);
|
||||
|
||||
void nonMaximumSuppression(const YXBoxes *const decoded_boxes, const float *const scores,
|
||||
const std::vector<int> &in_indexes, std::vector<int> *out_indexes_p,
|
||||
const float nmsThreshold = 0.6,
|
||||
const int count = 1917, const int max_results = 100);
|
||||
|
||||
double IOU(float r1[4], float r2[4]);
|
||||
|
||||
|
||||
// ============= variables =============.
|
||||
struct network {
|
||||
int model_input_height = 300;
|
||||
int model_input_width = 300;
|
||||
|
||||
int num_default[6] = {3, 6, 6, 6, 6, 6};
|
||||
int feature_size[6] = {19, 10, 5, 3, 2, 1};
|
||||
double min_scale = 0.2;
|
||||
float max_scale = 0.95;
|
||||
float steps[6] = {16, 32, 64, 100, 150, 300};
|
||||
float prior_scaling[2] = {0.1, 0.2};
|
||||
float gamma = 2.0;
|
||||
float alpha = 0.75;
|
||||
int aspect_ratios[6][2] = {{2, 0},
|
||||
{2, 3},
|
||||
{2, 3},
|
||||
{2, 3},
|
||||
{2, 3},
|
||||
{2, 3}};
|
||||
} config;
|
||||
|
||||
float g_thres_map[81] = {0, 0.635, 0.627, 0.589, 0.585, 0.648, 0.664, 0.655,
|
||||
0.481, 0.529, 0.611, 0.641, 0.774, 0.549, 0.513, 0.652,
|
||||
0.552, 0.590, 0.650, 0.575, 0.583, 0.650, 0.656, 0.696,
|
||||
0.653, 0.438, 0.515, 0.459, 0.561, 0.545, 0.635, 0.540,
|
||||
0.560, 0.721, 0.544, 0.548, 0.511, 0.611, 0.592, 0.542,
|
||||
0.512, 0.635, 0.531, 0.437, 0.525, 0.445, 0.484, 0.546,
|
||||
0.490, 0.581, 0.566, 0.516, 0.445, 0.541, 0.613, 0.560,
|
||||
0.483, 0.509, 0.464, 0.543, 0.538, 0.490, 0.576, 0.617,
|
||||
0.577, 0.595, 0.640, 0.585, 0.598, 0.592, 0.514, 0.397,
|
||||
0.592, 0.504, 0.548, 0.642, 0.581, 0.497, 0.545, 0.154,
|
||||
0.580,
|
||||
};
|
||||
|
||||
std::string label_classes[81] = {
|
||||
{"background"},
|
||||
{"human"},
|
||||
{"bike"},
|
||||
{"automobile"},
|
||||
{"motorbike"},
|
||||
{"aircraft"},
|
||||
{"motorbus"},
|
||||
{"train"},
|
||||
{"motortruck"},
|
||||
{"boat"},
|
||||
{"traffic signal"},
|
||||
{"fireplug"},
|
||||
{"stop sign"},
|
||||
{"parking meter"},
|
||||
{"seat"},
|
||||
{"bird"},
|
||||
{"cat"},
|
||||
{"dog"},
|
||||
{"horse"},
|
||||
{"sheep"},
|
||||
{"cow"},
|
||||
{"elephant"},
|
||||
{"bear"},
|
||||
{"zebra"},
|
||||
{"giraffe"},
|
||||
{"knapsack"},
|
||||
{"bumbershoot"},
|
||||
{"purse"},
|
||||
{"neckwear"},
|
||||
{"traveling bag"},
|
||||
{"frisbee"},
|
||||
{"skis"},
|
||||
{"snowboard"},
|
||||
{"sports ball"},
|
||||
{"kite"},
|
||||
{"baseball bat"},
|
||||
{"baseball glove"},
|
||||
{"skateboard"},
|
||||
{"surfboard"},
|
||||
{"tennis racket"},
|
||||
{"bottle"},
|
||||
{"wine glass"},
|
||||
{"cup"},
|
||||
{"fork"},
|
||||
{"knife"},
|
||||
{"spoon"},
|
||||
{"bowl"},
|
||||
{"banana"},
|
||||
{"apple"},
|
||||
{"sandwich"},
|
||||
{"orange"},
|
||||
{"broccoli"},
|
||||
{"carrot"},
|
||||
{"hot dog"},
|
||||
{"pizza"},
|
||||
{"donut"},
|
||||
{"cake"},
|
||||
{"chair"},
|
||||
{"couch"},
|
||||
{"houseplant"},
|
||||
{"bed"},
|
||||
{"dinner table"},
|
||||
{"toilet"},
|
||||
{"television"},
|
||||
{"notebook computer"},
|
||||
{"mouse"},
|
||||
{"remote"},
|
||||
{"keyboard"},
|
||||
{"smartphone"},
|
||||
{"microwave"},
|
||||
{"oven"},
|
||||
{"toaster"},
|
||||
{"water sink"},
|
||||
{"fridge"},
|
||||
{"book"},
|
||||
{"bell"},
|
||||
{"vase"},
|
||||
{"shears"},
|
||||
{"toy bear"},
|
||||
{"hair drier"},
|
||||
{"toothbrush"}
|
||||
};
|
||||
};
|
||||
#endif
|
@ -0,0 +1,95 @@
|
||||
package com.mindspore.hiobject;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.mindspore.hiobject.objectdetect.CameraActivity;
|
||||
import com.mindspore.hiobject.objectdetect.DealDataActivity;
|
||||
import com.mindspore.hiobject.objectdetect.PhotoActivity;
|
||||
|
||||
public class SplashActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
private static final int RC_CHOOSE_PHOTO = 1;
|
||||
private static final int REQUEST_CAMERA_PERMISSION = 2;
|
||||
|
||||
private Button btnPhoto, btnCamera, btnDealData;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
btnPhoto = findViewById(R.id.btn_photo);
|
||||
btnCamera = findViewById(R.id.btn_camera);
|
||||
btnDealData = findViewById(R.id.btn_deal);
|
||||
btnDealData.setVisibility(View.GONE);
|
||||
|
||||
btnPhoto.setOnClickListener(this);
|
||||
btnCamera.setOnClickListener(this);
|
||||
btnDealData.setOnClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (R.id.btn_photo == view.getId()) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_PHONE_STATE}, RC_CHOOSE_PHOTO);
|
||||
} else if (R.id.btn_camera == view.getId()) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
|
||||
|
||||
} else if (R.id.btn_deal == view.getId()) {
|
||||
Intent intent = new Intent(SplashActivity.this, DealDataActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限申请结果回调
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (RC_CHOOSE_PHOTO == requestCode) {
|
||||
choosePhoto();
|
||||
} else if (REQUEST_CAMERA_PERMISSION == requestCode) {
|
||||
chooseCamera();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void choosePhoto() {
|
||||
Intent intentToPickPic = new Intent(Intent.ACTION_PICK, null);
|
||||
intentToPickPic.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
|
||||
startActivityForResult(intentToPickPic, RC_CHOOSE_PHOTO);
|
||||
}
|
||||
|
||||
private void chooseCamera() {
|
||||
Intent intent = new Intent(SplashActivity.this, CameraActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (RC_CHOOSE_PHOTO == requestCode && null != data && null != data.getData()) {
|
||||
Intent intent = new Intent(SplashActivity.this, PhotoActivity.class);
|
||||
intent.setData(data.getData());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,159 @@
|
||||
package com.mindspore.hiobject.help;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecognitionObjectBean {
|
||||
private String rectID;
|
||||
private String imgID;
|
||||
private String objectName;
|
||||
private float score;
|
||||
private float left;
|
||||
private float top;
|
||||
private float right;
|
||||
private float bottom;
|
||||
|
||||
private RecognitionObjectBean(Builder builder){
|
||||
this.rectID = builder.rectID;
|
||||
this.imgID = builder.imgID;
|
||||
this.objectName = builder.objectName;
|
||||
this.score = builder.score;
|
||||
this.left = builder.left;
|
||||
this.top = builder.top;
|
||||
this.right = builder.right;
|
||||
this.bottom = builder.bottom;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private String rectID;
|
||||
private String imgID;
|
||||
private String objectName;
|
||||
private float score;
|
||||
private float left;
|
||||
private float top;
|
||||
private float right;
|
||||
private float bottom;
|
||||
|
||||
public RecognitionObjectBean build(){
|
||||
return new RecognitionObjectBean(this);
|
||||
}
|
||||
|
||||
public Builder setRectID(String rectID) {
|
||||
this.rectID = rectID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setImgID(String imgID) {
|
||||
this.imgID = imgID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setObjectName(String objectName) {
|
||||
this.objectName = objectName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setScore(float score) {
|
||||
this.score = score;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLeft(float left) {
|
||||
this.left = left;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTop(float top) {
|
||||
this.top = top;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRight(float right) {
|
||||
this.right = right;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBottom(float bottom) {
|
||||
this.bottom = bottom;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getImgID() {
|
||||
return imgID;
|
||||
}
|
||||
|
||||
public String getRectID() {
|
||||
return rectID;
|
||||
}
|
||||
|
||||
public String getObjectName() {
|
||||
return objectName;
|
||||
}
|
||||
|
||||
public float getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public float getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public float getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public float getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public float getBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
|
||||
public static List<RecognitionObjectBean> getRecognitionList(String result) {
|
||||
if (!TextUtils.isEmpty(result)) {
|
||||
String[] resultArray = result.split(";");
|
||||
List<RecognitionObjectBean> list = new ArrayList<>();
|
||||
for (int i = 0; i < resultArray.length; i++) {
|
||||
String singleRecognitionResult = resultArray[i];
|
||||
String[] singleResult = singleRecognitionResult.split("_");
|
||||
RecognitionObjectBean bean = new RecognitionObjectBean.Builder()
|
||||
.setRectID(String.valueOf(i + 1))
|
||||
.setImgID(null != getData(0, singleResult) ? getData(0, singleResult) : "")
|
||||
.setObjectName(null != getData(1, singleResult) ? getData(1, singleResult) : "")
|
||||
.setScore(null != getData(2, singleResult) ? Float.parseFloat(getData(2, singleResult)) : 0)
|
||||
.setLeft(null != getData(3, singleResult) ? Float.parseFloat(getData(3, singleResult)) : 0)
|
||||
.setTop(null != getData(4, singleResult) ? Float.parseFloat(getData(4, singleResult)) : 0)
|
||||
.setRight(null != getData(5, singleResult) ? Float.parseFloat(getData(5, singleResult)) : 0)
|
||||
.setBottom(null != getData(6, singleResult) ? Float.parseFloat(getData(6, singleResult)) : 0)
|
||||
.build();
|
||||
list.add(bean);
|
||||
}
|
||||
return list;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @param singleResult
|
||||
* @return
|
||||
*/
|
||||
private static String getData(int index, String[] singleResult) {
|
||||
if (index > singleResult.length) {
|
||||
return null;
|
||||
} else {
|
||||
if (!TextUtils.isEmpty(singleResult[index])) {
|
||||
return singleResult[index];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue