使用unity 3D进行面部识别。如何在C#中修复这段代码?

问题描述 投票:0回答:1

这段代码一直进入else条件,没有执行IF语句的第一部分。

public void OnSaveButtonClick ()
{
    Debug.Log ("User clicked [Save] button.");

    string saveDirectoryPath = Path.Combine (Application.persistentDataPath, saveDirectoryName);

    if (model != null)
    {
        // Clean up old files.
        if (Directory.Exists (saveDirectoryPath))
        {
            DirectoryInfo directoryInfo = new DirectoryInfo (saveDirectoryPath);
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                if ((fileInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) 
                {
                    fileInfo.Attributes = FileAttributes.Normal;
                }
            }
            if ((directoryInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                directoryInfo.Attributes = FileAttributes.Directory;
            }
            directoryInfo.Delete (true);
        }
        Directory.CreateDirectory (saveDirectoryPath);

        // save the train data.
        model.write (Path.Combine (saveDirectoryPath, "traindata.yml"));

        // save the preprocessedfaces.
        #if UNITY_WEBGL && !UNITY_EDITOR
        string format = "jpg";
        MatOfInt compressionParams = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, 100);
        #else
        string format = "png";
        MatOfInt compressionParams = new MatOfInt (Imgcodecs.IMWRITE_PNG_COMPRESSION, 0);
        #endif
        for (int i = 0; i < m_numPersons; ++i)
        {
            Imgcodecs.imwrite (Path.Combine (saveDirectoryPath, "preprocessedface" + i + "." + format), preprocessedFaces [m_latestFaces [i]], compressionParams);
        }
    } 
    else 
    {
        Debug.Log ("save failure. train data does not exist.");
    }
}

训练数据不存在。 UnityEngine.Debug:Log(Object) RealTimeFaceRecognitionExample.WebCamTextureRealTimeFaceRecognitionExample:OnSaveButtonClick() (at AssetsRealTimeFaceRecognitionExampleWebCamTextureRealTimeFaceRecognitionExampleWebCamTextureRealTimeFaceRecognitionExample.cs:541) UnityEngine.EventSystems.EventSystem:Update()

unity3d
1个回答
0
投票

在扫描图像或人物后,你必须点击被扫描的图像或人物面部的任何地方来训练数据,然后再保存。

© www.soinside.com 2019 - 2024. All rights reserved.