【问题标题】:Determining Camera Texture确定相机纹理
【发布时间】:2021-07-08 18:43:04
【问题描述】:

在试图找出适用于 Android 设备的问题时被卡住了一段时间。 tensorFlow.js library 中的示例代码表明,必须凭经验确定相机的分辨率。对于 iphone,它在各个版本中相对一致(仅针对版本 6 及更高版本进行更改),但是 android 手机如此多样化,我需要找出一种自动确定它的方法。当分辨率不正确时,身体扫描应用程序中用于指代身体不同部位的航点位于错误的位置(例如:头部靠近肩膀)。有没有人有提示找到解决方案?许多资源只是将它们称为幻数。我还联系了一个有类似问题的人,他有no response

import { Camera } from 'expo-camera';
import { cameraWithTensors } from '@tensorflow/tfjs-react-native';

const TensorCamera = cameraWithTensors(Camera);

class MyComponent {

  handleCameraStream(images, updatePreview, gl) {
    const loop = async () => {
      const nextImageTensor = images.next().value

      //
      // do something with tensor here
      //

      // if autorender is false you need the following two lines.
      // updatePreview();
      // gl.endFrameEXP();

      requestAnimation(loop);
    }
    loop();
  }

  render() {
   // Currently expo does not support automatically determining the
   // resolution of the camera texture used. So it must be determined
   // empirically for the supported devices and preview size.

   let textureDims;
   if (Platform.OS === 'ios') {
    textureDims = {
      height: 1920,
      width: 1080,
    };
   } else {
    textureDims = {
      height: 1200,
      width: 1600,
    };
   }

   return <View>
     <TensorCamera
      // Standard Camera props
      style={styles.camera}
      type={Camera.Constants.Type.front}
      // Tensor related props
      cameraTextureHeight={textureDims.height}
      cameraTextureWidth={textureDims.width}
      resizeHeight={200}
      resizeWidth={152}
      resizeDepth={3}
      onReady={this.handleCameraStream}
      autorender={true}
     />
   </View>
  }
}

【问题讨论】:

    标签: react-native tensorflow tensorflow.js


    【解决方案1】:

    textureDims 还取决于用户是在纵向还是横向,因此如果用户要更改设备的方向,iOS 设备的当前硬编码值将无法正常工作。

    您可以改用useWindowDimensions,但这仅适用于功能组件,不适用于类组件。

    import React, { useState } from "react";
    import { View, useWindowDimensions } from "react-native";
    
    const [textureDims, setTextureDims] = useState();
    
    const windowWidth = useWindowDimensions().width;
    const windowHeight = useWindowDimensions().height;
    
    setTextureDims({ height: windowHeight, width: windowWidth });
    
    return (
      <View>
        <TensorCamera
          // Standard Camera props
          style={styles.camera}
          type={Camera.Constants.Type.front}
          // Tensor related props
          cameraTextureHeight={textureDims.height}
          cameraTextureWidth={textureDims.width}
          resizeHeight={200}
          resizeWidth={152}
          resizeDepth={3}
          onReady={handleCameraStream}
          autorender={true}
        />
      </View>
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-23
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 2015-02-21
      • 2010-10-04
      • 2020-02-11
      相关资源
      最近更新 更多