FaceController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Http\Controllers\Common;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Vendor\BaiduAi\FaceService;
  5. use Illuminate\Http\Request;
  6. class FaceController extends Controller
  7. {
  8. /**
  9. * @param Request $request
  10. * @return array
  11. * @deprecated Common/FaceDetect
  12. */
  13. public function detect(Request $request)
  14. {
  15. $this->validate($request, [
  16. 'image' => 'required'
  17. ]);
  18. $images = $request->post('image');
  19. $fs = new FaceService();
  20. $data = $fs->detect($images, 'URL', array(
  21. 'face_field' => "quality",
  22. 'max_face_num' => 1,
  23. 'face_type' => 'LIVE'
  24. ));
  25. if (
  26. $data['error_code'] == 0
  27. && $data['result']['face_num'] > 0
  28. && $data['result']['face_list'][0]['quality']['occlusion']['left_eye'] < 0.6
  29. && $data['result']['face_list'][0]['quality']['occlusion']['right_eye'] < 0.6
  30. && $data['result']['face_list'][0]['quality']['occlusion']['nose'] < 0.7
  31. && $data['result']['face_list'][0]['quality']['occlusion']['mouth'] < 0.7
  32. && $data['result']['face_list'][0]['quality']['occlusion']['left_cheek'] < 0.8
  33. && $data['result']['face_list'][0]['quality']['occlusion']['right_cheek'] < 0.8
  34. && $data['result']['face_list'][0]['quality']['occlusion']['chin_contour'] < 0.8
  35. && $data['result']['face_list'][0]['quality']['blur'] < 0.7
  36. && $data['result']['face_list'][0]['quality']['illumination'] > 40
  37. ) {
  38. return array(
  39. 'code' => 200,
  40. 'message' => 'success',
  41. 'data' => [
  42. 'detect' => true
  43. ]
  44. );
  45. } else {
  46. return array(
  47. 'code' => 200,
  48. 'message' => 'success',
  49. 'data' => [
  50. 'detect' => false
  51. ]
  52. );
  53. }
  54. }
  55. }