Skip to content

Commit

Permalink
Use location from species nearby provider for the geomodel
Browse files Browse the repository at this point in the history
  • Loading branch information
jtklein committed Jan 8, 2025
1 parent 3c382aa commit 1fba2a8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion components/Camera/ARCamera/FrameProcessorCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Worklets } from "react-native-worklets-core";
import * as InatVision from "vision-camera-plugin-inatvision";

import { useIsForeground, useDeviceOrientation } from "../../../utility/customHooks";
import { useSpeciesNearby } from "../../Providers/SpeciesNearbyProvider";

import {
orientationPatch,
Expand Down Expand Up @@ -82,6 +83,9 @@ const FrameProcessorCamera = ( props: Props ) => {

const { deviceOrientation } = useDeviceOrientation();

const { speciesNearby } = useSpeciesNearby( );
const { latitude, longitude } = speciesNearby;

const [cameraPermissionStatus, setCameraPermissionStatus] = useState( "not-determined" );
const requestCameraPermission = useCallback( async () => {
// Checking camera permission status, if granted set it and return
Expand Down Expand Up @@ -201,6 +205,14 @@ const FrameProcessorCamera = ( props: Props ) => {

const patchedRunAsync = usePatchedRunAsync();
const patchedOrientationAndroid = orientationPatchFrameProcessor( deviceOrientation );
const hasUserLocation = latitude != null && longitude != null;
// The vision-plugin has a function to look up the location of the user in a h3 gridded world
// unfortunately, I was not able to run this new function in the worklets directly,
// so we need to do this here before calling the useFrameProcessor hook.
// For predictions from file this function runs in the vision-plugin code directly.
const location = hasUserLocation
? InatVision.lookUpLocation( { latitude, longitude } )
: null;
const frameProcessor = useFrameProcessor(
( frame ) => {
"worklet";
Expand All @@ -225,7 +237,13 @@ const FrameProcessorCamera = ( props: Props ) => {
filterByTaxonId,
negativeFilter,
patchedOrientationAndroid,
useGeomodel: hasUserLocation,
geomodelPath,
location: {
latitude: location?.latitude,
longitude: location?.longitude,
elevation: location?.elevation
}
} );
const timeAfter = Date.now();
const timeTaken = timeAfter - timeBefore;
Expand All @@ -251,7 +269,9 @@ const FrameProcessorCamera = ( props: Props ) => {
negativeFilter,
patchedOrientationAndroid,
lastTimestamp,
fps
fps,
hasUserLocation,
location
]
);

Expand Down

0 comments on commit 1fba2a8

Please sign in to comment.