MCPcopy Create free account
hub / github.com/a7medev/react-native-ml-kit / TextMap

Function TextMap

example/src/text-recognition/TextMap.tsx:19–76  ·  view source on GitHub ↗
({
  width,
  height,
  blocks,
  showWords,
  showBlocks,
}: TextMapProps)

Source from the content-addressed store, hash-verified

17}
18
19const TextMap = ({
20 width,
21 height,
22 blocks,
23 showWords,
24 showBlocks,
25}: TextMapProps) => {
26 const screen = useWindowDimensions();
27
28 const scaledFrame = scaleFrame(width, height, screen.width);
29
30 return (
31 <>
32 {blocks.map((block, blockId) => (
33 <React.Fragment key={blockId}>
34 {showBlocks && (
35 <TouchableOpacity
36 onPress={() =>
37 Alert.alert(
38 block.text,
39 "Confidence score and rotation degree of 1st line\n\n" +
40 `Confidence score: ${getConfidenceScore(block)}\n\n` +
41 `Rotation degree: ${getRotationDegree(block)}`,
42 )
43 }
44 style={[styles.text, scaledFrame(block.frame)]}
45 />
46 )}
47
48 {showWords &&
49 block.lines.map((line, lineId) =>
50 line.elements.map((element, elementId) => {
51 const key = [blockId, lineId, elementId, element.text].join(
52 '-',
53 );
54
55 return (
56 <TouchableOpacity
57 key={key}
58 onPress={() => Alert.alert(element.text)}
59 style={[styles.text, scaledFrame(element.frame)]}
60 />
61 );
62 }),
63 )}
64 </React.Fragment>
65 ))}
66 </>
67 );
68
69 function getRotationDegree(block: TextBlock) {
70 return block.lines[0]?.rotationDegree?.toFixed(2) ?? 0;
71 }
72
73 function getConfidenceScore(block: TextBlock) {
74 return block.lines[0]?.confidenceScore?.toFixed(2) ?? 0;
75 }
76};

Callers

nothing calls this directly

Calls 3

scaleFrameFunction · 0.90
getConfidenceScoreFunction · 0.85
getRotationDegreeFunction · 0.85

Tested by

no test coverage detected