-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Hello, I'm trying to extract RGB channels from each frame and I need to get mean and stdDev for each channel. my processFrame function is pretty straightforward but I can't figure out why is not working and what I'm doing wrong.
I'm using expo@53 with react-native@0.79.6
`
const processFrame = useFrameProcessor(async (frame) => {
"worklet";
const enough = measurements.value.length >= 450; // 15 seconds at 30 fps
if (enough) {
await stopMeasurements();
return;
}
const height = frame.height / 2;
const width = frame.width / 2;
const resized = resize(frame, {
scale: {
width: width,
height: height,
},
pixelFormat: "rgb",
dataType: "uint8",
});
// Convert buffer to Mat
const source = OpenCV.bufferToMat("uint8", height, width, 3, resized);
// Split into RGB channels
const red = OpenCV.createObject(ObjectType.Mat, height, width, DataTypes.CV_8U);
const green = OpenCV.createObject(ObjectType.Mat, height, width, DataTypes.CV_8U);
const blue = OpenCV.createObject(ObjectType.Mat, height, width, DataTypes.CV_8U);
OpenCV.invoke("extractChannel", source, red, 0);
OpenCV.invoke("extractChannel", source, green, 1);
OpenCV.invoke("extractChannel", source, blue, 2);
const redMeanScalar = OpenCV.invoke("mean", red);
const greenMeanScalar = OpenCV.invoke("mean", green);
const blueMeanScalar = OpenCV.invoke("mean", blue);
const redMean = OpenCV.toJSValue(redMeanScalar);
const greenMean = OpenCV.toJSValue(greenMeanScalar).a;
const blueMean = OpenCV.toJSValue(blueMeanScalar).a;
console.log({ redMean, greenMean, blueMean });
OpenCV.clearBuffers();
}, []);
`
and this is my Camera component:
<Camera device={device} format={format} fps={30} isActive={active} style={styles.camera} torch={torch} frameProcessor={processFrame} pixelFormat={"rgb"} />
tried to inspect FOCV_Function.cpp but the invocation of open cv is pretty linear cv::meanStdDev(*src, *mean, *stddev, *mask);
any idea?