Comments (9)
#2436 (comment) made it perfect but i dont know how she made it
from react-native-vision-camera.
i managed to improve the code by using
// useTransposeFromStream.ts
/** Determines the offset & scale values to translate stream coordinates to a layouts coordinate */
const getTransposeProperties = (source: Dimension, target: Dimension) => {
const scaleRatio = Math.max(
target.width / source.width,
target.height / source.height,
);
// Represents the width and height of the stream, scaled down to fit the screen
// This is without taking into account the cut off part of the stream (to fit the screen)
const uncutDimensions = {
width: source.width * scaleRatio,
height: source.height * scaleRatio,
};
// Reprensents how much of the stream is cut off to fit the screen
const cutDimensions = {
width: (uncutDimensions.width - target.width)*(scaleRatio),
height: (uncutDimensions.height - target.height)*scaleRatio,
};
const x = {
offset: cutDimensions.width/ 2 ,
scale: scaleRatio,
};
const y = {
offset: cutDimensions.height / 2,
scale: scaleRatio,
};
// console.log("scaleRatio", scaleRatio, "uncutDimensions", uncutDimensions, "cutDimensions", cutDimensions, "x", x, "y", y);
return { x, y };
};
export const transposeFromStream = (
{ x, y, width, height }: Rectangle,
source: Dimension, // replace 'any' with the actual type of 'stream'
target: Dimension
) => {
const transposeFromStreamProperties = getTransposeProperties(source, target);
return {
x:
x * transposeFromStreamProperties.x.scale -
transposeFromStreamProperties.x.offset,
y:
y * transposeFromStreamProperties.y.scale -
transposeFromStreamProperties.y.offset,
width: width * transposeFromStreamProperties.x.scale,
height: height * transposeFromStreamProperties.y.scale,
};
};
/** Given a set of coordinates in a landscape picture, returns the corresponding coordinates for a vertical plan */
export const rotateCoordinatesToVertical = (
{ x, y }: Point,
{ height }: Dimension,
) => {
return {
x: height - y,
y: x,
};
};
export const rotateRectangleToVertical = (
rectangle: Rectangle,
frame: Dimension,
) => {
// Rotating by 90° means the width and height are swapped
const width = rectangle.height;
const height = rectangle.width;
// Rotate the top left corner coordinates
const rotatedCoordinates = rotateCoordinatesToVertical(rectangle, frame);
// The top left corner coordinates now represent the top right corner of the rectangle in the new plane
// So recalculate the new top left corner coordinates
return {
x: rotatedCoordinates.x - width,
y: rotatedCoordinates.y,
width,
height,
};
};
export type Dimension = {
width: number;
height: number;
};
export type Point = {
x: number;
y: number;
};
export type Rectangle = Point & Dimension;
from react-native-vision-camera.
WhatsApp.Video.2024-04-12.at.17.47.11.mp4
from react-native-vision-camera.
Hi @shacharcohen1997 I have follow your idea and have a same problem. and I have try like this .maybe this will have help you. Viewbox of my camera is '0 0 414 709' you can get is by using View Ref
And my useCodeScanner function is like this.
By the way I just make a test in Rect . you can try it in Polygon . Many thank for your idea
from react-native-vision-camera.
Here is my result for this detection
from react-native-vision-camera.
@shacharcohen1997 I have try to draw code Scanner Border only when detected code
const topLeftX = codesFrame.x;
const topLeftY = codesFrame.y;
const topRightX = codesFrame.x + codesFrame.width;
const topRightY = codesFrame.y;
const bottomRightX = codesFrame.x + codesFrame.width;
const bottomRightY = codesFrame.y + codesFrame.height;
const bottomLeftX = codesFrame.x;
const bottomLeftY = codesFrame.y + codesFrame.height;
const paths = [
{ d: M${topLeftX + codesFrame.width / 3} ${topLeftY} H${topLeftX} V${topLeftY + codesFrame.height / 3}
},
{ d: M${topRightX - codesFrame.width / 3} ${topRightY} H${topRightX} V${topRightY + codesFrame.height / 3}
},
{ d: M${bottomRightX - codesFrame.width / 3} ${bottomRightY} H${bottomRightX} V${bottomRightY - codesFrame.height / 3}
},
{ d: `M${bottomLeftX + codesFrame.width / 3} ${bottomLeftY} H${bottomLeftX} V${bottomLeftY
divide for 3 just my calculate the stroke width:
The Result is:
from react-native-vision-camera.
Hey I think this can be discussed on the community discordi nstead of GitHub issues.
from react-native-vision-camera.
@shacharcohen1997 I have try to draw code Scanner Border only when detected code
const topLeftX = codesFrame.x; const topLeftY = codesFrame.y; const topRightX = codesFrame.x + codesFrame.width; const topRightY = codesFrame.y; const bottomRightX = codesFrame.x + codesFrame.width; const bottomRightY = codesFrame.y + codesFrame.height; const bottomLeftX = codesFrame.x; const bottomLeftY = codesFrame.y + codesFrame.height; const paths = [ { d:
M${topLeftX + codesFrame.width / 3} ${topLeftY} H${topLeftX} V${topLeftY + codesFrame.height / 3}
}, { d:M${topRightX - codesFrame.width / 3} ${topRightY} H${topRightX} V${topRightY + codesFrame.height / 3}
}, { d:M${bottomRightX - codesFrame.width / 3} ${bottomRightY} H${bottomRightX} V${bottomRightY - codesFrame.height / 3}
}, { d: `M${bottomLeftX + codesFrame.width / 3} ${bottomLeftY} H${bottomLeftX} V${bottomLeftYdivide for 3 just my calculate the stroke width: The Result is:
can you send the full snippet or your code?
from react-native-vision-camera.
@shacharcohen1997 I have try to draw code Scanner Border only when detected code
const topLeftX = codesFrame.x; const topLeftY = codesFrame.y; const topRightX = codesFrame.x + codesFrame.width; const topRightY = codesFrame.y; const bottomRightX = codesFrame.x + codesFrame.width; const bottomRightY = codesFrame.y + codesFrame.height; const bottomLeftX = codesFrame.x; const bottomLeftY = codesFrame.y + codesFrame.height; const paths = [ { d:M${topLeftX + codesFrame.width / 3} ${topLeftY} H${topLeftX} V${topLeftY + codesFrame.height / 3}
}, { d:M${topRightX - codesFrame.width / 3} ${topRightY} H${topRightX} V${topRightY + codesFrame.height / 3}
}, { d:M${bottomRightX - codesFrame.width / 3} ${bottomRightY} H${bottomRightX} V${bottomRightY - codesFrame.height / 3}
}, { d: `M${bottomLeftX + codesFrame.width / 3} ${bottomLeftY} H${bottomLeftX} V${bottomLeftY
divide for 3 just my calculate the stroke width: The Result is:
can you send the full snippet or your code?
@shacharcohen1997 I think this well help
from react-native-vision-camera.
Related Issues (20)
- barcodeScan mask flipped view HOT 9
- 💭 Is it possible to display the front and back cameras at the same time HOT 1
- ✨ Contrast HOT 1
- _NativeCameraModule.CameraModule.getLocationPermissionStatus is not a function (it is undefined)🔧 HOT 1
- 💭 Two separate frame processors at different target FPS HOT 7
- 🐛 [AVCaptureDevice setActiveColorSpace:] Not supported - use activeFormat.supportedColorSpaces'. HOT 2
- 🐛 APK Size increase After implementing react-native-vision-camera lib double the apk size HOT 5
- 💭 Why the Photo Result Does Not Come Out in the Specified Aspect Ratio HOT 1
- 🐛 `finally` on a `Promise` stops camera on Android HOT 3
- 🐛 [V4][Android] Release crash: maxImages (6) has already been acquired HOT 1
- 🔧 Not able to build expo dev client when using any of the given frame processing plugin for OCR HOT 2
- 🐛 [Android] isActive change doesn't happen fast enough causing device/camera-already-in-use error when switching to native camera app HOT 1
- 🔧 Execution failed for task ':react-native-vision-camera:compileReleaseKotlin'. HOT 3
- 🔧 This API is provided only for React Native frameworks and not intended for general users. This API can change between minor versions in alignment with React Native frameworks and won't be considered a breaking change. HOT 10
- 💭 Android: Frameprocessor HOT 7
- 💭 Focus not work HOT 1
- 🐛 Memory leak Android HOT 6
- 💭 [iOS] Did someone manage to get to reasonable FPS with ML Kit Pose Detection (native frame processor plugin)? HOT 2
- 💭 Lifecycle methods for native frame processors HOT 5
- 💭 How to access GPS location tags in photo metadata? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-vision-camera.