CommonService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Services\V1;
  3. use App\Generated\V1\Messages\Common\FaceDetectMessage;
  4. use App\Services\Vendor\BaiduAi\FaceService;
  5. class CommonService
  6. {
  7. public function faceDetect(FaceDetectMessage $message)
  8. {
  9. $image = $message->getImage();
  10. $faceService = new FaceService();
  11. $data = $faceService->detect($image, 'URL', array(
  12. 'face_field' => "quality",
  13. 'max_face_num' => 1,
  14. 'face_type' => 'LIVE'
  15. ));
  16. $message->setResponse([
  17. 'detect' => $data['error_code'] == 0 && $data['result']['face_num'] > 0
  18. && $data['result']['face_list'][0]['quality']['occlusion']['left_eye'] < 0.6
  19. && $data['result']['face_list'][0]['quality']['occlusion']['right_eye'] < 0.6
  20. && $data['result']['face_list'][0]['quality']['occlusion']['nose'] < 0.7
  21. && $data['result']['face_list'][0]['quality']['occlusion']['mouth'] < 0.7
  22. && $data['result']['face_list'][0]['quality']['occlusion']['left_cheek'] < 0.8
  23. && $data['result']['face_list'][0]['quality']['occlusion']['right_cheek'] < 0.8
  24. && $data['result']['face_list'][0]['quality']['occlusion']['chin_contour'] < 0.8
  25. && $data['result']['face_list'][0]['quality']['blur'] < 0.7
  26. && $data['result']['face_list'][0]['quality']['illumination'] > 40
  27. ]);
  28. }
  29. }