- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将 Microsoft 的 Face API 与 Android Studio 结合使用来制作应用程序。现在,我只是在玩弄 API,但我遇到了问题。在应该可用的面部属性类型中(参见 on this page),我可以从中挑选的唯一属性类型是 Age、FacialHair、Gender、HeadPose 和 Smile。我很想使用 Emotion 属性类型,但无法识别。
我得到的错误:Cannot resolve symbol 'Emotion'
这里是相关的代码部分:
Face[] result = faceServiceClient.detect(inputStreams[0], true, true, new FaceServiceClient.FaceAttributeType[]{FaceServiceClient.FaceAttributeType.Emotion});
这是我的 MainActivity 中的完整代码:
package me.ianterry.face;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.microsoft.projectoxford.face.*;
import com.microsoft.projectoxford.face.contract.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity {
private FaceServiceClient faceServiceClient =
new FaceServiceRestClient("https://westcentralus.api.cognitive.microsoft.com/face/v1.0", "MY KEY");
private ImageView mImageView;
private Button mProcessButton;
private ProgressDialog progress;
public final String TAG = "attributeMethod";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
mImageView = findViewById(R.id.image);
mImageView.setImageBitmap(myBitmap);
mProcessButton = findViewById(R.id.btn_process);
mProcessButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
detectAndFrame(myBitmap);
}
});
progress = new ProgressDialog(this);
}
private void detectAndFrame(final Bitmap myBitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
AsyncTask<InputStream, String, Face[]> detectTask = new AsyncTask<InputStream, String, Face[]>() {
//private ProgressDialog progress = new ProgressDialog(MainActivity.this);
@Override
protected void onPostExecute(Face[] faces) {
progress.dismiss();
if (faces == null) {
return;
}
mImageView.setImageBitmap(drawFaceRectangleOnBitmap(myBitmap, faces));
attributeMethod(faces);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progress.show();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
progress.setMessage(values[0]);
}
@Override
protected Face[] doInBackground(InputStream... inputStreams) {
//return new Face[0];
try {
publishProgress("Detecting...");
Face[] result = faceServiceClient.detect(inputStreams[0], true, true, new FaceServiceClient.FaceAttributeType[]{FaceServiceClient.FaceAttributeType.Emotion});
if (result == null) {
publishProgress("Detection finished. Nothing detected.");
return null;
}
publishProgress(String.format("Detection Finished. %d face(s) detected", result.length));
return result;
} catch (Exception e) {
publishProgress("Detection failed.");
return null;
}
}
};
detectTask.execute(inputStream);
}
private static Bitmap drawFaceRectangleOnBitmap(Bitmap myBitmap, Face[] faces) {
Bitmap bitmap = myBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.WHITE);
int strokeWidth = 8;
paint.setStrokeWidth(strokeWidth);
if (faces != null) {
for (Face face : faces) {
FaceRectangle faceRectangle = face.faceRectangle;
canvas.drawRect(faceRectangle.left,
faceRectangle.top,
faceRectangle.left + faceRectangle.width,
faceRectangle.top + faceRectangle.height,
paint);
}
}
return bitmap;
}
private void attributeMethod(Face[] faces) {
for (Face face : faces) {
FaceAttribute attribute = face.faceAttributes;
Log.d(TAG, "age: " + attribute.age);
Log.d(TAG, "gender: " + attribute.gender);
}
}
}
此代码或多或少直接取自 this tutorial.
最佳答案
在 SDK 1.2.5 版中添加了对情感的支持。 Source
在 1.4.3 版发布之前,您应该使用 1.4.1 版。
关于java - Microsoft Face API(Android)中缺少属性类型。如何使用 Emotion 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49869760/
我正在尝试将 Outlook API 与我的 React 应用程序集成。当我尝试使用 microsoft-graph-client 实现身份验证时,遇到以下错误。 'ImplicitMSALAuthe
我正在尝试使用 Microsoft Graph Beta API 在 Microsoft Teams 中创建 channel 。在文档中,它说 channel 实体具有属性 IsFavoriteByD
我的目标很简单。我想使用图形 API 将自动聊天消息发送到 MS Teams channel 。 这似乎是图形 API 的测试版功能,仅在 Microsoft.Graph.Beta 中可用。 我已经阅
通过委派权限获取 Teams channel 消息时(用户是团队成员): https://graph.microsoft.com/beta/teams/ {team_id}/channels/{cha
我正在使用带有 OData 端点的 Web API 和 Entity Framework 创建一个 RESTful 服务。 Microsoft.AspNet.WebApi.OData 和 Micros
我可以通过对标题和作者姓名的评估查询(以及解释查询)获得良好的结果。 但是如果我想通过 DOI 查找论文怎么办? 我可以通过扩展元数据描述(在现有搜索的属性中)获取条目的DOI信息,但是由于扩展元数据
我正在尝试通过displayName查询用户,但是在同时使用C#SDK和Graph Explorer发送请求时,我无法转义单引号。 更新:在示例中不清楚,我遇到麻烦的搜索词是I' 查询示例: http
我在使用 Microsoft fakes 的解决方案中有一个单元测试项目,当我构建它时出现以下错误。它提示无法加载的 DLL 在磁盘上。我已经打开了 Fusion 日志记录,这表明绑定(bind)成功
我想创建一个应用程序,当用户在 MS Teams 中接到电话时会收到通知。我的意思是我想在来电事件上订阅一些东西,然后根据来电信息做一些事情。这可能吗?到目前为止,我在 SDK 中没有看到任何事件。
如果我开发一个网站,它是否会以相同的方式在 IE11、Chrome、Firefox 和 edge 上运行,还是我们需要专门为 IE11 编写代码?我没有 Windows 8,因此无法在边缘浏览器上测试
我几个月前为某些收件箱创建了一些订阅,系统成功收到了有关收到电子邮件的通知,订阅也定期更新以增加到期日期。这是我的订阅列表: https://graph.microsoft.com/v1.0/subs
如果我开发一个网站,它是否会以相同的方式在 IE11、Chrome、Firefox 和 edge 上运行,还是我们需要专门为 IE11 编写代码?我没有 Windows 8,因此无法在边缘浏览器上测试
如果 Edge 在某些机器上发生崩溃,我们需要检查日志以了解发生了什么情况。 最佳答案 Microsoft Edge 实际上是一个 Windows 进程,因此您应该能够在事件查看器中查看日志。此外,您
我已经将一些测试用例与项目中的单元测试相关联。该项目已构建并复制到共享上的放置位置。当我去运行这些测试时,由于作为这些测试的一部分包含的非托管 DLL 的 System.DllNotFoundExce
我对 asp.net 核心标识中的三个包感到困惑。我不知道彼此之间有什么区别。还有哪些是我们应该使用的? 我在 GitHub 上找到了这个链接,但我没有找到。 Difference between M
在我的 Windows 类库(由 MVC 网站使用)中,我安装了 NugetPackage Microsoft.SqlServer.Types (Spatial)。 现在,我正在使用 ado.net
我有一个简单的 web 应用程序,我在 Teams 中显示为一个应用程序。我已经在 App Studio 中进行了设置,一切都按我的预期工作,一切都很好。它正在显示我的网络应用程序,这就是我想要的。
有什么不同?它们都是业务管理解决方案。他们做的一样吗?一些不同的版本?他们使用同一个平台吗? 动态 Assets 净值 Microsoft Dynamics NAV 2009 is a compreh
如何制定包含非英语字符(例如日耳曼语Umlauts)的Microsoft Graph /myOrganization/users OData查询? 例子: 我的租户中有一个名为“ThomasMülle
我想创建一个类似于乐队附带的星巴克应用程序的应用程序。我想显示条形码。我可以在云端或本地设备上将条形码生成为 JPG 图像,但我需要能够在乐队的屏幕上显示它们。到目前为止,我还没有找到使用 Band
我是一名优秀的程序员,十分优秀!