gev2002 / react-native-vision-camera-v3-text-recognition

https://www.npmjs.com/package/react-native-vision-camera-v3-text-recognition
MIT License
19 stars 6 forks source link

Better TypeScript + `runAtTargetFps` Support #2

Closed thongquach closed 6 months ago

thongquach commented 6 months ago

Hi, I appreciate your effort in creating this plugin. Nonetheless, I'm using https://github.com/francesco-clementi-92/vision-camera-ocr-plugin and trying to migrate to this plugin since I encountered some bugs on Android and that library is no longer maintained. Unfortunately:

My current code with TS and scanOCR:

  const calculateCameraHeightWorklet = Worklets.createRunInJsFn(
    (frame: Frame) => {
      calculateCameraHeight({
        frame,
        cameraWidth: deviceWidth,
        setCameraHeight,
      })
    }
  )

  const scanContainerInfoWorklet = Worklets.createRunInJsFn(
    (frame: Frame, ocrFrame: OCRFrame) => {
      scanContainerInfo({
        frame,
        ocrFrame,
        setContainerInfo,
      })
    }
  )

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet'

    runAtTargetFps(2, () => {
      'worklet'
      calculateCameraHeightWorklet(frame)
      const ocrFrame = scanOCR(frame)
      scanContainerInfoWorklet(frame, ocrFrame)
    })
  }, [])

Thanks a lot for any support!

pedrol2b commented 6 months ago

Hey, so about the runAtTargetFps the src/index.tsx only exports the JSX Camera but you can access the scanText function just by importing it with import { scanText } from 'react-native-vision-camera-v3-text-recognition/src/scanText'

I made a previous implementation of this library which i did use runAtTargetFps on my frameprocesor along with this plugin https://github.com/pedrol2b/example-v3-text-recognition/blob/main/App.tsx

I'm opening an PR for @gev2002 for both text-recognition and barcode-scanner which exposed the scan methods until then hope this quick hack helps you

pedrol2b commented 6 months ago

Opened a PR #3 #6

gev2002 commented 6 months ago

Hi, I appreciate your effort in creating this plugin. Nonetheless, I'm using https://github.com/francesco-clementi-92/vision-camera-ocr-plugin and trying to migrate to this plugin since I encountered some bugs on Android and that library is no longer maintained. Unfortunately:

  • The types seems not to be precise. For example, callback is defined as a function. Maybe we can be more specific about the input of that function. We can based on OCRFrame of that library.
  • In my case, I need to run the frame processor only at 2fps with runAtTargetFps. Nonetheless, this cannot be done since your library does not expose scanText pure version without worklet, can you expose that? For example, in that library, it is scanOCR.

My current code with TS and scanOCR:

  const calculateCameraHeightWorklet = Worklets.createRunInJsFn(
    (frame: Frame) => {
      calculateCameraHeight({
        frame,
        cameraWidth: deviceWidth,
        setCameraHeight,
      })
    }
  )

  const scanContainerInfoWorklet = Worklets.createRunInJsFn(
    (frame: Frame, ocrFrame: OCRFrame) => {
      scanContainerInfo({
        frame,
        ocrFrame,
        setContainerInfo,
      })
    }
  )

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet'

    runAtTargetFps(2, () => {
      'worklet'
      calculateCameraHeightWorklet(frame)
      const ocrFrame = scanOCR(frame)
      scanContainerInfoWorklet(frame, ocrFrame)
    })
  }, [])

Thanks a lot for any support!

Hey ! I merge @pedrol2b request. Now you can import scanText and create your Worklets core.

thongquach commented 6 months ago

Thanks @pedrol2b @gev2002 for your very quick support <3 I'll try it out.