recognizeImageRemote

Import

import {
  PassioSDK,
  type PassioAdvisorFoodInfo,
  type PassioFoodDataInfo,
} from '@passiolife/nutritionai-react-native-sdk-v3'

import { launchImageLibrary } from 'react-native-image-picker'
 
  /**
   * Retrieving food info using image uri,
   * Smaller resolutions will result in faster response times
   * while higher resolutions should provide more accurate results
   * @param imageUri - The local URI of the image.
   * @param message - An optional message to indicate the context of the image.
   * @param resolution - enables the caller to set the target resolution of the image uploaded to the server, Default is RES_512
   * @returns A `Promise` resolving to an array of `PassioAdvisorFoodInfo`.
   */

  recognizeImageRemote(
    imageUri: string,
    message?: string,
    resolution?: PassioImageResolution
  ): Promise<PassioAdvisorFoodInfo[] | null>

Example

It's return PassioAdvisorFoodInfo[]

 const onScanImage = useCallback(async () => {
    try {
      const { assets } = await launchImageLibrary({ mediaType: 'photo' })
      if (assets) {
        setLoading(true)
        setPassioSpeechRecognitionModel(null)
        PassioSDK.recognizeImageRemote(
          assets?.[0].uri?.replace('file://', '') ?? ''
        )
          .then(async (candidates) => {
            setPassioSpeechRecognitionModel(candidates)
          })
          .catch(() => {
            Alert.alert('Unable to recognized this image')
          })
          .finally(() => {
            setLoading(false)
          })
      }
    } catch (err) {
      setLoading(false)
    }
  }, [])

Last updated