gpt4 book ai didi

javascript - 在 8th Wall Web 中以灰度显示摄像头源

转载 作者:行者123 更新时间:2023-12-01 01:27:31 26 4
gpt4 key购买 nike

有没有一种简单的方法可以以灰度显示摄像头画面?
我找到了一个 QR 码扫描应用程序的示例,用于将相机纹理处理为灰度像素值数组,但我一直坚持显示灰度而不是 RGBA。

// Install a module which gets the camera feed as a UInt8Array.
XR.addCameraPipelineModule(
XR.CameraPixelArray.pipelineModule({luminance: true, width: 240, height: 320}))

// Install a module that draws the camera feed to the canvas.
XR.addCameraPipelineModule(XR.GlTextureRenderer.pipelineModule())

// Create our custom application logic for scanning and displaying QR codes.
XR.addCameraPipelineModule({
name = 'qrscan',
onProcessCpu = ({onProcessGpuResult}) => {
// CameraPixelArray.pipelineModule() returned these in onProcessGpu.
const { pixels, rows, cols, rowBytes } = onProcesGpuResult.camerapixelarray
const { wasFound, url, corners } = findQrCode(pixels, rows, cols, rowBytes)
return { wasFound, url, corners }
},
onUpdate = ({onProcessCpuResult}) => {
// These were returned by this module ('qrscan') in onProcessCpu
const {wasFound, url, corners } = onProcessCpuResult.qrscan
if (wasFound) {
showUrlAndCorners(url, corners)
}
},
})

最佳答案

如果您想向相机提要添加自定义视觉处理,您可以向 GlTextureRenderer 提供自定义片段着色器:

const luminanceFragmentShader =
'precision mediump float;\n' +
'varying vec2 texUv;\n' +
'uniform sampler2D sampler;\n' +
'void main() {\n' +
' vec4 color = texture2D(sampler, texUv);\n' +
' vec3 lum = vec3(0.299, 0.587, 0.114);\n' +
' gl_FragColor = vec4(vec3(dot(color.rgb, lum)), color.a);\n' +
'}\n'

然后,您可以将其作为输入提供给渲染相机源的管道模块:

XR.addCameraPipelineModule(
XR.GlTextureRenderer.pipelineModule(
{
fragmentSource: luminanceFragmentShader
}
)
)

关于javascript - 在 8th Wall Web 中以灰度显示摄像头源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53627412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com