aarongrider / vision-camera-ocr

VisionCamera Frame Processor Plugin to detect text in real time using MLKit Text Detector (OCR)
MIT License
243 stars 94 forks source link

Example is not working properly #29

Open dongseobb opened 1 year ago

dongseobb commented 1 year ago

I've been using a camera before, and I'm going to introduce vision-camera-ocr for a new function. But I tried to follow the example, but it didn't work.

If you run like this, runOnJS says it can't find it, but it doesn't work.

What is the problem and how do I solve it?

[package information]

[code]


import {Camera, useCameraDevices, useFrameProcessor} from 'react-native-vision-camera';
import {runOnJS} from 'react-native-reanimated'
import { OCRFrame, scanOCR } from 'vision-camera-ocr';

const App = () => {
  const camera = useRef<any>(null); // 카메라 화면
  const devices = useCameraDevices();
  const device = devices.back; // 후면 카메라 사용
  const [ocr, setOcr] = React.useState<OCRFrame>();

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet';
    const data = scanOCR(frame);
    runOnJS(setOcr)(data);
  }, []);

  ...

  return(
    <Camera
      ref={camera}
      style={{
        height: '100%',
        width: windowWidth,
      }}
      device={device}
      isActive={showCamera}
      photo={true}
      fps={240}
      frameProcessor={frameProcessor}
    />
  )
}

[babel.config.js]

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ['babel-plugin-styled-components'],
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__scanOCR'],
      },
    ],
  ],
};
dlato97 commented 10 months ago

this package only work with react-native-vision-camera v2. If you want to use the packege whit version 3 see https://github.com/aarongrider/vision-camera-ocr/pull/32