这段代码一直进入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()
在扫描图像或人物后,你必须点击被扫描的图像或人物面部的任何地方来训练数据,然后再保存。