Commit 079dd022 authored by LinhNP's avatar LinhNP

update code

parent 7cb851c0
cmake_minimum_required(VERSION 3.4.1)
project("myapplicationnativec")
message(${CMAKE_PROJECT_NAME} ryu)
add_library(${CMAKE_PROJECT_NAME} SHARED
../native_add.cpp
# ../src/utils.h
# ../src/utils.cpp
# ../src/detector/nudedetector.h
# ../src/detector/nudedetector.cpp
# ../src/detector/enginebase.h
# ../src/detector/enginebase.cpp
)
#add_library(${CMAKE_PROJECT_NAME}
# SHARED
# IMPORTED )
#
#set_target_properties(${CMAKE_PROJECT_NAME}
# PROPERTIES IMPORTED_LOCATION
#
# app/src/main/jniLibs/arm64-v8a/libonnxruntime.so
#)
include_directories(
# "/home/thangdm/Software/opencv-4.9.0-android-sdk/OpenCV-android-sdk/sdk/native/jni/include/"
# "/home/thangdm/Software/onnxruntime-android-1.17.1/headers/"
)
target_link_directories( ${CMAKE_PROJECT_NAME} PUBLIC
# "/home/thangdm/Projects/Qt/AIMobileLib/build-AIMobileLib-Android_Qt_6_6_2_Clang_arm64_v8a-Release/"
)
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
# /home/thangdm/Projects/Android/flutter_ffi/android/app/src/main/jniLibs/arm64-v8a/libQt6Core_arm64-v8a.so
# /home/thangdm/Projects/Android/flutter_ffi/android/app/src/main/jniLibs/arm64-v8a/libQt6Gui_arm64-v8a.so
# /home/thangdm/Projects/Android/flutter_ffi/android/app/src/main/jniLibs/arm64-v8a/libonnxruntime.so
# /home/thangdm/Projects/Android/flutter_ffi/android/app/src/main/jniLibs/arm64-v8a/libopencv_java4.so
# # /home/thangdm/Qt/6.6.2/android_arm64_v8a/lib/libQt6Gui_arm64-v8a.so
# /home/thangdm/Projects/Android/flutter_ffi/android/app/src/main/jniLibs/arm64-v8a/libAIMobileLib_arm64-v8a.so
log)
\ No newline at end of file
# Uncomment this line to define a global platform for your project # Uncomment this line to define a global platform for your project
platform :ios, '17.4' platform :ios, '12'
use_frameworks! use_frameworks!
# CocoaPods analytics sends network stats synchronously affecting flutter build latency. # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
......
...@@ -24,6 +24,6 @@ SPEC CHECKSUMS: ...@@ -24,6 +24,6 @@ SPEC CHECKSUMS:
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
PODFILE CHECKSUM: 44a20dcded4fc328b465643033e4019d5a4e09ba PODFILE CHECKSUM: fe994e98d2939c49e37e478d3d4af64fe1d68cf8
COCOAPODS: 1.15.2 COCOAPODS: 1.15.2
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
...@@ -10,15 +10,16 @@ import UIKit ...@@ -10,15 +10,16 @@ import UIKit
_ application: UIApplication, _ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool { ) -> Bool {
print("Starting didFinishLaunchingWithOptions method...")
if let filePath = Bundle.main.path(forResource: "nudenet", ofType: "onnx") { if let filePath = Bundle.main.path(forResource: "nudenet", ofType: "onnx") {
print(filePath) print(filePath)
if let imgPath = Bundle.main.path(forResource: "lisa1", ofType: "jpg") { if let imgPath = Bundle.main.path(forResource: "david", ofType: "jpg") {
print(imgPath) print(imgPath)
// Tạo đường dẫn mới cho ảnh được lưu trong thư mục Documents // Tạo đường dẫn mới cho ảnh được lưu trong thư mục Documents
if var documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first { if var documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
documentsPath = documentsPath + "/lisa_rap.jpg"; documentsPath = documentsPath + "/porn.jpg";
callInitEngine(filePath, imgPath, documentsPath) callInitEngine(filePath, imgPath, documentsPath)
...@@ -27,7 +28,7 @@ import UIKit ...@@ -27,7 +28,7 @@ import UIKit
} }
if let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first { if let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
let imagePath = (documentsPath as NSString).appendingPathComponent("lisa_rap.jpg") let imagePath = (documentsPath as NSString).appendingPathComponent("porn.jpg")
if let image = UIImage(contentsOfFile: imagePath) { if let image = UIImage(contentsOfFile: imagePath) {
// Đã đọc thành công ảnh từ tệp // Đã đọc thành công ảnh từ tệp
...@@ -46,21 +47,22 @@ import UIKit ...@@ -46,21 +47,22 @@ import UIKit
} }
// create method get document path from swift
let controller = window?.rootViewController as! FlutterViewController let controller = window?.rootViewController as! FlutterViewController
let channel = FlutterMethodChannel(name: "com.example.app/native", binaryMessenger: controller.binaryMessenger) let channelVersion = FlutterMethodChannel(name: "native_method_chanel",
binaryMessenger: controller.binaryMessenger)
channel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in channelVersion.setMethodCallHandler({(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "getAssetFilePath" { if call.method == "document_path" {
self.getAssetFilePath(result: result) if let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
} else { // let imagePath = (documentsPath as NSString).appendingPathComponent("porn.jpg")
result(FlutterMethodNotImplemented) result(documentsPath)
} }
} }
// readAssetFile(result: <#T##FlutterResult##FlutterResult##(Any?) -> Void#>) })
print("Starting didFinishLaunchingWithOptions method...")
let result = super.application(application, didFinishLaunchingWithOptions: launchOptions) let result = super.application(application, didFinishLaunchingWithOptions: launchOptions)
print("Finishing didFinishLaunchingWithOptions method...") print("Finishing didFinishLaunchingWithOptions method...")
return result return result
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string> <string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
...@@ -24,6 +26,8 @@ ...@@ -24,6 +26,8 @@
<string>$(FLUTTER_BUILD_NUMBER)</string> <string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIMainStoryboardFile</key> <key>UIMainStoryboardFile</key>
...@@ -41,9 +45,5 @@ ...@@ -41,9 +45,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict> </dict>
</plist> </plist>
...@@ -55,12 +55,10 @@ void init_engine(const char* modelPath, const char* imgPath, const char* documen ...@@ -55,12 +55,10 @@ void init_engine(const char* modelPath, const char* imgPath, const char* documen
cv::Mat nudeImage = cv::imread(imgPath); cv::Mat nudeImage = cv::imread(imgPath);
//drawing
cv::Mat drawing = nudeImage.clone();
LOG_C("documentsPath: " <<documentsPath); LOG_C("documentsPath: " <<documentsPath);
cv::imwrite(documentsPath, drawing); // cv::imwrite(documentsPath, drawing);
auto firstBlood = CURRENT_MILIS; auto firstBlood = CURRENT_MILIS;
nudeEngine->InferenceEngine(nudeImage, documentsPath); nudeEngine->InferenceEngine(nudeImage, documentsPath);
......
#include <stdint.h>
#include <string>
#include "../c/src/detector/nudedetector.h"
#include <stdio.h>
//#include <onnxruntime/onnxruntime_cxx_api.h>
//#include <opencv2/opencv.hpp>
//#include <android/log.h>
//#define LOGR(x) __android_log_print(ANDROID_LOG_DEBUG, "flutter", x);
extern "C" __attribute__((visibility("default"))) __attribute__((used))
int32_t native_add(int32_t x, int32_t y) {
// LOGR("test from c native_add")
return x+y;
}
extern "C" __attribute__((visibility("default"))) __attribute__((used))
float native_add_floats(float x, float y) {
// LOGR("test from c native_add_floats");
return x + y;
}
extern "C" __attribute__((visibility("default"))) __attribute__((used))
bool native_compare_int(int32_t x, int32_t y) {
// LOGR("test from c native_compare_int");
return x == y;
}
extern "C" __attribute__((visibility("default"))) __attribute__((used))
const wchar_t* native_get_wstring(const wchar_t* input) {
static std::wstring result;
result = input;
result += L" hello world";
return result.c_str();
}
extern "C"
void test() {
printf("hello mon");
}
extern "C" __attribute__((visibility("default"))) __attribute__((used))
void init_engine(const char* modelPath, const char* imgPath, const char* documentsPath) {
NudeDetector *nudeEngine = new NudeDetector;
// nudeEngine->modelPath = "/storage/emulated/0/Models/Yolov8/NudeNet/NudeNet.onnx";
nudeEngine->modelPath = modelPath;
// nudeEngine->modelPath = "/assets/nudenet.onnx";
//"/private/var/containers/Bundle/Application/C3250AEF-83D8-4121-918F-7B8142F91B36/Runner.app/NudeNet.onnx";
nudeEngine->numThread = 1;
nudeEngine->modelShape = cv::Size(320,320);
nudeEngine->inputNodeDims = {1,3,320,320};
nudeEngine->objectThreshold = 0.2;
nudeEngine->InitEngine();
// LOGR("init engine done");
cv::Mat nudeImage = cv::imread(imgPath);
LOG_C("documentsPath: " <<documentsPath);
// cv::imwrite(documentsPath, drawing);
auto firstBlood = CURRENT_MILIS;
nudeEngine->InferenceEngine(nudeImage, documentsPath);
// LOGR("first blood: " + std::to_string(CURRENT_MILIS - firstBlood));
auto start = CURRENT_MILIS;
uint total=0;
// for(uint i=0; i < 100 ; i++){
// nudeEngine->InferenceEngine(nudeImage);
// total += CURRENT_MILIS-start;
// start = CURRENT_MILIS;
// }
// LOGR("average process time: " + std::to_string(total/100) + "ms");
//LOGR("finished")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment