All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.demo.index.html Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version




  
  
  
  
  
  
  


  

FaceApi

该demo示例完成了前端的两种请求方式实现数据交互:

1、通过基于RESTful HTTP请求封装的ajax(jQuery)实现数据交互点击此处,预览demo

2、通过Apache Thrift Javascript client(jQuery)实现数据交互点击此处,预览demo

demo中前、后端主要用到的方法调用示例:
              
// 提交照片进行人脸检测
$('.submit').click(function () {
  $.ajax({
    type: "post",
    url: http://127.0.0.1:26423 + '/FaceApi/detectFace',
    //解决跨域请求问题
    xhrFields: {
      withCredentials: true
    },
    crossDomain: true,
    contentType: "application/json",
    //参数格式
    data: JSON.stringify({
      imgData: imgCommon
    }),
    //请求成功返回的数据
    success: function (data) {
      console.log(data)
    }, 
    //请求失败返回的数据
    error: function (error) { 
      console.log(error)
    } 
  })
})
          
        
          
// 提交照片进行人脸检测
var transport = new Thrift.Transport("http://127.0.0.1:26422");
var protocol = new Thrift.Protocol(transport);
var client = new FaceApiClient(protocol);
$('.submit').click(function () {
  client.detectFace(imgBlob, function (data) {
    console.log(data)
  }).fail(function (jqXHR, status, error) {
    console.log(jqXHR)
  })
})
          
        
      
try{
  // 创建faceapi rpc client
  FaceApiThriftClient client = new FaceApiThriftClient("127.0.0.1",26421);
  // 读取图像文件为二进制字节数组
  // byte[] imgData = ...
  // 调用检测方法
  CodeInfo[] codes = client.detectFace(imgData);
  // 输出检测到的人脸位置信息
  for(CodeInfo c:codes){
    logger.info("FRECT={}",c.getPos());
  }
}catch (IOException e) {
  e.printStackTrace();
} catch(ImageErrorException e){
  // 捕获服务端抛出的图像数据异常
  e.printStackTrace();
}catch(ServiceRuntimeException e){
  // 捕获服务端抛出的运行时异常(RuntimeException)
  e.printServiceStackTrace();
}catch(RuntimeException e){
  e.printStackTrace();
}
        
      
        
auto client = FaceApiIfClient("127.0.0.1", 26421);
try{
  // 加载图像数据为std::string
  // std::string imgData = ....
  // 调用检测方法
  auto codes = client.detectFace(imgData);
  for (auto code : *codes) {
      std::cout << *code.__get_pos() << std::endl;
  }
}
catch (net::gdface::image::ImageErrorException &e) 
{
  // 捕获服务端抛出的图像数据异常
  std::cout << e.serviceStackTraceMessage << std::endl;
}
catch (net::gdface::thrift::exception::ServiceRuntimeException &e)
{
  // 捕获服务端抛出的运行时异常(RuntimeException)
  std::cout << e.serviceStackTraceMessage << std::endl;
}
catch (std::exception& e) {
  std::cout << e.what()<< std::endl;
}
              
            




© 2015 - 2025 Weber Informatics LLC | Privacy Policy