1.0.1 ā€¢ Published 5 months ago

object-based-positioning v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Object Based Positioning Library

React Native Expo TensorFlow TypeScript

!NOTE Summary: Prototype mechanism for achieving user positioning in indoor spaces using object recognition and detection models. This library works exclusively with React Native and Expo. A concrete implementation using Firebase to store data is presented, although other mechanisms could be used.

šŸŒŸ Introduction

This library is presented as a concrete implementation aimed at enabling a proof of concept. The library allows for positioning users in indoor spaces using various object recognition models. To achieve positioning, there are two stages involved. In the first stage, the user needs to use their phone's camera to scan the environment, recording different objects present in the space. These "points of interest" can then be accessed in the second stage, providing contextual information or services to other users.

šŸ”‘ Key Features

šŸŸ¢ Real-time object detection and classification. šŸ“ Indoor positioning using object recognition models. āš™ļø Easy integration with React Native and Expo. šŸ”§ Configurable detection settings and model options.

šŸ“š Table of Contents

  1. šŸŒŸ Introduction
  2. šŸ”‘ Key Features
  3. šŸ“– Documentation

šŸ“– Documentation

BaseObjectBasedPositioning class

Method NameDescriptionParametersReturns
setCurrentModelSet the current model.model: MODELvoid
addCustomModelAdd a new custom model.model: string, component: anyvoid
getCurrentModelGet the current model.NoneMODEL
getReactCameraComponentGet the React component for the current model.NoneReact.LazyExoticComponent<any>
setCurrentPositioningMethodSet the current positioning method.method: POSITIONING_METHODSvoid
getCurrentPositioningMethodGet the current positioning method.NonePOSITIONING_METHODS
getCurrentPositioningMethodClassGet the current positioning method class.NoneBasePositioning
getCurrentPositionGet the current position using the current positioning method.NonePromise<CurrentPositionResponse>
setMaxDistanceToDetectObjectsSet the maximum distance to detect objects in meters.distance: numbervoid
getMaxDistanceToDetectObjectsGet the maximum distance to detect objects in meters.Nonenumber
setMaxHeadingToDetectObjectsSet the maximum heading to detect objects in degrees.heading: numbervoid
getMaxHeadingToDetectObjectsGet the maximum heading to detect objects in degrees.Nonenumber
setDatabaseSet the database.database: anyvoid
getDatabaseGet the database.Noneany
onRegisterObjectRegister a new object in the database. (Abstract method, to be implemented)object: TensorCameraResult, extra?: anyPromise<void>
onUnregisterObjectUnregister an object from the database. (Abstract method, to be implemented)id: stringPromise<void>
getRegisteredObjectsGet all registered objects. (Abstract method, to be implemented)conditions: anyPromise<any>
getNearbyObjectsGet all nearby objects. (Abstract method, to be implemented)NonePromise<any>

FirebaseObjectBasedPositioning class

FirebaseObjectBasedPositioning is a class that extends the functionality of BaseObjectBasedPositioning to provide an indoor positioning mechanism based on storing and managing data in Firebase. This class allows you to register and unregister objects in a Firestore database, retrieve registered objects, and get nearby objects based on the user's current position.

Method NameDescriptionParametersReturns
getCollectionNameGet the collection name.Nonestring
getCollectionGet the collection reference.NoneCollectionReference<FirebaseObject, DocumentData>
onRegisterObjectRegister a new object in the database.objectData: TensorCameraResult, extraData: Record<string, any>Promise<void>
onUnregisterObjectDelete an object in the database by its ID.id: stringPromise<void>
getRegisteredObjectsGet all registered objects in Firebase based on conditions.conditions: QueryConstraint \| QueryNonFilterConstraintPromise<FirebaseObject[]>
getNearbyObjectsGet all nearby objects based on the current position and configured limits.NonePromise<FirebaseObject[]>

Create an instance

import { Firestore } from 'firebase/firestore';
import { FirebaseObjectBasedPositioning } from './path/to/FirebaseObjectBasedPositioning';

// Initialize Firestore (make sure to replace with your own configuration)
const firestore: Firestore = ...; // Your Firestore initialization here

// Create an instance of FirebaseObjectBasedPositioning
const positioning = new FirebaseObjectBasedPositioning(firestore);

Changing default settings

// Change the default collection name
positioning.setCollectionName('new-collection-name');

// Change the current object detection model
positioning.setCurrentModel('mobilenet v2');

// Add a custom model
const CustomModelComponent = React.lazy(() => import('../components/CustomModelCamera'));
positioning.addCustomModel('custom-model', CustomModelComponent);

// Change the current positioning method
positioning.setCurrentPositioningMethod('custom-positioning-method');

// Set the maximum distance to detect objects
positioning.setMaxDistanceToDetectObjects(20); // 20 meters

// Set the maximum heading to detect objects
positioning.setMaxHeadingToDetectObjects(90); // 90 degrees

Registering new object

// Example of registering an object
const tensorCameraResult = { /* TensorCameraResult data here */ };
const extraData = { /* Any extra data here */ };

positioning.onRegisterObject(tensorCameraResult, extraData)
  .then(() => {
    console.log('Object registered successfully.');
  })
  .catch((error) => {
    console.error('Error registering object:', error);
  });

Unregistering existing object

// Example of unregistering an object
const objectId = '1234567890';

positioning.onUnregisterObject(objectId)
  .then(() => {
    console.log('Object unregistered successfully.');
  })
  .catch((error) => {
    console.error('Error unregistering object:', error);
  });

Retriving objects

// Example of getting all registered objects with some condition
const conditions = { /* Your conditions here */ };

positioning.getRegisteredObjects(conditions)
  .then((objects) => {
    console.log('Registered objects:', objects);
  })
  .catch((error) => {
    console.error('Error getting registered objects:', error);
  });

// Example of getting nearby objects
positioning.getNearbyObjects()
  .then((nearbyObjects) => {
    console.log('Nearby objects:', nearbyObjects);
  })
  .catch((error) => {
    console.error('Error getting nearby objects:', error);
  });

Get React Component

!NOTE More information about these Components can be found here.

The documentation presents a collection of React components available for real-time object detection and classification using pre-trained TensorFlow.js models. These components are designed to seamlessly integrate into React Native applications and leverage the device's camera capabilities to detect and classify a variety of objects. Each component provides a straightforward interface for configuring and receiving detection or classification results. They allow the phone's camera to view the environment and send images for processing by the object recognition model, making it easy to integrate into existing projects and customize according to specific application needs.

// Change the current object detection model
positioning.setCurrentModel('mobilenet v2');

// Get Camera Component for Mobilenet v2
const Component = positioning.getReactCameraComponent();

const App = () => {
  const handleNewResults = (results) => {
       console.log('New detection results:', results);
       // Your logic here
     };

  return (
    <Component
      minPrecision={25}
      numberOfFrames={150}
      onNewResults={handleNewResults}
      availableObjects={['person', 'car']}
    />
  );
}