Я пытаюсь захватить поток с камеры, используя cameraWithTensors из tenorflow / tf js -react-native пример из https://js.tensorflow.org/api_react_native/0.2.3. Я использую вкладки реагирующих кнопок навигации (не знаю, связано ли это).
import { Camera } from 'expo-camera';
import { cameraWithTensors } from '@tensorflow/tfjs-react-native';
const TensorCamera = cameraWithTensors(Camera);
class MyComponent {
handleCameraStream(images, updatePreview, gl) {
const loop = async () => {
const nextImageTensor = images.next().value
console.log("*** This line is not logged ***");
// if autorender is false you need the following two lines.
// updatePreview();
// gl.endFrameEXP();
requestAnimation(loop);
}
loop();
}
render() {
// Currently expo does not support automatically determining the
// resolution of the camera texture used. So it must be determined
// empirically for the supported devices and preview size.
let textureDims;
if (Platform.OS === 'ios') {
textureDims = {
height: 1920,
width: 1080,
};
} else {
textureDims = {
height: 1200,
width: 1600,
};
}
return <View>
<TensorCamera
// Standard Camera props
style={styles.camera}
type={Camera.Constants.Type.front}
// Tensor related props
cameraTextureHeight={textureDims.height}
cameraTextureWidth={textureDims.width}
resizeHeight={200}
resizeWidth={152}
resizeDepth={3}
onReady={this.handleCameraStream}
autorender={true}
/>
</View>
}
}
Использование следующих модулей
react-native-cli: 2.0.1
react-native: 0.61.4
"expo-gl": "^8.1.0"
"@tensorflow/tfjs": "1.7.2",
"@tensorflow/tfjs-react-native": "^0.2.3",
"core-js": "3",
"expo": "^36.0.2",
"expo-asset": "~8.0.0",
"expo-camera": "^8.2.0",
"expo-constants": "^9.0.0",
"expo-font": "~8.0.0",
"expo-gl": "^8.1.0",
"expo-image-picker": "^8.1.0",
"expo-permissions": "^8.1.0",
"@react-native-community/async-storage": "^1.8.1",
"@react-native-community/masked-view": "0.1.5",
"@react-navigation/bottom-tabs": "^5.0.0",
"@react-navigation/native": "^5.0.0",
"@react-navigation/stack": "^5.0.0",
Пробовал на iOS симуляторе и устройстве. Функция «OnReady» не вызывается, либо в консоль записывается лог. При запуске приложения я получил следующие ошибки:
Не удалось инициализировать бэкэнд rn-webgl
Ошибка: ExponentGLObjectManager.createContextAsyn c: при инициализации безголового контекста произошла непредвиденная ошибка
Я попытался отладить собственное приложение реагировать, но не смог понять причину root. Это может быть проблемой зависимости. Когда я использую этот простой пример , он работает нормально, однако при попытке использовать тот же компонент, что и на вкладке экрана, происходит сбой.
Буду признателен, если вы объясните, как устранить эти ошибки выше.
Спасибо