unity3d 如何在C# Unity中通过REST API发送点击图片

4sup72z8  于 2023-02-13  发布在  C#
关注(0)|答案(1)|浏览(138)

这是我的代码来捕捉webcamTexture的图像。

public void SavePhoto()
{
    Debug.Log(Application.dataPath);
    Texture2D photo = new Texture2D(camTexture.width, camTexture.height);
    photo.SetPixels(camTexture.GetPixels());
    photo.Apply();

    //Encode to a PNG
    byte[] bytes = photo.EncodeToJPG();

    System.IO.File.WriteAllBytes(Application.dataPath + "/photo.png", bytes);
    predictImage(bytes);
}

这是我的代码发送图像到API

public async void predictImage(byte[] bytes)
{
    ByteArrayContent content = new ByteArrayContent(bytes);
    
    var response = await client.PostAsync("http://74.235.83.70:80", content);
    var responseString = await response.Content.ReadAsStringAsync();
    Debug.Log(responseString);
}

这是以字节数组的形式发送图像,但是我想以图像文件的形式发送图像,我该怎么做呢?实际上,那个API是一个用于图像分类的机器学习模型。

相关问题