faceplusplus 免费人脸识别云服务

faceplusplus免费人脸识别云服务


using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.IO;


public class FaceTest : MonoBehaviour
{
    private string api_key = "f0b0a4183f4ecf32a8791e1fc4cee84d";
    private string api_secret = "iAfFeuo5eH53U4Os5w1FEzS0KA-Rm4uC";
    private string url = "http://apicn.faceplusplus.com/v2/detection/detect?";
    private string parameters = "&attribute=glass,pose,gender,age,race,smiling";


    private string imgName = "temp.jpg";


    public Texture2D img = null;


    // Use this for initialization
    void Start()
    {


    }


    // Update is called once per frame
    void Update()
    {


    }




    void OnGUI()
    {
        if (img != null)
        {
            GUI.DrawTexture(new Rect(0, 35, img.width, img.height), img);
        }


        if (GUI.Button(new Rect(0, 0, 100, 35), "OpenDialog"))
        {
            OpenFileName ofn = new OpenFileName();


            ofn.structSize = Marshal.SizeOf(ofn);


            ofn.filter = "图片文件(*.jpg*.png)\0*.jpg;*.png";


            ofn.file = new string(new char[256]);


            ofn.maxFile = ofn.file.Length;


            ofn.fileTitle = new string(new char[64]);


            ofn.maxFileTitle = ofn.fileTitle.Length;


            ofn.initialDir = UnityEngine.Application.dataPath;//默认路径  


            ofn.title = "Open Project";


            ofn.defExt = "JPG";


            ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR  


            if (WindowDll.GetOpenFileName(ofn))
            {
                Debug.Log("Selected file with full path: {0}" + ofn.file);
                if (!Directory.Exists(UnityEngine.Application.streamingAssetsPath))
                {
                    Directory.CreateDirectory(UnityEngine.Application.streamingAssetsPath);
                }
                File.Copy(ofn.file, UnityEngine.Application.streamingAssetsPath + "/temp.jpg");
                Debug.Log("file://" + ofn.file);
                StartCoroutine(LoadTexture("file://" + UnityEngine.Application.streamingAssetsPath + "/temp.jpg"));
            }


        }
    }


    IEnumerator LoadTexture(string localUrl)
    {
        WWW www = new WWW(localUrl);
        yield return www;
        img = www.texture;
        byte[] pngData = www.texture.EncodeToJPG();
        File.Delete(UnityEngine.Application.streamingAssetsPath + "/temp.jpg");
        StartCoroutine(PostImage(pngData));
    }


    IEnumerator PostImage(byte[] imgBytes)
    {
        WWWForm form = new WWWForm();
        form.AddField("api_key", api_key);
        form.AddField("api_secret", api_secret);
        form.AddBinaryData("img", imgBytes, "temp.jpg", "image/jpg");
        form.AddField("attribute", "glass,pose,gender,age,race,smiling");
        WWW www = new WWW(url, form);
        yield return www;
        Debug.Log(www.text);
    }
}

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

public class OpenFileName
{
    public int structSize = 0;
    public IntPtr dlgOwner = IntPtr.Zero;
    public IntPtr instance = IntPtr.Zero;
    public String filter = null;
    public String customFilter = null;
    public int maxCustFilter = 0;
    public int filterIndex = 0;
    public String file = null;
    public int maxFile = 0;
    public String fileTitle = null;
    public int maxFileTitle = 0;
    public String initialDir = null;
    public String title = null;
    public int flags = 0;
    public short fileOffset = 0;
    public short fileExtension = 0;
    public String defExt = null;
    public IntPtr custData = IntPtr.Zero;
    public IntPtr hook = IntPtr.Zero;
    public String templateName = null;
    public IntPtr reservedPtr = IntPtr.Zero;
    public int reservedInt = 0;
    public int flagsEx = 0;
}

public class WindowDll
{
    [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
    public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
    public static bool GetOpenFileName1([In, Out] OpenFileName ofn)
    {
        return GetOpenFileName(ofn);
    }
}





工程下载点击这里

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地狱为王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值