Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions with-tfjs-camera/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Camera } from "expo-camera";
import { useCameraPermissions } from "expo-camera";
import React from "react";
import { Button } from 'react-native';

Expand All @@ -8,7 +8,7 @@ import { useTensorFlowLoaded } from "./src/useTensorFlow";

export default function App() {
const isLoaded = useTensorFlowLoaded();
const [permission, requestPermission] = Camera.useCameraPermissions();
const [permission, requestPermission] = useCameraPermissions();

if (!permission?.granted) {
return (
Expand All @@ -17,7 +17,7 @@ export default function App() {
</LoadingView>
);
}

if (!isLoaded) {
return <LoadingView message="Loading TensorFlow" />;
}
Expand Down
4 changes: 2 additions & 2 deletions with-tfjs-camera/src/CustomTensorCamera.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cameraWithTensors } from '@tensorflow/tfjs-react-native';
import { Camera } from 'expo-camera';
import { CameraView } from 'expo-camera';
import React from 'react';

const TEXTURE_SIZE = { width: 1080, height: 1920 };
Expand All @@ -13,7 +13,7 @@ const TENSOR_SIZE = {
height: TENSOR_WIDTH * CAMERA_RATIO,
};

const TensorCamera = cameraWithTensors(Camera);
const TensorCamera = cameraWithTensors(CameraView);

export function CustomTensorCamera({ style, width, ...props }) {
const sizeStyle = React.useMemo(() => {
Expand Down
11 changes: 7 additions & 4 deletions with-tfjs-camera/src/ModelView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as mobilenet from '@tensorflow-models/mobilenet';
import { Camera } from 'expo-camera';
import React from 'react';
import { StyleSheet, useWindowDimensions, View } from 'react-native';

Expand All @@ -11,18 +10,23 @@ import { useTensorFlowModel } from './useTensorFlow';
export function ModelView() {
const model = useTensorFlowModel(mobilenet);
const [predictions, setPredictions] = React.useState([]);
const [facing, setFacing] = React.useState("front")

if (!model) {
return <LoadingView message="Loading TensorFlow model" />;
}

const toggleCameraFacing = () => {
setFacing((prev) => prev === "front" ? "back" : "front")
}

return (
<View
style={{ flex: 1, backgroundColor: "black", justifyContent: "center" }}
>
<PredictionList predictions={predictions} />
<View style={{ borderRadius: 20, overflow: "hidden" }}>
<ModelCamera model={model} setPredictions={setPredictions} />
<ModelCamera model={model} setPredictions={setPredictions} facing={facing} />
</View>
</View>
);
Expand Down Expand Up @@ -50,13 +54,12 @@ function ModelCamera({ model, setPredictions }) {
},
[setPredictions]
);

return React.useMemo(
() => (
<CustomTensorCamera
width={size.width}
style={styles.camera}
type={Camera.Constants.Type.back}
facing="front"
onReady={onReady}
autorender
/>
Expand Down