HarmonyOS 相机双路预览,通过ImageReceiver 接收预览流后,怎么获取预览流的角度

HarmonyOS 相机双路预览,通过ImageReceiver 接收预览流渲染后,图像的角度不正确,是横向的,camera预览流中怎么设置图像角度,ImageReceiver中怎么获取接受的预览流的图像角度。

HarmonyOS
2024-11-11 11:41:25
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

​目前双路预览流角度固定前置摄像头预览得到的YUV数据顺时针旋转了90度,后置摄像头得到的YUV数据顺时针旋转了270度。目前没有系统接口可以获取视频帧方向,可以自己通过YUV数据进行旋转操作。

旋转操作可以参考:​

private byte[] rotateYUVDegree270(byte[] data, int imageWidth, int imageHeight) { 
  byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2]; 
  // Rotate the Y luma 
  int i = 0; 
  for (int x = imageWidth - 1; x >= 0; x--) { 
    for (int y = 0; y < imageHeight; y++) { 
      yuv[i] = data[y * imageWidth + x]; 
      i++; 
    } 
  }// Rotate the U and V color components 
  i = imageWidth * imageHeight; 
  for (int x = imageWidth - 1; x > 0; x = x - 2) { 
    for (int y = 0; y < imageHeight / 2; y++) { 
      yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x - 1)]; 
      i++; 
      yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x]; 
      i++; 
    } 
  } 
  return yuv; 
}

对于前置摄像头的数据还需要进行镜像翻转的操作:

private byte[] rotateYUVDegree270(byte[] data, int imageWidth, int imageHeight) { 
  byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2]; 
  // Rotate the Y luma 
  int i = 0; 
  for (int x = imageWidth - 1; x >= 0; x--) { 
    for (int y = 0; y < imageHeight; y++) { 
      yuv[i] = data[y * imageWidth + x]; 
      i++; 
    } 
  }// Rotate the U and V color components 
  i = imageWidth * imageHeight; 
  for (int x = imageWidth - 1; x > 0; x = x - 2) { 
    for (int y = 0; y < imageHeight / 2; y++) { 
      yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x - 1)]; 
      i++; 
      yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x]; 
      i++; 
    } 
  } 
  return yuv; 
}
分享
微博
QQ
微信
回复
2024-11-11 16:51:45
相关问题
HarmonyOS GL封装相机预览角度咨询
394浏览 • 1回复 待解决
如何连续获取相机预览数据
957浏览 • 1回复 待解决
如何实现预览+录制功能
1268浏览 • 1回复 待解决
如何解决预览黑屏问题
1400浏览 • 1回复 待解决