【发布时间】:2016-10-14 12:56:29
【问题描述】:
我正在使用 OpenCv 构建人脸检测应用程序。我正在处理回调 onPreviewFrame 上收到的预览帧数据。我在纵向模式下使用相机,而 onPreviewFrame 在横向模式下返回数据。我正在使用此代码旋转帧数据。
public static byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight) {
byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2];
// Rotate the Y luma
int i = 0;
for (int x = 0; x < imageWidth; x++) {
for (int y = imageHeight - 1; y >= 0; y--) {
yuv[i] = data[y * imageWidth + x];
i++;
}
}
// Rotate the U and V color components
i = imageWidth * imageHeight * 3 / 2 - 1;
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];
i--;
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x - 1)];
i--;
}
}
return yuv;
}
旋转数据后,我将字节数组转换为 OpenCv Mat。转换后,我传入 openCv 本机代码。
在横向模式下(不旋转预览数据),在处理相机预览后,我可以获得近 20 FPS。但是在纵向模式下,使用上述方法,FPS 会降低到 3 FPS。在测量rotateYUV420Degree90所花费的时间时,这种方法是罪魁祸首。
我是 OpenCv 的新手。有没有其他方法可以使用 java 代码或本机代码快速旋转预览数据。由于我的应用程序的复杂性,我不能使用 OpenCV 提供的JavaCameraView。
【问题讨论】:
标签: android opencv android-camera