Search code examples
node.jsfirebasegoogle-cloud-functionsgoogle-cloud-vision

How do i get textDetection and LabelDetection with NodeJs?


const results = await visionClient.labelDetection(imageUri).safeSearchDetection(imageUri);

i am trying to get an image response with cloud vision.


Solution

  • Solved it this way for version 0.21.0

    import * as vision from '@google-cloud/vision';
    const visionClient = new vision.ImageAnnotatorClient();
    
    const request = {
                    "image": {
                        "source": {
                            "imageUri": imageUri
                        }
                    },
                    "features": [
                        {
                            "type": "FACE_DETECTION"
                        },
                        {
                            "type": "LABEL_DETECTION"
                        },
                        {
                            "type": "SAFE_SEARCH_DETECTION"
                        },
                        {
                            "type": "WEB_DETECTION"
                        },
                        {
                            "type": "CROP_HINTS"
                        },
                        {
                            "type": "IMAGE_PROPERTIES"
                        },
                        {
                            "type": "DOCUMENT_TEXT_DETECTION"
                        },
                        {
                            "type": "TEXT_DETECTION"
                        },
                        {
                            "type": "LOGO_DETECTION"
                        },
                        {
                            "type": "LANDMARK_DETECTION"
                        },
                        {
                            "type": "TYPE_UNSPECIFIED"
                        },
                        // Other detection types here...
                    ]
            };
    
            return await visionClient.annotateImage(request).then((res) => {
                console.log(JSON.stringify(res));
            });