docs/content/docs/a-scannedobject.mdx
import { Tab, Tabs } from 'fumadocs-ui/components/tabs'
A ScannedObject is any kind of object (like a machine readable code or a human face) scanned by a CameraObjectOutput.
ScannedObject is the base-class of all objects scanned by the CameraObjectOutput.
There are multiple subclasses of ScannedObject, such as ScannedCode (e.g. for QR codes or barcodes) or ScannedFace:
const scannedObject = ...
// [!code ++]
if (isScannedCode(scannedObject)) {
console.log(`Code: ${scannedObject.value}`)
// [!code ++]
} else if (isScannedFace(scannedObject)) {
console.log(`Face: ${scannedObject.faceID}`)
} else {
console.log(`Any Object: ${scannedObject.type}`)
}
A ScannedObject's boundingBox describes its location in the Camera's coordinate system - which ranges from 0.0 to 1.0.
Additionally, a ScannedCode exposes cornerPoints, and a ScannedFace exposes rollAngle and yawAngle, which are also relative to the Camera's coordinate system.
You can convert all ScannedObject's coordinates to a Preview View coordinate system using convertScannedObjectCoordinatesToViewCoordinates(...):
<Tabs items={["<Camera />", "<NativePreviewView />"]}> <Tab value="<Camera />">
function App() {
const camera = useRef<CameraRef>(null)
const objectOutput = useObjectOutput({
types: ['qr'],
onObjectsScanned(objects) {
for (const object of objects) {
// [!code ++:2]
const converted = camera.current
.convertScannedObjectCoordinatesToViewCoordinates(object)
}
}
})
return (
<Camera
ref={camera}
{...props}
/>
)
}
const objectOutput = useObjectOutput({ types: ['qr'], onObjectsScanned(objects) { for (const object of objects) { // [!code ++:2] const converted = preview.current .convertScannedObjectCoordinatesToViewCoordinates(object) } } })
return ( <NativePreviewView hybridRef={callback((r) => { preview.current = r })} {...props} /> ) }
</Tab>
</Tabs>