在乐器陪练场景中,学生端可能会配置鱼眼镜头,用于让教师看到学生的弹奏动作。但是鱼眼镜头拍摄的画面存在失真。你可以使用声网 API 对鱼眼镜头的画面进行畸变矫正和分离显示处理,帮助教师在教学过程中更好地演示和纠正学生的弹奏动作。
你可以通过以下步骤进行鱼眼镜头画面畸变校正。声网建议在学生端进行鱼眼镜头画面校正操作。
根据镜头的实际情况,设置鱼眼镜头画面矫正参数。
// 鱼眼镜头画面矫正参数。
FishCorrectionParams config = new FishCorrectionParams();
// xCenter 和 yCenter 代表鱼眼图像处理的中心位置。取值范围 [0.4, 0.6]。
config.xCenter = 0.5;
config.yCenter = 0.5;
// 鱼眼镜头成像的区域大小。取值范围 [1, 5]。
config.scaleFactor = 2;
// 镜头焦距。取值范围 [20, 40]。
config.focalLength = 28;
// 标定鱼眼镜头的参数,通过镜头焦距计算。取值范围 [20, 40]。
config.polFocalLength = 31;
// 鱼眼校正效果切分高度。取值范围 [0, 1]。在切分线以上的画面有鱼眼校正效果,在切分线以下的画面无鱼眼校正效果。
config.splitHeight = 0.469;
// 镜头的一组参数,通过多项式拟合得到。不同类型的鱼眼镜头会有不同的值。
config.ss[0] = 0.8327;
config.ss[1] = 0.0;
config.ss[2] = -0.5536;
config.ss[3] = 0.4999;
config.ss[4] = -0.5590;
调用 enableFishCorrection
开启鱼眼镜头画面矫正。
mRtcEngine.enableFishCorrection(true, config);
你可以通过以下步骤进行画面分离。声网建议在教师端进行画面分离操作,分离后的画面再传回学生端。
调用 enableVideoMultiRenderer
启用多重渲染。
// 必须在调用 setupRemoteVideo、setupLocalVideo、setLocalVideoMirrorMode、setRemoteRenderMode、setLocalRenderMode 之前调用该方法
mRtcEngine.enableVideoMultiRenderer(true);
调用 setupLocalVideo
和 setupRemoteVideo
分别增加本地和远端的渲染视图。
VideoCanvas canvas = new VideoCanvas();
// 设置渲染的视频源
canvas.sourceType = VIDEO_SOURCE_CAMERA_PRIMARY;
canvas.crop = new VideoCanvas.Crop();
// 设置裁剪后出现在渲染区域的图像
canvas.crop.xPoint = 100;
canvas.crop.yPoint = 100;
canvas.crop.width = 400;
canvas.crop.height = 400;
// 增加本地渲染视图
mRtcEngine.setupLocalVideo(canvas, VIDEO_VIEW_SETUP_ADD);
// 增加远端渲染视图
mRtcEngine.setupRemoteVideo(canvas, VIDEO_VIEW_SETUP_ADD);
public abstract int enableFishCorrection(boolean enable, FishCorrectionParams config);
开启或关闭鱼眼镜头画面畸变矫正。
参数 | 说明 |
---|---|
enabled | 是否开启鱼眼镜头画面矫正。
|
config | 畸变矫正参数。详见 FishCorrectionParams 。 |
public abstract int enableVideoMultiRenderer(boolean enabled);
开启或关闭多渲染功能。
参数 | 说明 |
---|---|
enabled | 是否开启多渲染功能。
|
public abstract int setupLocalVideo(VideoCanvas local, Constants.VideoViewSetupMode mode);
(多渲染功能)设置本地渲染画面。
参数 | 说明 |
---|---|
local | 视频渲染画布。详见 VideoCanvas 。 |
mode | 视频渲染模式。详见 VideoViewSetupMode 。 |
public abstract int setupRemoteVideo(VideoCanvas remote, Constants.VideoViewSetupMode mode);
(多渲染功能)设置远端渲染画面。
参数 | 说明 |
---|---|
remote | 视频渲染画布。详见 VideoCanvas 。 |
mode | 视频渲染模式。详见 VideoViewSetupMode 。 |
public abstract int setupRemoteVideoEx(
VideoCanvas canvas, Constants.VideoViewSetupMode mode, RtcConnection connection)
(多频道场景)设置远端渲染画面。
参数 | 说明 |
---|---|
remote | 视频渲染画布。详见 VideoCanvas 。 |
mode | 视频渲染模式。详见 VIDEO_VIEW_SETUP_MODE 。 |
connection | Connection 信息。详见 RtcConnection。 |
public class FishCorrectionParams {
public float xCenter;
public float yCenter;
public float scaleFactor;
public float focalLength;
public float polFocalLength;
public float splitHeight;
public float ss[] = new float[5];
public FishCorrectionParams() {
this.xCenter = 0.49f;
this.yCenter = 0.48f;
this.scaleFactor = 4.5f;
this.focalLength = 31.0f;
this.polFocalLength = 31.0f;
this.splitHeight = 1.0f;
this.ss[0] = 0.9375f;
this.ss[1] = 0.0f;
this.ss[2] = -2.9440f;
this.ss[3] = 5.7344f;
this.ss[4] = -4.4564f;
}
public FishCorrectionParams(float xCenter, float yCenter, float scaleFactor, float focalLength,
float polFocalLength, float splitHeight, float ss[]) {
this.xCenter = xCenter;
this.yCenter = yCenter;
this.scaleFactor = scaleFactor;
this.focalLength = focalLength;
this.polFocalLength = polFocalLength;
this.splitHeight = splitHeight;
this.ss[0] = ss[0];
this.ss[1] = ss[1];
this.ss[2] = ss[2];
this.ss[3] = ss[3];
this.ss[4] = ss[4];
}
@CalledByNative
float getXCenter() {
return xCenter;
}
@CalledByNative
float getYCenter() {
return yCenter;
}
@CalledByNative
float getScaleFactor() {
return scaleFactor;
}
@CalledByNative
float getFocalLength() {
return focalLength;
}
@CalledByNative
float getPolFocalLength() {
return polFocalLength;
}
@CalledByNative
float getSplitHeight() {
return splitHeight;
}
@CalledByNative
float[] getSS() {
return ss;
}
}
鱼眼镜头画面畸变校正参数。
参数 | 说明 |
---|---|
xCenter | 鱼眼图像处理的中心位置 X 坐标。取值范围 [0.4, 0.6]。 |
yCenter | 鱼眼图像处理的中心位置 Y 坐标。取值范围 [0.4, 0.6]。 |
scaleFactor | 鱼眼镜头成像的区域大小。取值范围 [1, 5]。1 为镜头最内圈,5 为镜头最外圈。 |
focalLength | 镜头焦距。取值范围 [20, 40]。 |
polFocalLength | 标定鱼眼镜头的参数,通过镜头焦距计算。取值范围 [20, 40]。 |
splitHeight | 鱼眼校正效果切分高度。取值范围 [0, 1]。在切分线以上的画面有鱼眼校正效果,在切分线以下的画面无鱼眼校正效果。 |
ss[5] | 镜头的一组参数,通过多项式拟合得到。不同类型的鱼眼镜头会有不同的值。 |
public static class Crop {
public int left;
public int top;
public int width;
public int height;
@CalledByNative("Crop")
int getLeft() {
return left;
}
@CalledByNative("Crop")
int getTop() {
return top;
}
@CalledByNative("Crop")
int getWidth() {
return width;
}
@CalledByNative("Crop")
int getHeight() {
return height;
}
}
需要截取的视频画面区域。参数使用屏幕坐标系,原点在屏幕左上角(0, 0)。
参数 | 说明 |
---|---|
参数 | 说明 |
left | 屏幕坐标系中图像左上角顶点的 X 坐标。单位为像素。 |
top | 屏幕坐标系中图像左上角顶点的 Y 坐标。单位为像素。 |
width | 以图像左上角顶点为起始点,截取画面的宽度。单位为像素。 |
height | 以图像左上角顶点为起始点,截取画面的高度。单位为像素。 |
图像的截取方式如下图所示: