繁体   English   中英

无法在 React-Native 中检测到的人脸上绘制边界框

[英]Unable to draw bounding box on detected face in React-Native

我正在尝试在脸上绘制边界框,但 CSS 存在一些问题,显示以下错误:

[269,"RCTView",281,{"position":"absolute","borderWidth":2,"borderColor":-65536,"left":"<<NaN>>","top":"<<NaN>>","width":"<<NaN>>","height":"<<NaN>>"}] is not usable as a native method argument

错误来源的边界框样式:

  bbox: {
    position: "absolute",
    borderWidth: 2,
    borderColor: "red"
  },

在面部渲染边界框的函数:

  const previewLeft = 40;
  const previewTop = 50;
  const previewWidth = 350;
  const previewHeight = 600;
  const tensorDims = { height: 224, width: 224, depth: 3 };


  const renderBoundingBoxes = () => {
    const { faces } = modelFaces;
    const tensorDims = { height: 300, width: 400 };
    const scale = {
      height: styles.camera.height / tensorDims.height,
      width: styles.camera.width / tensorDims.width
    };
    const flipHorizontal = Platform.OS === "ios" ? false : true;
    if (!isEmpty(faces)) {
      return faces.map((face, i) => {
        const { topLeft, bottomRight } = face;
        const bbLeft = topLeft[0] * scale.width;
        const boxStyle = Object.assign({}, styles.bbox, {
          left: flipHorizontal
            ? previewWidth - bbLeft - previewLeft
            : bbLeft + previewLeft,
          top: topLeft[1] * scale.height + 20,
          width: (bottomRight[0] - topLeft[0]) * scale.width,
          height: (bottomRight[1] - topLeft[1]) * scale.height
        });

        return <View style={boxStyle} key={`face${i}`}></View>;
        1;
      });
    }
  };

RenderBoundingBoxes 被调用:

    <View>
      <TensorCamera
        style={styles.camera}
        type={type}
        cameraTextureHeight={textureDims.height}
        cameraTextureWidth={textureDims.width}
        resizeHeight={tensorDims.height}
        resizeWidth={tensorDims.width}
        resizeDepth={tensorDims.depth}
        onReady={images => handleCameraStream(images)}
        autorender={AUTORENDER}
      />
      {renderBoundingBoxes()}
   </View>

我犯了一个错误,bottomRight 和 topLeft 不是数组而是张量对象。 我需要先使用 tf.dataSync() 下载张量,然后访问其中的数组:

  const renderBoundingBoxes = () => {
    const { faces } = modelFaces;
    const scale = {
      height: styles.camera.height / tensorDims.height,
      width: styles.camera.width / tensorDims.width
    };
    const flipHorizontal = Platform.OS === "ios" ? false : true;
    if (!isEmpty(faces)) {
      return faces.map((face, i) => {
        const { topLeft, bottomRight } = face;
        const bbLeft = topLeft.dataSync()[0] * scale.width;
        const boxStyle = Object.assign({}, styles.bbox, {
          left: flipHorizontal
            ? previewWidth - bbLeft - previewLeft
            : bbLeft + previewLeft,
          top: topLeft.dataSync()[1] * scale.height + 20,
          width:
            (bottomRight.dataSync()[0] - topLeft.dataSync()[0]) * scale.width,
          height:
            (bottomRight.dataSync()[1] - topLeft.dataSync()[1]) * scale.height
        });

        return <View style={boxStyle}></View>;
        1;
      });
    }
  };



暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM