Commit f8b12d09 authored by 14699's avatar 14699

add:腾讯人脸SDK接入

parent 8490cbb9
......@@ -15,6 +15,8 @@ yarn-error.log*
*.ntvs*
*.njsproj
*.sln
plugins/cordova-plugin-hand-tencentface/src/ios/SDKExport/Libs/TuringShieldCamRisk.framework
plugins/cordova-plugin-hand-tencentface/src/ios/SDKExport/Libs/TencentCloudHuiyanSDKFace.framework
*~
*.sw[mnpcod]
......
......@@ -115,4 +115,5 @@
<preference name="xwalkCommandLine" value="--disable-pull-to-refresh-effect" />
<preference name="xwalkMode" value="embedded" />
<preference name="xwalkMultipleApk" value="true" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
</widget>
......@@ -37,6 +37,9 @@
"cordova-plugin-file-transfer": {
"PACKAGE_NAME": "com.xcmg.app"
},
"cordova-plugin-hand-tencentface": {
"PACKAGE_NAME": "com.xcmg.app"
},
"cordova-plugin-hrms-faceidentify": {
"PACKAGE_NAME": "com.xcmg.app"
},
......
#Name:tecentface
-----------
### ID: cordova-plugin-hand-tecentface
### Version: 0.2.0
### Platform: Android;iOS
-----------------
说明:
## 安装
<pre><code>
cordova plugin add Your_Plugin_Path
</code></pre>
## 接口列表
### Tecentface.prototype.startWbFaceVerifySdk = function (successCallback, errorCallback, options)
说明:开启人脸检测
参数:
* successCallback:function 成功回调
* errorCallback: function 失败回调
* options: object 参数结构体
返回值
* 发票数据在data中,为JSON数组转的字符串,
* errCode为0时跳用成功
Example:
<pre><code>
var test = {
// 以下是必须的参数
"openApiAppId":"1",
"keyLicence":"1",
"faceId":"1",
"agreementNo":"1",
"openApiAppVersion":"1.0.0",
"openApiNonce":"1",
"openApiAppVersion":"1",
"openApiUserId":"1",
"openApiSign":"1",
// 以下是可选的
"config": {
"customTipsInUpload":"test",
"forceOrientation":true
}
}
Tecentface.startWbFaceVerifySdk(initSuccess, copyError, test)
</code></pre>
返回值:
<pre><code>
{
"errCode":"",
"errStr":""
"data":""
}
</code></pre>
<br/>
## iOS Quirks
sdk 需要iOS 11 以上
<br/>
## Android Quirks
\ No newline at end of file
{
"name": "cordova-plugin-hand-tencentface",
"version": "0.2.0",
"description": "cordova-plugin-hand-tencentface for cordova plugin",
"cordova": {
"id": "cordova-plugin-hand-tencentface",
"platforms": [
"ios",
"android"
]
},
"keywords": [
"weixinSDK"
],
"engines": [
{
"name": "cordova",
"version": ">=5.0"
}
],
"peerDependencies": {
},
"author": "hand",
"license": "Apache 2.0 License",
"bugs": {
"url": ""
},
"homepage": ""
}
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-hand-tencentface" version="0.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>tencentfaceSDK</name>
<js-module name="Tencentface" src="www/tencentfaceSDK.js">
<clobbers target="Tencentface" />
</js-module>
<!-- android -->
<platform name="android">
<!-- 业务类指定 -->
<config-file target="res/xml/config.xml" parent="/*">
<feature name="tencentfaceCordova">
<param name="android-package" value="com.hand.plugin.cordova.wbcloud.WBCloudFaceLivePlugin"/>
</feature>
</config-file>
<!-- 需要的android权限 -->
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="ANDROID.PERMISSION.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk tools:overrideLibrary="com.tencent.cloud.huiyansdkface.wecamera" />
</config-file>
<!-- 其它配置 -->
<resource-file src="src/android/libs/WbCloudNormal-v5.1.10-4e3e198.aar" target="libs/WbCloudNormal-v5.1.10-4e3e198.aar" />
<resource-file src="src/android/libs/WbCloudFaceLiveSdk-face-v6.1.0-3ca9d59c.aar" target="libs/WbCloudFaceLiveSdk-face-v6.1.0-3ca9d59c.aar" />
<framework src="src/android/tencentface.gradle" custom="true" type="gradleReference" />
<source-file src="src/android/java/WBCloudFaceLivePlugin.java" target-dir="src/com/hand/plugin/cordova/wbcloud/" />
<!-- 混淆文件 -->
<resource-file src="src/android/kyc-cloud-face-consumer-proguard-rules.pro" target="cordova-plugin-hand-tencentface/kyc-cloud-face-consumer-proguard-rules.pro" />
</platform>
<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="tencentfaceCordova">
<param name="ios-package" value="TencentfaceCordova"/>
</feature>
</config-file>
<header-file src="src/ios/TencentfaceCordova.h" target-dir="."/>
<source-file src="src/ios/TencentfaceCordova.m" target-dir="."/>
<header-file src="src/ios/VerifyParameter.h" target-dir="."/>
<source-file src="src/ios/VerifyParameter.m" target-dir="."/>
<!-- <source-file src="src/ios/SDKExport/libWeChatSDK.a" framework="true" /> -->
<!-- <framework src="CoreBluetooth.framework" weak="true"/> -->
<framework src="src/ios/SDKExport/Libs/TencentCloudHuiyanSDKFace.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTCv.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTFaceTrackerLiveness.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/TuringShieldCamRisk.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTFaceAlignmentTinyLiveness.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTPoseDetector.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTFaceDetectorLiveness.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YtSDKKitFrameworkTool.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTCommonLiveness.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/YTFaceLiveReflect.framework" custom="true" />
<framework src="src/ios/SDKExport/Libs/tnnliveness.framework" custom="true" />
<resource-file src="src/ios/SDKExport/Resources/face-tracker-v001.bundle" target="res/face-tracker-v001.bundle" />
<resource-file src="src/ios/SDKExport/Resources/TencentCloudHuiyanSDKFace.bundle" target="res/TencentCloudHuiyanSDKFace.bundle" />
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>亲,我们需要访问您的相机,用于拍摄人脸、身份证等照片</string>
</config-file>
<!--
<config-file target="*-Info.plist" parent="NSContactsUsageDescription">
<string></string>
</config-file>
-->
<!-- <framework src="Security.framework" />
<framework src="CoreTelephony.framework" />
<framework src="SystemConfiguration.framework" />
<framework src="libz.dylib" />
<framework src="libsqlite3.0.dylib" />
<framework src="UIKit.framework" />
<framework src="Foundation.framework" />
<framework src="libc++.dylib" />
<framework src="CFNetwork.framework" /> -->
<framework src="UIKit.framework" />
<framework src="AVFoundation.framework" />
<framework src="CoreVideo.framework" />
<framework src="Security.framework" />
<framework src="SystemConfiguration.framework" />
<framework src="CoreMedia.framework" />
<framework src="VideoToolbox.framework" />
<framework src="CoreTelephony.framework" />
<framework src="ImageIO.framework" />
<framework src="Accelerate.framework" />
<framework src="WebKit.framework" />
<framework src="MediaPlayer.framework" />
<framework src="libz.dylib" />
<framework src="libc++.dylib" />
</platform>
</plugin>
package com.hand.plugin.cordova.wbcloud;
import android.os.Bundle;
import com.google.gson.Gson;
import com.tencent.cloud.huiyansdkface.facelight.api.WbCloudFaceContant;
import com.tencent.cloud.huiyansdkface.facelight.api.WbCloudFaceVerifySdk;
import com.tencent.cloud.huiyansdkface.facelight.api.listeners.WbCloudFaceVerifyLoginListener;
import com.tencent.cloud.huiyansdkface.facelight.api.listeners.WbCloudFaceVerifyResultListener;
import com.tencent.cloud.huiyansdkface.facelight.api.result.WbFaceError;
import com.tencent.cloud.huiyansdkface.facelight.api.result.WbFaceVerifyResult;
import com.tencent.cloud.huiyansdkface.facelight.process.FaceVerifyStatus;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.Iterator;
public class WBCloudFaceLivePlugin extends CordovaPlugin {
private static final String TAG = "WBFaceLivePlugin";
private static final String ACTION_START_WB_FACE_VERIFY_SDK = "startWbFaceVerifySdk";
private static final String CODE_INVALID_ARGUMENT = "CODE_INVALID_ARGUMENT";
private static final String CODE_TASK_ALREADY_RUNNING = "CODE_TASK_ALREADY_RUNNING";
private static final String CODE_SUCCESS = "CODE_SUCCESS";
private static final String CODE_JSON_PARSE_ERROR = "CODE_JSON_PARSE_ERROR";
private static final String CODE_INIT_SDK_FAILED = "CODE_INIT_SDK_FAILED";
private boolean isStarted = false;
private final Gson gson = new Gson();
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext){
if (ACTION_START_WB_FACE_VERIFY_SDK.equals(action)) {
startWbFaceVerifySdk(args, callbackContext);
return true;
}
return false;
}
private JSONObject getResult(String code, String message, JSONObject data) {
JSONObject result = new JSONObject();
try {
result.put("code", code);
result.put("message", message);
if (data != null) {
result.put("data", data);
}
} catch (JSONException ignored) {
}
return result;
}
private JSONObject getResult(String code, String message) {
return getResult(code, message, null);
}
public void startWbFaceVerifySdk(JSONArray argsArray, final CallbackContext jsCallback) {
if (isStarted) {
jsCallback.error(getResult(CODE_TASK_ALREADY_RUNNING, "认证服务已经运行,请不要多次执行"));
return;
}
Bundle data = new Bundle();
// 兼容iOS设计
boolean useAdvanceCompare = true;
try {
JSONObject args = argsArray.getJSONObject(0);
String faceId = args.getString("faceId");
String agreementNo = args.getString("agreementNo");
String openApiAppId = args.getString("openApiAppId");
String openApiAppVersion = args.getString("openApiAppVersion");
String openApiNonce = args.getString("openApiNonce");
String openApiUserId = args.getString("openApiUserId");
String openApiSign = args.getString("openApiSign");
String keyLicence = args.getString("keyLicence");
WbCloudFaceVerifySdk.InputData inputData = new WbCloudFaceVerifySdk.InputData(
faceId,
agreementNo,
openApiAppId,
openApiAppVersion,
openApiNonce,
openApiUserId,
openApiSign,
FaceVerifyStatus.Mode.GRADE,
keyLicence);
data.putSerializable(WbCloudFaceContant.INPUT_DATA, inputData);
JSONObject config = args.getJSONObject("config");
if(config.has("useAdvanceCompare")){
useAdvanceCompare = config.optBoolean("useAdvanceCompare", true);
config.remove("useAdvanceCompare");
}
Iterator<String> keys = config.keys();
while (keys.hasNext()) {
String key = keys.next();
Object value = config.opt(key);
if (value instanceof Serializable) {
data.putSerializable(key, (Serializable) value);
}
}
} catch (JSONException e) {
e.printStackTrace();
JSONObject err = new JSONObject();
try {
err.put("exception", e.toString());
StackTraceElement[] stackTrace = e.getStackTrace();
StringBuilder sb = new StringBuilder();
for (StackTraceElement s : stackTrace) {
sb.append(s.toString()).append("\n");
}
err.put("stacktrace", sb.toString());
} catch (JSONException ignored) {
}
jsCallback.error(getResult(CODE_INVALID_ARGUMENT, "传入参数非法!", err));
return;
}
WbCloudFaceVerifyLoginListener listener = new WbCloudFaceVerifyLoginListener() {
public void onLoginSuccess() {
WbCloudFaceVerifySdk.getInstance().startWbFaceVerifySdk(cordova.getActivity(), new WbCloudFaceVerifyResultListener() {
public void onFinish(WbFaceVerifyResult result) {
isStarted = false;
JSONObject res = null;
try {
String resStr = gson.toJson(result);
res = new JSONObject(resStr);
jsCallback.success(getResult(CODE_SUCCESS, "操作成功", res));
} catch (JSONException e) {
jsCallback.error(getResult(CODE_JSON_PARSE_ERROR, "返回数据过程中Json转换异常: " + e));
}
WbCloudFaceVerifySdk.getInstance().release();
}
});
}
public void onLoginFailed(WbFaceError error) {
isStarted = false;
try {
String errorStr = gson.toJson(error);
JSONObject err = new JSONObject(errorStr);
jsCallback.error(getResult(CODE_INIT_SDK_FAILED, "初始化SDK失败", err));
} catch (JSONException e) {
jsCallback.error(getResult(CODE_JSON_PARSE_ERROR, "SDK初始化失败之后返回数据过程中Json转换异常: " + e));
}
WbCloudFaceVerifySdk.getInstance().release();
}
};
isStarted = true;
if (useAdvanceCompare) {
WbCloudFaceVerifySdk.getInstance().initAdvSdk(cordova.getActivity(), data, listener);
} else {
WbCloudFaceVerifySdk.getInstance().initSdk(cordova.getActivity(), data, listener);
}
}
}
#不混淆内部类
-keepattributes InnerClasses
#不混淆jni调用类
-keepclasseswithmembers class *{
native <methods>;
}
###################### faceverify-BEGIN ###########################
-ignorewarnings
-keep public class com.tencent.ytcommon.**{*;}
-keep class com.tencent.turingface.sdk.*.TNative$aa { public *; }
-keep class com.tencent.turingface.sdk.*.TNative$aa$bb { public *; }
-keep class com.tencent.turingcam.** {*;}
-keep public class com.tencent.youtu.ytagreflectlivecheck.jni.**{*;}
-keep public class com.tencent.youtu.ytagreflectlivecheck.YTAGReflectLiveCheckInterface{
public <methods>;
}
-keep public class com.tencent.youtu.ytposedetect.jni.**{*;}
-keep public class com.tencent.youtu.ytposedetect.data.**{*;}
-keep public class com.tencent.youtu.liveness.YTDeviceInfo{*;}
-keep public class com.tencent.youtu.liveness.YTFaceTracker{*;}
-keep public class com.tencent.youtu.liveness.YTFaceTracker$*{*;}
-keep public class com.tencent.youtu.sdkkitframework.liveness.framework.YtSDKKitFrameworkTool{
public *;
}
-keep public class com.tencent.youtu.sdkkitframework.liveness.common.YTImageData{
*;
}
-keep public class com.tencent.cloud.huiyansdkface.facelight.net.*$*{
*;
}
-keep public class com.tencent.cloud.huiyansdkface.facelight.net.**{
*;
}
-keep public class com.tencent.cloud.huiyansdkface.facelight.provider.WbDeviceRiskInfo{
public <fields>;
}
-keep public class com.tencent.cloud.huiyansdkface.facelight.provider.WbUiTips{
*;
}
#================数据上报混淆规则 start===========================
#实体类
-keep class com.tencent.cloud.huiyansdkface.analytics.EventSender{
*;
}
-keep class com.tencent.cloud.huiyansdkface.analytics.EventSender$*{
*;
}
-keep class com.tencent.cloud.huiyansdkface.analytics.WBSAEvent{
*;
}
-keep class com.tencent.cloud.huiyansdkface.analytics.WBSAParam{
*;
}
#================数据上报混淆规则 end===========================
#######################faceverify-END#############################
####################### normal混淆规则-BEGIN#############################
#不混淆内部类
-keepattributes InnerClasses
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes Exceptions
-keep public class com.tencent.cloud.huiyansdkface.normal.net.*$*{
*;
}
-keep public class com.tencent.cloud.huiyansdkface.normal.net.*{
*;
}
#bugly
-keep class com.tencent.bugly.idasc.**{
*;
}
#wehttp混淆规则
-dontwarn com.tencent.cloud.huiyansdkface.okio.**
-keep class com.tencent.cloud.huiyansdkface.okio.**{
*;
}
-dontwarn com.tencent.cloud.huiyansdkface.okhttp3.OkHttpClient$Builder
####################### normal混淆规则-END#############################
repositories{
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/public' }
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:"jsgzsdk",ext: 'aar')
//必须添加如下依赖!!!
implementation 'com.android.support:appcompat-v7:28.+'
implementation 'com.google.code.gson:gson:+'
compile(name: 'WbCloudNormal-v5.1.10-4e3e198', ext: 'aar')
compile(name: 'WbCloudFaceLiveSdk-face-v6.1.0-3ca9d59c', ext: 'aar')
}
android {
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'cordova-plugin-hand-tecentface/kyc-cloud-face-consumer-proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'cordova-plugin-hand-tecentface/kyc-cloud-face-consumer-proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
aaptOptions {
noCompress "dat"
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '28.0.0'
}
}
}
}
\ No newline at end of file
#define ANDROID_CUSTOM_NONE (1)
#define ANDROID_CUSTOM_FOR_IOT (0)
#define ANDROID_CUSTOM_FOR_UNIONPAY (0)
#define ANDROID_CUSTOM_SUPPORT_VTS (0)
//vts && vndk: https://source.android.com/devices/architecture/images/VNDK.pdf
#define CUSTOM_FOR_QQ (0)
#define ALLOW_EMPTY_SECRET_KEY (1)
// change namespace for different business
#define YTLICENSE_NAMESPACE ytliveness
#define CLASS_WITH_PREFIX(__class) YTLiveness##__class
#define FUNCTION_WITH_PREFIX(__func) ytliveness_##__func
#define INNER_INTERFACE_USE_NAMESPACE (1)
/**
* @file yt_auth.h
* @author tencent
* @brief 鉴权接口
* @version 2.0
* @date 2020-09-10
*
* @copyright Copyright (c) 2020
*
*/
#ifndef _YT_AUTH_H_
#define _YT_AUTH_H_
#include "yt_defines.h"
// license文件申请:https://docs.qq.com/doc/DZERXWmNYeVNyWlF0
/**
* @brief 使用license文件初始化授权
* @param `platform_context` Android平台输入JNIEnv*;其他平台输入NULL
* @param `license_path` Android平台将license文件打包到assets中,传入文件名;其他平台传入文件完整路径
* @param `secret_key` 传入license对应的secret_key,在申请的时候获得
* @return 授权结果,0代表成功,错误码参考:[授权错误代码](#errorcode)
*/
YT_PUBLIC int ytliveness_auth_init_by_path(void* platform_context, const char* license_path, const char* secret_key);
/**
* @brief 使用license字符串初始化鉴权,字符串获取方式:将license文件做base64即可
* @param `platform_context` Android平台输入JNIEnv*;其他平台输入NULL
* @param `license_string` license字符串
* @param `secret_key` 传入license对应的secret_key,在申请的时候获得
* @return 授权结果,0代表成功,错误码参考:[授权错误代码](#errorcode)
*/
YT_PUBLIC int ytliveness_auth_init_by_string(void* platform_context, const char* license_string, const char* secret_key);
/**
* @brief 腾讯内部业务专用授权接口
* @param `platform_context` Android平台输入JNIEnv*;其他平台输入NULL
* @return 授权结果,0代表成功,错误码参考:[授权错误代码](#errorcode)
*/
YT_PUBLIC int ytliveness_auth_init_for_qq(void* platform_context);
/**
* @brief 授权成功后,查询授权有效期
* @return 授权到期时间的时间戳
*/
YT_PUBLIC long long ytliveness_auth_get_endtime();
/**
* @brief 查询授权库的版本
* @return 授权库的版本号
*/
YT_PUBLIC const char* ytliveness_auth_get_version();
/**
* @brief 获取已授权的SDK列表
* @param sdklist_buf 出参,返回sdklist,调用者自己分配一个int[]数组用于存储SDKlist
* @param max_count 入参,传入的sdklist_buf的最大index
* @return 实际返回的sdklist数量
* @note 如果sdklist_buf传NULL,返回值代表SDK列表的总数
*/
YT_PUBLIC int ytliveness_auth_get_sdklist_ids(int* sdklist_buf, int max_count);
/**
* @brief 获取sdk_id代表的SDK名称
* @param sdk_id
* @return 该id代表的SDK名称
*/
YT_PUBLIC const char* ytliveness_auth_get_sdkname(int sdk_id);
/**
* @brief 设置是否显示log,默认为显示
* @param enable,1-显示 0-不显示
* @return
*/
YT_PUBLIC void ytliveness_auth_enable_log(int enable);
#endif
#import <Foundation/Foundation.h>
__attribute__((visibility("default"))) @interface YTLivenessAuthManager : NSObject
+ (int)initAuthByFilePath:(NSString*) license_path withSecretKey:(NSString*) secret_key;
+ (int)initAuthByString:(NSString*) license_string withSecretKey:(NSString*) secret_key;
+ (int)initAuthForQQ;
+ (NSString*)getVersion;
+ (int64_t)getEndTime;
+ (NSArray*)getSDKList;
+ (NSString*)getSDKNameByID:(int)sdk_id;
+ (void)setEnableLog:(int)enable;
@end
#ifndef __YT_AUTH_ERRORCODE_H__
#define __YT_AUTH_ERRORCODE_H__
#define YT_AUTH_ERROR_FETCH_FAIL (1002)
#define YT_AUTH_ERROR_DECODE_FAIL (3004)
#define YT_AUTH_ERROR_EMPTY_STRING (3005)
#define YT_AUTH_ERROR_UNMATCH_DEVICE_INFO (3013)
#define YT_AUTH_ERROR_UNMATCH_IDENTIFIER (3015)
#define YT_AUTH_ERROR_EMPTY_IDENTIFIER (3016)
#define YT_AUTH_ERROR_TIME_EXPIRED (3018)
#define YT_AUTH_ERROR_UNMATCH_SECRET_KEY (3024)
#define YT_AUTH_ERROR_INVALID_DEVICE_INFO (4003)
#define YT_AUTH_ERROR_FUNC_NOT_IMPLEMENT (5001)
#endif // __YT_AUTH_ERRORCODE_H__
\ No newline at end of file
#ifndef _YT_DEFINES_H_
#define _YT_DEFINES_H_
// ----------------------------------------------------------------------------
// YouTu for cross platform defines export c api.
// windows @see: http://geoffair.net/ms/declspec.htm
// ----------------------------------------------------------------------------
#if (defined(WIN32) || defined(WIN64))
#ifdef YT_EXPORT
#define YT_PUBLIC_ __declspec(dllexport)
#else
#define YT_PUBLIC_ __declspec(dllimport)
#endif
#else
#ifdef YT_EXPORT
#define YT_PUBLIC_ __attribute__((visibility("default")))
#else
#define YT_PUBLIC_
#endif
#endif
#ifdef __cplusplus
#define YT_PUBLIC extern "C" YT_PUBLIC_
#else
#define YT_PUBLIC YT_PUBLIC_
#endif
// ----------------------------------------------------------------------------
// YouTu error code defines
// ----------------------------------------------------------------------------
#define YT_SUCCESS 0
#define YT_ERROR -1
// init error code: [-10, -99]
#define YT_ERROR_OPEN_FILE -10
#define YT_ERROR_READ_FILE -11
#define YT_ERROR_FILE_EMPTY -12
#define YT_ERROR_RPN_NET_INIT -20
#define YT_ERROR_RPN_NET_NOT_INIT -21
#define YT_ERROR_RPN_INST_INIT -22
#define YT_ERROR_RPN_INST_NOT_INIT -23
#define YT_ERROR_RPN_FORWARD -24
#define YT_ERROR_INVALID_INSTANCE -99
// arguments error code: [-100, -999]
#define YT_ERROR_MUST_NOT_NULL -100
#define YT_ERROR_IMAGE_TYPE -110
#define YT_ERROR_FACE_POINTS -120
#define YT_ERROR_FACE_FIVE_POINTS -121
#define YT_ERROR_FACE_NINETY_POINTS -122
#define YT_ERROR_FACE_RECT -123
#define YT_ERROR_INVALID_MODEL_VERSION -130
#define YT_ERROR_MODEL_THRESHOLDS_SIZE -131
// auth error code
#define YT_ERROR_AUTH_FAILED -1024
// ----------------------------------------------------------------------------
// YouTu common code defines
// ----------------------------------------------------------------------------
#define YT_FACE_FEATURE_SIZE_512 512
#define YT_FACE_FEATURE_SIZE_1024 1024
#define YT_FACE_FIVE_POINTS_SIZE 5
#define YT_FACE_NINETY_POINTS_SIZE 90
#endif // _YT_DEFINES_H_
<?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>CFBundleName</key>
<string>YTCommonLiveness</string>
<key>CFBundleIdentifier</key>
<string>com.tencent.youtu</string>
<key>CFBundleVersion</key>
<string>v2.3.5-liveness.19-2-g554d78f</string>
<key>CFBundleShortVersionString</key>
<string>v2.3.5-liveness.19-2-g554d78f</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
</dict>
</plist>
\ No newline at end of file
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_NARY_MAT_ITERATOR_HPP_
#define FBC_CV_CORE_NARY_MAT_ITERATOR_HPP_
/* reference: include/opencv2/core/map.hpp
modules/core/src/matrix.cpp
*/
#include "mat.hpp"
namespace yt_tinycv {
// n-ary multi-dimensional array iterator
// Use the class to implement unary, binary, and, generally, n-ary element-wise operations on multi - dimensional arrays.
template<typename _Tp, int chs> class NAryMatIterator {
public:
// the default constructor
NAryMatIterator();
// the full constructor taking arbitrary number of n-dim matrices
NAryMatIterator(const Mat_<_Tp, chs>** arrays, uchar** ptrs, int narrays = -1);
// the full constructor taking arbitrary number of n-dim matrices
NAryMatIterator(const Mat_<_Tp, chs>** arrays, Mat_<_Tp, chs>* planes, int narrays = -1);
// the separate iterator initialization method
void init(const Mat_<_Tp, chs>** arrays, Mat_<_Tp, chs>* planes, uchar** ptrs, int narrays = -1);
// proceeds to the next plane of every iterated matrix
NAryMatIterator& operator ++();
// proceeds to the next plane of every iterated matrix (postfix increment operator)
NAryMatIterator operator ++(int);
// the iterated arrays
const Mat_<_Tp, chs>** arrays;
// the current planes
Mat_<_Tp, chs>* planes;
// data pointers
uchar** ptrs;
// the number of arrays
int narrays;
// the number of hyper-planes that the iterator steps through
size_t nplanes;
// the size of each segment (in elements)
size_t size;
protected:
int iterdepth;
size_t idx;
};
template<typename _Tp, int chs> inline
NAryMatIterator<_Tp, chs>::NAryMatIterator()
: arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0)
{
}
template<typename _Tp, int chs>
NAryMatIterator<_Tp, chs>::NAryMatIterator(const Mat_<_Tp, chs>** _arrays, Mat_<_Tp, chs>* _planes, int _narrays)
: arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0)
{
init(_arrays, _planes, 0, _narrays);
}
template<typename _Tp, int chs>
NAryMatIterator<_Tp, chs>::NAryMatIterator(const Mat_<_Tp, chs>** _arrays, uchar** _ptrs, int _narrays)
: arrays(0), planes(0), ptrs(0), narrays(0), nplanes(0), size(0), iterdepth(0), idx(0)
{
init(_arrays, 0, _ptrs, _narrays);
}
template<typename _Tp, int chs>
void NAryMatIterator<_Tp, chs>::init(const Mat_<_Tp, chs>** _arrays, Mat_<_Tp, chs>* _planes, uchar** _ptrs, int _narrays)
{
fprintf(stderr, "NAryMatIterator no impl\n");
FBC_Error("null"); // TODO
/*FBC_Assert(_arrays && (_ptrs || _planes));
int i, j, d1 = 0, i0 = -1, d = -1;
arrays = _arrays;
ptrs = _ptrs;
planes = _planes;
narrays = _narrays;
nplanes = 0;
size = 0;
if (narrays < 0) {
for (i = 0; _arrays[i] != 0; i++)
;
narrays = i;
FBC_Assert(narrays <= 1000);
}
iterdepth = 0;
for (i = 0; i < narrays; i++) {
FBC_Assert(arrays[i] != 0);
const Mat_<_Tp, chs>& A = *arrays[i];
if (ptrs)
ptrs[i] = A.data;
if (!A.data)
continue;
if (i0 < 0) {
i0 = i;
d = 2; // A.dims;
// find the first dimensionality which is different from 1;
// in any of the arrays the first "d1" step do not affect the continuity
for (d1 = 0; d1 < d; d1++)
if (A.size[d1] > 1)
break;
} else {
FBC_Assert(A.size == arrays[i0]->size);
}
if (!A.isContinuous()) {
FBC_Assert(A.step[d - 1] == A.elemSize());
for (j = d - 1; j > d1; j--)
if (A.step[j] * A.size[j] < A.step[j - 1])
break;
iterdepth = std::max(iterdepth, j);
}
}
if (i0 >= 0) {
size = arrays[i0]->size[d - 1];
for (j = d - 1; j > iterdepth; j--) {
int64 total1 = (int64)size*arrays[i0]->size[j - 1];
if (total1 != (int)total1)
break;
size = (int)total1;
}
iterdepth = j;
if (iterdepth == d1)
iterdepth = 0;
nplanes = 1;
for (j = iterdepth - 1; j >= 0; j--)
nplanes *= arrays[i0]->size[j];
} else {
iterdepth = 0;
}
idx = 0;
if (!planes)
return;
for (i = 0; i < narrays; i++) {
FBC_Assert(arrays[i] != 0);
const Mat_<_Tp, chs>& A = *arrays[i];
if (!A.data) {
planes[i] = Mat_<_Tp, chs>();
continue;
}
planes[i] = Mat_<_Tp, chs>(1, (int)size, A.data);
}*/
}
template<typename _Tp, int chs>
NAryMatIterator<_Tp, chs>& NAryMatIterator<_Tp, chs>::operator ++()
{
fprintf(stderr, "NAryMatIterator no impl\n");
/*if (idx >= nplanes - 1)
return *this;
++idx;
if (iterdepth == 1) {
if (ptrs) {
for (int i = 0; i < narrays; i++) {
if (!ptrs[i])
continue;
ptrs[i] = arrays[i]->data + arrays[i]->step[0] * idx;
}
}
if (planes) {
for (int i = 0; i < narrays; i++) {
if (!planes[i].data)
continue;
planes[i].data = arrays[i]->data + arrays[i]->step[0] * idx;
}
}
} else {
for (int i = 0; i < narrays; i++) {
const Mat_<_Tp, chs>& A = *arrays[i];
if (!A.data)
continue;
int _idx = (int)idx;
uchar* data = A.data;
for (int j = iterdepth - 1; j >= 0 && _idx > 0; j--) {
int szi = A.size[j], t = _idx / szi;
data += (_idx - t * szi)*A.step[j];
_idx = t;
}
if (ptrs)
ptrs[i] = data;
if (planes)
planes[i].data = data;
}
}*/
return *this;
}
template<typename _Tp, int chs>
NAryMatIterator<_Tp, chs> NAryMatIterator<_Tp, chs>::operator ++(int)
{
NAryMatIterator<_Tp, chs> it = *this;
++*this;
return it;
}
} // namespace yt_tinycv
#endif // FBC_CV_CORE_NARY_MAT_ITERATOR_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_CORE_HPP_
#define FBC_CV_CORE_CORE_HPP_
/* reference: include/opencv2/core/core_c.h
include/opencv2/core.hpp
modules/core/src/stat.cpp
modules/core/include/opencv2/core/private.hpp
modules/core/src/matrix.cpp
modules/core/src/arithm.cpp
*/
#ifndef __cplusplus
#error core.hpp header must be compiled as C++
#endif
#include <exception>
#include <string>
#include "fbcdef.hpp"
#include "mat.hpp"
namespace yt_tinycv {
// NormFlags
#define FBC_C 1
#define FBC_L1 2
#define FBC_L2 4
#define FBC_NORM_MASK 7
#define FBC_RELATIVE 8
#define FBC_DIFF 16
#define FBC_MINMAX 32
#define FBC_DIFF_C (FBC_DIFF | FBC_C)
#define FBC_DIFF_L1 (FBC_DIFF | FBC_L1)
#define FBC_DIFF_L2 (FBC_DIFF | FBC_L2)
#define FBC_RELATIVE_C (FBC_RELATIVE | FBC_C)
#define FBC_RELATIVE_L1 (FBC_RELATIVE | FBC_L1)
#define FBC_RELATIVE_L2 (FBC_RELATIVE | FBC_L2)
// Discrete Linear Transforms and Related Functions
#define FBC_DXT_SCALE 2 // divide result by size of array
// Fast cubic root calculation
FBC_EXPORTS float fbcCbrt(float value);
template<typename dump>
static inline void* fbcAlignPtr(const void* ptr, int align = 32)
{
FBC_Assert((align & (align - 1)) == 0);
return (void*)(((size_t)ptr + align - 1) & ~(size_t)(align - 1));
}
template<typename dump>
static inline int fbcAlign(int size, int align)
{
FBC_Assert((align & (align - 1)) == 0 && size < INT_MAX);
return (size + align - 1) & -align;
}
// Computes the source location of an extrapolated pixel
/* Various border types, image boundaries are denoted with '|'
* BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
* BORDER_REFLECT: fedcba|abcdefgh|hgfedcb
* BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba
* BORDER_WRAP: cdefgh|abcdefgh|abcdefg
* BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii with some specified 'i'
*/
template<typename _Tp>
int borderInterpolate(int p, int len, int borderType)
{
if ((unsigned)p < (unsigned)len) {
;
} else if (borderType == BORDER_REPLICATE) {
p = p < 0 ? 0 : len - 1;
} else if (borderType == BORDER_REFLECT || borderType == BORDER_REFLECT_101) {
int delta = borderType == BORDER_REFLECT_101;
if (len == 1)
return 0;
do {
if (p < 0)
p = -p - 1 + delta;
else
p = len - 1 - (p - len) - delta;
} while ((unsigned)p >= (unsigned)len);
} else if (borderType == BORDER_WRAP) {
FBC_Assert(len > 0);
if (p < 0)
p -= ((p - len + 1) / len)*len;
if (p >= len)
p %= len;
} else if (borderType == BORDER_CONSTANT) {
p = -1;
} else {
FBC_Error("Unknown/unsupported border type");
}
return p;
}
// Transposes a matrix
// \f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f]
template<typename _Tp, int chs>
int transpose(const Mat_<_Tp, chs>& src, Mat_<_Tp, chs>& dst)
{
if (src.empty()) {
dst.release();
return -1;
}
// handle the case of single-column/single-row matrices, stored in STL vectors
if (src.rows != dst.cols || src.cols != dst.rows) {
FBC_Assert(src.size() == dst.size() && (src.cols == 1 || src.rows == 1));
src.copyTo(dst);
return 0;
}
if (dst.data == src.data) {
FBC_Assert(0); // TODO
} else {
Size sz = src.size();
int i = 0, j, m = sz.width, n = sz.height;
int sstep = src.step;
int dstep = dst.step;
for (; i <= m - 4; i += 4) {
_Tp* d0 = (_Tp*)(dst.data + dstep*i);
_Tp* d1 = (_Tp*)(dst.data + dstep*(i + 1));
_Tp* d2 = (_Tp*)(dst.data + dstep*(i + 2));
_Tp* d3 = (_Tp*)(dst.data + dstep*(i + 3));
for (j = 0; j <= n - 4; j += 4) {
const _Tp* s0 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*j);
const _Tp* s1 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*(j + 1));
const _Tp* s2 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*(j + 2));
const _Tp* s3 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*(j + 3));
d0[j] = s0[0]; d0[j + 1] = s1[0]; d0[j + 2] = s2[0]; d0[j + 3] = s3[0];
d1[j] = s0[1]; d1[j + 1] = s1[1]; d1[j + 2] = s2[1]; d1[j + 3] = s3[1];
d2[j] = s0[2]; d2[j + 1] = s1[2]; d2[j + 2] = s2[2]; d2[j + 3] = s3[2];
d3[j] = s0[3]; d3[j + 1] = s1[3]; d3[j + 2] = s2[3]; d3[j + 3] = s3[3];
}
for (; j < n; j++) {
const _Tp* s0 = (const _Tp*)(src.data + i*sizeof(_Tp) + j*sstep);
d0[j] = s0[0]; d1[j] = s0[1]; d2[j] = s0[2]; d3[j] = s0[3];
}
}
for (; i < m; i++) {
_Tp* d0 = (_Tp*)(dst.data + dstep*i);
j = 0;
for (; j <= n - 4; j += 4) {
const _Tp* s0 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*j);
const _Tp* s1 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*(j + 1));
const _Tp* s2 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*(j + 2));
const _Tp* s3 = (const _Tp*)(src.data + i*sizeof(_Tp) + sstep*(j + 3));
d0[j] = s0[0]; d0[j + 1] = s1[0]; d0[j + 2] = s2[0]; d0[j + 3] = s3[0];
}
for (; j < n; j++) {
const _Tp* s0 = (const _Tp*)(src.data + i*sizeof(_Tp) + j*sstep);
d0[j] = s0[0];
}
}
}
return 0;
}
// Counts non-zero array elements
// \f[\sum _{ I: \; \texttt{ src } (I) \ne0 } 1\f]
template<typename _Tp, int chs>
int countNonZero(const Mat_<_Tp, chs>& src)
{
FBC_Assert(chs == 1);
int len = src.rows * src.cols;
const _Tp* p = (_Tp*)src.data;
int nz = 0;
for (int i = 0; i < len; i++) {
nz += (p[i] != 0);
}
return nz;
}
template<typename _Tp, int chs>
void scalarToRawData(const yt_tinycv::Scalar& s, void* _buf, int unroll_to = 0)
{
FBC_Assert(typeid(uchar).name() == typeid(_Tp).name() || typeid(float).name() == typeid(_Tp).name()); // uchar || float
int i, cn = chs;
FBC_Assert(chs <= 4);
int depth = sizeof(_Tp);
switch (depth) {
case 1: {
uchar* buf = (uchar*)_buf;
for (i = 0; i < cn; i++)
buf[i] = saturate_cast<uchar>(s.val[i]);
for (; i < unroll_to; i++)
buf[i] = buf[i - cn];
}
break;
case 4: {
float* buf = (float*)_buf;
for (i = 0; i < cn; i++)
buf[i] = saturate_cast<float>(s.val[i]);
for (; i < unroll_to; i++)
buf[i] = buf[i - cn];
}
break;
default:
FBC_Error("UnsupportedFormat");
}
}
// calculates the per - element bit - wise logical conjunction
// \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f]
// mask optional operation mask, 8-bit single channel array, that specifies elements of the output array to be changed
template<typename _Tp, int chs>
int bitwise_and(const Mat_<_Tp, chs>& src1, const Mat_<_Tp, chs>& src2, Mat_<_Tp, chs>& dst, const Mat_<uchar, 1>& mask = Mat_<uchar, 1>())
{
FBC_Assert(src1.rows == src2.rows && src1.cols == src2.cols);
if (dst.empty()) {
dst = Mat_<_Tp, chs>(src1.rows, src1.cols);
} else {
FBC_Assert(src1.rows == dst.rows && src1.cols == dst.cols);
}
if (!mask.empty()) {
FBC_Assert(src1.rows == mask.rows && src1.cols == mask.cols);
}
int bytePerRow = src1.cols * chs * sizeof(_Tp);
int bypePerPixel = chs * sizeof(_Tp);
for (int y = 0; y < src1.rows; y++) {
const uchar* pSrc1 = src1.ptr(y);
const uchar* pSrc2 = src2.ptr(y);
uchar* pDst = dst.ptr(y);
const uchar* pMask = NULL;
if (!mask.empty()) {
pMask = mask.ptr(y);
for (int x = 0; x < src1.cols; x++) {
if (pMask[x] == 1) {
int addr = x * bypePerPixel;
for (int t = 0; t < bypePerPixel; t++) {
pDst[addr + t] = pSrc1[addr + t] & pSrc2[addr + t];
}
}
}
} else {
for (int x = 0; x < bytePerRow; x++) {
pDst[x] = pSrc1[x] & pSrc2[x];
}
}
}
return 0;
}
// Inverts every bit of an array
// \f[\texttt{dst} (I) = \neg \texttt{src} (I)\f]
// mask optional operation mask, 8-bit single channel array, that specifies elements of the output array to be changed
template<typename _Tp, int chs>
int bitwise_not(const Mat_<_Tp, chs>& src, Mat_<_Tp, chs>& dst, const Mat_<uchar, 1>& mask = Mat_<uchar, 1>())
{
if (dst.empty()) {
dst = Mat_<_Tp, chs>(src.rows, src.cols);
} else {
FBC_Assert(src.rows == dst.rows && src.cols == dst.cols);
}
if (!mask.empty()) {
FBC_Assert(src.rows == mask.rows && src.cols == mask.cols);
}
int bytePerRow = src.cols * chs * sizeof(_Tp);
int bypePerPixel = chs * sizeof(_Tp);
for (int y = 0; y < src.rows; y++) {
const uchar* pSrc = src.ptr(y);
uchar* pDst = dst.ptr(y);
const uchar* pMask = NULL;
if (!mask.empty()) {
pMask = mask.ptr(y);
for (int x = 0; x < src.cols; x++) {
if (pMask[x] == 1) {
int addr = x * bypePerPixel;
for (int t = 0; t < bypePerPixel; t++) {
pDst[addr + t] = ~pSrc[addr + t];
}
}
}
} else {
for (int x = 0; x < bytePerRow; x++) {
pDst[x] = ~pSrc[x];
}
}
}
return 0;
}
} // namespace yt_tinycv
#endif // FBC_CV_CORE_CORE_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_FAST_MATH_HPP_
#define FBC_CV_CORE_FAST_MATH_HPP_
// reference: include/opencv2/core/fast_math.hpp
#include "fbcdef.hpp"
namespace yt_tinycv {
// Rounds floating-point number to the nearest integer
static inline int fbcRound(double value)
{
// it's ok if round does not comply with IEEE754 standard;
// it should allow +/-1 difference when the other functions use round
return (int)(value + (value >= 0 ? 0.5 : -0.5));
}
static inline int fbcRound(float value)
{
// it's ok if round does not comply with IEEE754 standard;
// it should allow +/-1 difference when the other functions use round
return (int)(value + (value >= 0 ? 0.5f : -0.5f));
}
static inline int fbcRound(int value)
{
return value;
}
// Rounds floating-point number to the nearest integer not larger than the original
static inline int fbcFloor(double value)
{
int i = fbcRound(value);
float diff = (float)(value - i);
return i - (diff < 0);
}
static inline int fbcFloor(float value)
{
int i = fbcRound(value);
float diff = (float)(value - i);
return i - (diff < 0);
}
static inline int fbcFloor(int value)
{
return value;
}
// Rounds floating-point number to the nearest integer not smaller than the original
static inline int fbcCeil(double value)
{
int i = fbcRound(value);
float diff = (float)(i - value);
return i + (diff < 0);
}
static inline int fbcCeil(float value)
{
int i = fbcRound(value);
float diff = (float)(i - value);
return i + (diff < 0);
}
static inline int fbcCeil(int value)
{
return value;
}
} // yt_tinycv
#endif // FBC_CV_CORE_FAST_MATH_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_FBCDEF_HPP_
#define FBC_CV_CORE_FBCDEF_HPP_
/* reference: include/opencv2/core/cvdef.h
include/opencv2/core/typedef_c.h
*/
#include "interface.hpp"
#ifdef _MSC_VER
#define FBC_EXPORTS __declspec(dllexport)
#define FBC_DECL_ALIGNED(x) __declspec(align(x))
#else
#define FBC_EXPORTS __attribute__((visibility("default")))
#define FBC_DECL_ALIGNED(x) __attribute__((aligned(x)))
#endif
namespace yt_tinycv {
#define FBC_CN_MAX 512
#define FBC_CN_SHIFT 3
#define FBC_DEPTH_MAX (1 << FBC_CN_SHIFT)
#define FBC_MAT_TYPE_MASK (FBC_DEPTH_MAX*FBC_CN_MAX - 1)
#define FBC_MAT_TYPE(flags) ((flags) & FBC_MAT_TYPE_MASK)
#ifndef MIN
#define MIN(a,b) ((a) > (b) ? (b) : (a))
#endif
#ifndef MAX
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
#define FBC_CN_MAX 512
// Common macros and inline functions
#define FBC_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
/** min & max without jumps */
#define FBC_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
#define FBC_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
// fundamental constants
#define FBC_PI 3.1415926535897932384626433832795
// Note: No practical significance
class dump {};
typedef union Cv32suf {
int i;
unsigned u;
float f;
} Cv32suf;
typedef union Cv64suf {
int64 i;
yt_tinycv::uint64 u;
double f;
} Cv64suf;
} // namespace yt_tinycv
#endif // FBC_CV_CORE_FBCDEF_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_FBCSTD_HPP_
#define FBC_CV_CORE_FBCSTD_HPP_
// reference: include/opencv2/core/cvstd.hpp
#include "fbcdef.hpp"
#ifndef __cplusplus
#error fbcstd.hpp header must be compiled as C++
#endif
namespace yt_tinycv {
/* the alignment of all the allocated buffers */
#define FBC_MALLOC_ALIGN 16
// Allocates an aligned memory buffer
FBC_EXPORTS void* fastMalloc(size_t size);
// Deallocates a memory buffer
FBC_EXPORTS void fastFree(void* ptr);
void* cvAlloc(size_t size);
void cvFree_(void* ptr);
#define cvFree(ptr) (cvFree_(*(ptr)), *(ptr)=0)
} // namespace yt_tinycv
#endif // FBC_CV_CORE_FBCSTD_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_INTERFACE_HPP_
#define FBC_CV_CORE_INTERFACE_HPP_
// reference: include/opencv2/core/hal/interface.h
#include <stdint.h>
namespace yt_tinycv {
/* primitive types */
/*
schar - signed 1 byte integer
uchar - unsigned 1 byte integer
short - signed 2 byte integer
ushort - unsigned 2 byte integer
int - signed 4 byte integer
uint - unsigned 4 byte integer
int64 - signed 8 byte integer
uint64 - unsigned 8 byte integer
*/
typedef unsigned int uint;
typedef signed char schar;
typedef unsigned char uchar;
typedef unsigned short ushort;
#ifdef _MSC_VER
typedef __int64 int64;
typedef unsigned __int64 uint64;
#else
typedef int64_t int64;
typedef uint64_t uint64;
#endif
} // yt_tinycv
#endif // FBC_CV_CORE_INTERFACE_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_SATURATE_HPP_
#define FBC_CV_CORE_SATURATE_HPP_
// reference: include/opencv2/core/saturate.hpp
#include <algorithm>
#include <limits.h>
#include "fbcdef.hpp"
#include "interface.hpp"
#include "fast_math.hpp"
namespace yt_tinycv
{
template<typename _Tp> static inline _Tp saturate_cast(uchar v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(schar v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(ushort v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(short v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(unsigned int v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(int v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(float v) { return _Tp(v); }
template<typename _Tp> static inline _Tp saturate_cast(double v) { return _Tp(v); }
template<> inline uchar saturate_cast<uchar>(schar v) { return (uchar)std::max((int)v, 0); }
template<> inline uchar saturate_cast<uchar>(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); }
template<> inline uchar saturate_cast<uchar>(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
template<> inline uchar saturate_cast<uchar>(short v) { return saturate_cast<uchar>((int)v); }
template<> inline uchar saturate_cast<uchar>(unsigned int v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); }
template<> inline uchar saturate_cast<uchar>(float v) { int iv = fbcRound(v); return saturate_cast<uchar>(iv); }
template<> inline uchar saturate_cast<uchar>(double v) { int iv = fbcRound(v); return saturate_cast<uchar>(iv); }
template<> inline schar saturate_cast<schar>(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); }
template<> inline schar saturate_cast<schar>(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); }
template<> inline schar saturate_cast<schar>(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
template<> inline schar saturate_cast<schar>(short v) { return saturate_cast<schar>((int)v); }
template<> inline schar saturate_cast<schar>(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); }
template<> inline schar saturate_cast<schar>(float v) { int iv = fbcRound(v); return saturate_cast<schar>(iv); }
template<> inline schar saturate_cast<schar>(double v) { int iv = fbcRound(v); return saturate_cast<schar>(iv); }
template<> inline ushort saturate_cast<ushort>(schar v) { return (ushort)std::max((int)v, 0); }
template<> inline ushort saturate_cast<ushort>(short v) { return (ushort)std::max((int)v, 0); }
template<> inline ushort saturate_cast<ushort>(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
template<> inline ushort saturate_cast<ushort>(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); }
template<> inline ushort saturate_cast<ushort>(float v) { int iv = fbcRound(v); return saturate_cast<ushort>(iv); }
template<> inline ushort saturate_cast<ushort>(double v) { int iv = fbcRound(v); return saturate_cast<ushort>(iv); }
template<> inline short saturate_cast<short>(ushort v) { return (short)std::min((int)v, SHRT_MAX); }
template<> inline short saturate_cast<short>(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
template<> inline short saturate_cast<short>(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); }
template<> inline short saturate_cast<short>(float v) { int iv = fbcRound(v); return saturate_cast<short>(iv); }
template<> inline short saturate_cast<short>(double v) { int iv = fbcRound(v); return saturate_cast<short>(iv); }
template<> inline int saturate_cast<int>(float v) { return fbcRound(v); }
template<> inline int saturate_cast<int>(double v) { return fbcRound(v); }
template<> inline unsigned saturate_cast<unsigned>(float v) { return fbcRound(v); }
template<> inline unsigned saturate_cast<unsigned>(double v) { return fbcRound(v); }
} // yt_tinycv
#endif // FBC_CV_CORE_SATURATE_HPP_
// fbc_cv is free software and uses the same licence as OpenCV
// Email: fengbingchun@163.com
#ifndef FBC_CV_CORE_UTILITY_HPP_
#define FBC_CV_CORE_UTILITY_HPP_
// reference: include/opencv2/core/utility.hpp
#ifndef __cplusplus
#error utility.hpp header must be compiled as C++
#endif
#include "fbcdef.hpp"
#include "base.hpp"
namespace yt_tinycv {
// The function returns the aligned pointer of the same type as the input pointer
template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n = (int)sizeof(_Tp))
{
return (_Tp*)(((size_t)ptr + n - 1) & -n);
}
// The function returns the minimum number that is greater or equal to sz and is divisible by n
static inline size_t alignSize(size_t sz, int n)
{
FBC_Assert((n & (n - 1)) == 0); // n is a power of 2
return (sz + n - 1) & -n;
}
// Automatically Allocated Buffer Class
// The class is used for temporary buffers in functions and methods.
template<typename _Tp, size_t fixed_size = 1024 / sizeof(_Tp) + 8> class AutoBuffer {
public:
typedef _Tp value_type;
// the default constructor
AutoBuffer();
// constructor taking the real buffer size
AutoBuffer(size_t _size);
// the copy constructor
AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf);
// the assignment operator
AutoBuffer<_Tp, fixed_size>& operator = (const AutoBuffer<_Tp, fixed_size>& buf);
// destructor. calls deallocate()
~AutoBuffer();
// allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used
void allocate(size_t _size);
// deallocates the buffer if it was dynamically allocated
void deallocate();
// resizes the buffer and preserves the content
void resize(size_t _size);
// returns the current buffer size
size_t size() const;
// returns pointer to the real buffer, stack-allocated or head-allocated
operator _Tp* ();
// returns read-only pointer to the real buffer, stack-allocated or head-allocated
operator const _Tp* () const;
protected:
// pointer to the real buffer, can point to buf if the buffer is small enough
_Tp* ptr;
// size of the real buffer
size_t sz;
//! pre-allocated buffer. At least 1 element to confirm C++ standard reqirements
_Tp buf[(fixed_size > 0) ? fixed_size : 1];
};
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::AutoBuffer()
{
ptr = buf;
sz = fixed_size;
}
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size)
{
ptr = buf;
sz = fixed_size;
allocate(_size);
}
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf)
{
ptr = buf;
sz = fixed_size;
allocate(abuf.size());
for (size_t i = 0; i < sz; i++) {
ptr[i] = abuf.ptr[i];
}
}
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>&
AutoBuffer<_Tp, fixed_size>::operator = (const AutoBuffer<_Tp, fixed_size>& abuf)
{
if (this != &abuf) {
deallocate();
allocate(abuf.size());
for (size_t i = 0; i < sz; i++) {
ptr[i] = abuf.ptr[i];
}
}
return *this;
}
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::~AutoBuffer()
{
deallocate();
}
template<typename _Tp, size_t fixed_size> inline void
AutoBuffer<_Tp, fixed_size>::allocate(size_t _size)
{
if (_size <= sz) {
sz = _size;
return;
}
deallocate();
if (_size > fixed_size) {
ptr = new _Tp[_size];
sz = _size;
}
}
template<typename _Tp, size_t fixed_size> inline void
AutoBuffer<_Tp, fixed_size>::deallocate()
{
if (ptr != buf) {
delete[] ptr;
ptr = buf;
sz = fixed_size;
}
}
template<typename _Tp, size_t fixed_size> inline void
AutoBuffer<_Tp, fixed_size>::resize(size_t _size)
{
if (_size <= sz) {
sz = _size;
return;
}
size_t i, prevsize = sz, minsize = MIN(prevsize, _size);
_Tp* prevptr = ptr;
ptr = _size > fixed_size ? new _Tp[_size] : buf;
sz = _size;
if (ptr != prevptr) {
for (i = 0; i < minsize; i++) {
ptr[i] = prevptr[i];
}
}
for (i = prevsize; i < _size; i++) {
ptr[i] = _Tp();
}
if (prevptr != buf) {
delete[] prevptr;
}
}
template<typename _Tp, size_t fixed_size> inline size_t
AutoBuffer<_Tp, fixed_size>::size() const
{
return sz;
}
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::operator _Tp* ()
{
return ptr;
}
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const
{
return ptr;
}
} // yt_tinycv
#endif // FBC_CV_CORE_UTILITY_HPP_
<?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>CFBundleName</key>
<string>YTCv</string>
<key>CFBundleIdentifier</key>
<string>com.tencent.youtu</string>
<key>CFBundleVersion</key>
<string>v0.0.3</string>
<key>CFBundleShortVersionString</key>
<string>v0.0.3</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
</dict>
</plist>
\ No newline at end of file
#ifndef _YT_COMMON_H_
#define _YT_COMMON_H_
typedef void *yt_handle;
typedef enum {
YT_IMG_BGR_8UC3,
YT_IMG_RGB_8UC3,
YT_IMG_GRAY_8UC1,
YT_IMG_DEPTH_16UC1,
YT_IMG_BGRA_8UC4,
YT_IMG_RGBA_8UC4,
YT_IMG_NV21,
YT_IMG_NV12,
YT_IMG_UNKNOWN,
} yt_img_type;
typedef struct yt_image_t {
unsigned char *data;
int width;
int height;
yt_img_type type;
} yt_image;
typedef struct yt_rect_t {
int x;
int y;
int width;
int height;
} yt_rect;
typedef struct yt_pointf_t {
float x;
float y;
} yt_pointf;
typedef struct yt_point3f_t {
float x;
float y;
float z;
} yt_point3f;
#endif // _YT_COMMON_H_
<?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>CFBundleName</key>
<string>YTFaceAlignmentTiny</string>
<key>CFBundleIdentifier</key>
<string>com.tencent.youtu</string>
<key>CFBundleVersion</key>
<string>v3.0.2-mini.4</string>
<key>CFBundleShortVersionString</key>
<string>v3.0.2-mini.4</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
</dict>
</plist>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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