本文主要给大家介绍如何在Android平台下使用多模型版本的角蜂鸟实现一个简单的多模型例子。
    //子线程中执行对应步骤代码
   int status = openDevice();
   int face_id = allocateGraphByAssets(mContext, "graph_face_SSD");
   int object_id = allocateGraphByAssets(mContext, "graph_object_SSD");
   byte[] bytes = getImage(STD, MEAN, face_id);
   float[] result_face = getResult(face_id);
   //...经过预处理bytes图像数据并转成float类型传给物体检测模型
   loadTensor(float_tensor, float_tensor.length, object_id);
   float[] result_object = getResult(object_id);
  HornedSungemFrame frame = getFrameResult(image, result_face, result_object);//整合结果显示
具体代码可以参考示例工程,本文只摘取了重要代码,其中数据的处理及业务逻辑未列出
因本文主要用到人脸检测和物体检测俩种模型,具体的解析结果可参照模型列表的详细介绍。
  int num_object = (int) object_result[0];
  if (num_object > 0) {
    for (int i = 0; i < num_object; i++) {
        HornedSungemFrame.ObjectInfo objectInfo = new HornedSungemFrame.ObjectInfo();
        int type = (int) (object_result[7 * (i + 1) + 1]);
        int x1 = (int) (object_result[7 * (i + 1) + 3] * 1280);
        int y1 = (int) (object_result[7 * (i + 1) + 4] * 720);
        int x2 = (int) (object_result[7 * (i + 1) + 5] * 1280);
        int y2 = (int) (object_result[7 * (i + 1) + 6] * 720);
        int wight = x2 - x1;
        int height = y2 - y1;
        int percentage = (int) (object_result[7 * (i + 1) + 2] * 100);
        if (type == 0) {
            continue;
        }
        if (percentage <= 55) {
            continue;
        }
        if (wight >= 1280 * 0.8 || height >= 720 * 0.8) {
            continue;
        }
        if (x1 < 0 || x2 < 0 || y1 < 0 || y2 < 0 || wight < 0 || height < 0) {
            continue;
        }
        objectInfo.setType(labels[type - 1]);
        objectInfo.setRect(new Rect(x1, y1, x2, y2));
        objectInfo.setScore(percentage);
        objectInfos.add(objectInfo);
    }
}

多模型版本处于测试阶段,如遇到问题请向我们发送电子邮件(support@hornedsungem.org)。 如有任何建议、模型需求或希望加入我们也欢迎和我们联系。