找不到 FacesTopLevelMultiple

FacesTopLevelMultiple could not be found

使用 IBM Watson 提供的视觉识别 API 的人脸检测程序出现问题。我根据找到的教程编写了一个程序,但我遇到了一个阻止它 运行 的错误。错误如下: https://i.stack.imgur.com/CBN0p.png

这是我 运行 用于人脸检测的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Utilities;
using IBM.Watson.DeveloperCloud.Connection;


public class FaceDetector : MonoBehaviour
{
    public Text dataOutput;
    private VisualRecognition _visualRecognition;
    private string path = "C:\Users\Alberto\Desktop\Alberto.jpg";

    public string _serviceUrl;
    public string _iamApikey;

    void Start() {
        LogSystem.InstallDefaultReactors();
        Runnable.Run(CreateService());
    }

    private IEnumerator CreateService() {
        if (string.IsNullOrEmpty(_iamApikey)) {
            throw new WatsonException("Please provide IAM ApiKey for the service.");
        }

        Credentials credentials = null;

        TokenOptions tokenOptions = new TokenOptions() {
            IamApiKey = _iamApikey
        };

        credentials = new Credentials(tokenOptions, _serviceUrl);

        //wait for token
        while (!credentials.HasIamTokenData())
            yield return null;

        //create credentials
        _visualRecognition = new VisualRecognition(credentials);
        _visualRecognition.VersionDate = "2019-02-26";
    }

    public void DetectFaces(string path) {
        //classify using image url
        // if (!_visualRecognition.DetectFaces(picURL, OnDetectFaces, OnFail))
        //     Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!");

        //classify using image path
        if(!_visualRecognition.DetectFaces(OnDetectFaces, OnFail, path)) {
            Debug.Log("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!");
        } else {
            Debug.Log("Calling Watson");
            dataOutput.text = "";
        }
    }

    private void OnDetectFaces(FacesTopLevelMultiple multipleImages, Dictionary<string, object> customData) {
        var data = multipleImages.images[0].faces[0];
        dataOutput.text = "Age : " + data.age.min + "-" + data.age.max + " PROBABILITY: " + data.age.score + "\n";
        "Gender: " + data.gender.gender + " PROBABILITY: " + data.gender.score + "\n";
        Debug.Log("ExampleVisualRecognition.OnDetectFaces(): Detect faces result: " + customData["json"].ToString());
    }

    private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData) {
        Debug.LogError("ExampleVisualRecognition.OnFail(): Error received: " + error.ToString());
    }
}

这是使网络摄像头能够跟踪我的脸的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
using IBM.Watson.DeveloperCloud.Logging;
using IBM.Watson.DeveloperCloud.Utilities;

public class CameraRender : MonoBehaviour
{
    public Image overlay;
    public FaceDetector fd;
    // Start is called before the first frame update
    void Start()
    {
        WebCamTexture backCam = new WebCamTexture();
        backCam.Play();
        overlay.material.mainTexture = backCam;
    }

    public void CaptureImage() {
        ScreenCapture.CaptureScreenshot("screenshot.png");
        fd.DetectFaces(application.persistentDataPath + "/screenshot.png");

    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0)) {
            CaptureImage();
        }
    }

}

我希望这有助于找出问题所在。 FacesTopLevelMultiple 在 FaceDetector 脚本底部附近使用。

detectFaces 回调似乎已过时(可能来自需要更新的教程)。方法签名应该是

OnDetectFaces(DetectedFaces multipleImages, Dictionary<string, object> customData)

您应该能够使用

找到面孔
private void OnDetectFaces(DetectedFaces multipleImages, Dictionary<string, object> customData)
{
    Log.Debug("ExampleFaceDetection", "First face age: {0}", multipleImages.images[0].faces[0].age);
    Log.Debug("ExampleFaceDetection", "First face gender: {0}", multipleImages.images[0].faces[0].gender);
}