Como executar o app para fazer detecção facial
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Executar o app que desenha caixas ao redor dos rostos detectados em uma imagem.
Mais informações
Para conferir a documentação detalhada que inclui este exemplo de código, consulte:
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[],[],null,["# Running the app for face detection\n\nRun the app that draws boxes around detected faces in an image.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Face detection tutorial](/vision/docs/face-tutorial)\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision Java API\nreference documentation](/java/docs/reference/google-cloud-vision/latest/overview).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n /** Annotates an image using the Vision API. */\n public static void main(String[] args) throws IOException, GeneralSecurityException {\n if (args.length != 2) {\n System.err.println(\"Usage:\");\n System.err.printf(\n \"\\tjava %s inputImagePath outputImagePath\\n\", FaceDetectApp.class.getCanonicalName());\n System.exit(1);\n }\n Path inputPath = Paths.get(args[0]);\n Path outputPath = Paths.get(args[1]);\n if (!outputPath.toString().toLowerCase().endsWith(\".jpg\")) {\n System.err.println(\"outputImagePath must have the file extension 'jpg'.\");\n System.exit(1);\n }\n\n FaceDetectApp app = new FaceDetectApp(getVisionService());\n List\u003cFaceAnnotation\u003e faces = app.detectFaces(inputPath, MAX_RESULTS);\n System.out.printf(\"Found %d face%s\\n\", faces.size(), faces.size() == 1 ? \"\" : \"s\");\n System.out.printf(\"Writing to file %s\\n\", outputPath);\n app.writeWithFaces(inputPath, outputPath, faces);\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision Node.js API\nreference documentation](https://googleapis.dev/nodejs/vision/latest).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n async function main(inputFile, outputFile) {\n const PImage = require('pureimage');\n outputFile = outputFile || 'out.png';\n const faces = await detectFaces(inputFile);\n console.log('Highlighting...');\n await highlightFaces(inputFile, faces, outputFile, PImage);\n console.log('Finished!');\n }\n\n### PHP\n\n\nBefore trying this sample, follow the PHP setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision PHP API\nreference documentation](/php/docs/reference/cloud-vision/latest).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n call_user_func($imageWriteFunc[$ext], $outputImage, $outFile);\n printf('Output image written to %s' . PHP_EOL, $outFile);\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision Python API\nreference documentation](/python/docs/reference/vision/latest).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def main(input_filename, output_filename, max_results):\n with open(input_filename, \"rb\") as image:\n faces = detect_face(image, max_results)\n print(\"Found {} face{}\".format(len(faces), \"\" if len(faces) == 1 else \"s\"))\n\n print(f\"Writing to file {output_filename}\")\n # Reset the file pointer, so we can read the file again\n image.seek(0)\n highlight_faces(image, faces, output_filename)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=vision)."]]