frame widening maths, cleanup
This commit is contained in:
@ -9,7 +9,6 @@
|
|||||||
// #define debug_borders
|
// #define debug_borders
|
||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
|
|
||||||
uniform sampler2DRect myTextureY;
|
uniform sampler2DRect myTextureY;
|
||||||
uniform sampler2DRect myTextureU;
|
uniform sampler2DRect myTextureU;
|
||||||
uniform sampler2DRect myTextureV;
|
uniform sampler2DRect myTextureV;
|
||||||
@ -17,42 +16,41 @@ uniform vec2 myResolution;
|
|||||||
uniform float pts;
|
uniform float pts;
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
|
const vec2 sensor_size = vec2(5.949440, 5.205760);
|
||||||
const vec2 sensor_dimensions = vec2(5.949440, 5.205760);
|
|
||||||
const float fisheye_focal_length = 2.92;
|
|
||||||
const float rectilinear_focal_length = 2.102263;
|
|
||||||
const vec2 pixel_scale = vec2(0.871558, 1.0);
|
const vec2 pixel_scale = vec2(0.871558, 1.0);
|
||||||
const int subsampling = 4;
|
const float equidistant_focal_length = 2.920000;
|
||||||
|
const float rectilinear_focal_length = 2.102263;
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
|
const int subsampling = 4;
|
||||||
const float subsampling_step = 1.0 / float(subsampling);
|
const vec2 subsampling_step = vec2(1.0 / float(subsampling));
|
||||||
const float subsampling_start = subsampling_step * 0.5 - 0.5;
|
const vec2 subsampling_start = subsampling_step * 0.5 - vec2(0.5);
|
||||||
const float subsampling_denominator = 1.0 / float(subsampling * subsampling);
|
const float subsampling_scale = 1.0 / float(subsampling * subsampling);
|
||||||
|
|
||||||
// variables
|
// variables
|
||||||
|
|
||||||
vec2 texture_center;
|
vec2 texture_center;
|
||||||
vec2 texture_to_sensor;
|
vec2 texture_to_sensor;
|
||||||
vec2 sensor_to_texture;
|
vec2 sensor_to_texture;
|
||||||
|
|
||||||
void initialize() {
|
void initialize() {
|
||||||
texture_center = myResolution * 0.5;
|
texture_center = myResolution * 0.5;
|
||||||
texture_to_sensor = (sensor_dimensions / myResolution) * pixel_scale;
|
texture_to_sensor = (sensor_size / myResolution) * pixel_scale;
|
||||||
sensor_to_texture = (myResolution / sensor_dimensions);
|
sensor_to_texture = (myResolution / sensor_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 unfish_coord(const in vec2 coord) {
|
vec2 unfish_coord(const in vec2 coord) {
|
||||||
float rectilinear_distance = length(coord);
|
float rectilinear_radius = length(coord);
|
||||||
float rectilinear_angle = atan(rectilinear_distance / rectilinear_focal_length);
|
float rectilinear_angle = atan(rectilinear_radius / rectilinear_focal_length);
|
||||||
float fisheye_distance = rectilinear_angle * fisheye_focal_length;
|
float equidistant_radius = rectilinear_angle * equidistant_focal_length;
|
||||||
return coord * (fisheye_distance / rectilinear_distance);
|
return coord * (equidistant_radius / rectilinear_radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 unfish_pixel(const in vec2 coord) {
|
vec4 unfish_pixel(const in vec2 coord) {
|
||||||
vec2 unfished = unfish_coord((coord - texture_center) * texture_to_sensor);
|
vec2 unfished = unfish_coord((coord - texture_center) * texture_to_sensor);
|
||||||
vec2 y_coord = texture_center + unfished * sensor_to_texture;
|
vec2 y_coord = texture_center + unfished * sensor_to_texture;
|
||||||
|
|
||||||
|
// y_coord.y = coord.y;
|
||||||
|
|
||||||
#ifdef debug_borders
|
#ifdef debug_borders
|
||||||
if (y_coord.x < 0.0 || y_coord.y < 0.0 || y_coord.x > myResolution.x || y_coord.y > myResolution.y) {
|
if (y_coord.x < 0.0 || y_coord.y < 0.0 || y_coord.x > myResolution.x || y_coord.y > myResolution.y) {
|
||||||
return vec4(1.0, 1.0, 1.0, 1.0);
|
return vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
@ -74,13 +72,12 @@ void main() {
|
|||||||
vec2 coord = gl_TexCoord[0].xy;
|
vec2 coord = gl_TexCoord[0].xy;
|
||||||
vec4 pixel = vec4(0.0, 0.0, 0.0, 0.0);
|
vec4 pixel = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
float x, y = subsampling_start;
|
for (int y = 0; y < subsampling; y++) {
|
||||||
for (int column = 0; column < subsampling; column++, y += subsampling_step) {
|
for (int x = 0; x < subsampling; x++) {
|
||||||
x = subsampling_start;
|
vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
|
||||||
for (int row = 0; row < subsampling; row++, x += subsampling_step) {
|
pixel += unfish_pixel(coord + offset);
|
||||||
pixel += unfish_pixel(coord + vec2(x, y));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_FragColor = pixel * subsampling_denominator;
|
gl_FragColor = pixel * subsampling_scale;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,85 +2,101 @@
|
|||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
print("\n--- sensor size (millimeters) ---\n")
|
print("\n--- physical sensor ---\n")
|
||||||
|
|
||||||
# https://www.sony-semicon.com/files/62/pdf/p-13_IMX677-AAPH5-J_Flyer.pdf
|
# https://www.sony-semicon.com/files/62/pdf/p-13_IMX677-AAPH5-J_Flyer.pdf
|
||||||
|
|
||||||
sensor_total_array_width = 5700 # p
|
sensor_array_horizontal = 5700 # p
|
||||||
sensor_total_array_height = 5160 # p
|
sensor_array_vertical = 5160 # p
|
||||||
sensor_total_array_diagonal = math.hypot(sensor_total_array_width, sensor_total_array_height)
|
sensor_array_diagonal = math.hypot(sensor_array_horizontal, sensor_array_vertical)
|
||||||
|
|
||||||
sensor_pixel_size = 1.12 * 0.001 # mm
|
sensor_pixel_size = 1.12 * 0.001 # mm
|
||||||
|
|
||||||
sensor_total_width = sensor_total_array_width * sensor_pixel_size
|
sensor_size_horizontal = sensor_array_horizontal * sensor_pixel_size
|
||||||
sensor_total_height = sensor_total_array_height * sensor_pixel_size
|
sensor_size_vertical = sensor_array_vertical * sensor_pixel_size
|
||||||
sensor_total_diagonal = math.hypot(sensor_total_width, sensor_total_height)
|
sensor_size_diagonal = math.hypot(sensor_size_horizontal, sensor_size_vertical)
|
||||||
|
|
||||||
# sensor_total_diagonal = 8.35 # mm
|
print("sensor size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
|
||||||
# sensor_total_width = sensor_total_diagonal * (sensor_total_array_width / sensor_total_array_diagonal)
|
sensor_size_horizontal,
|
||||||
# sensor_total_height = sensor_total_diagonal * (sensor_total_array_height / sensor_total_array_diagonal)
|
sensor_size_vertical,
|
||||||
|
sensor_size_diagonal))
|
||||||
print("sensor total: width = %.6f, height = %.6f, diagonal = %.6f" % (
|
|
||||||
sensor_total_width,
|
|
||||||
sensor_total_height,
|
|
||||||
sensor_total_diagonal))
|
|
||||||
|
|
||||||
sensor_active_array_width = 5599 # p
|
|
||||||
sensor_active_array_height = 4927 # p
|
|
||||||
sensor_active_array_diagonal = math.hypot(sensor_active_array_width, sensor_active_array_height)
|
|
||||||
|
|
||||||
sensor_active_width = (sensor_active_array_width / sensor_total_array_width) * sensor_total_width
|
|
||||||
sensor_active_height = (sensor_active_array_height / sensor_total_array_height) * sensor_total_height
|
|
||||||
sensor_active_diagonal = (sensor_active_array_diagonal / sensor_total_array_diagonal) * sensor_total_diagonal
|
|
||||||
|
|
||||||
print("sensor active: width = %.6f, height = %.6f, diagonal = %.6f" % (
|
|
||||||
sensor_active_width,
|
|
||||||
sensor_active_height,
|
|
||||||
sensor_active_diagonal))
|
|
||||||
|
|
||||||
# https://community.gopro.com/s/article/HERO11-Black-Video-Settings-And-Resolutions
|
# https://community.gopro.com/s/article/HERO11-Black-Video-Settings-And-Resolutions
|
||||||
|
|
||||||
gopro_array_width = 5312 # p
|
gopro_array_horizontal = 5312 # p
|
||||||
gopro_array_height = 4648 # p
|
gopro_array_vertical = 4648 # p
|
||||||
gopro_array_diagonal = math.hypot(gopro_array_width, gopro_array_height)
|
gopro_array_diagonal = math.hypot(gopro_array_horizontal, gopro_array_vertical)
|
||||||
|
|
||||||
gopro_sensor_width = (gopro_array_width / sensor_total_array_width) * sensor_total_width
|
gopro_size_horizontal = (gopro_array_horizontal / sensor_array_horizontal) * sensor_size_horizontal
|
||||||
gopro_sensor_height = (gopro_array_height / sensor_total_array_height) * sensor_total_height
|
gopro_size_vertical = (gopro_array_vertical / sensor_array_vertical) * sensor_size_vertical
|
||||||
gopro_sensor_diagonal = (gopro_array_diagonal / sensor_total_array_diagonal) * sensor_total_diagonal
|
gopro_size_diagonal = (gopro_array_diagonal / sensor_array_diagonal) * sensor_size_diagonal
|
||||||
|
|
||||||
print("gopro active: width = %.6f, height = %.6f, diagonal = %.6f" % (
|
print("gopro size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
|
||||||
gopro_sensor_width,
|
gopro_size_horizontal,
|
||||||
gopro_sensor_height,
|
gopro_size_vertical,
|
||||||
gopro_sensor_diagonal))
|
gopro_size_diagonal))
|
||||||
|
|
||||||
# https://thinglabs.io/gopro-focal-length-guide
|
# https://thinglabs.io/gopro-focal-radius-guide
|
||||||
|
|
||||||
gopro_focal_length = 2.92 # mm
|
gopro_focal_length = 2.92 # mm
|
||||||
|
|
||||||
print("\n--- fisheye field of view (degrees) ---\n")
|
gopro_radius_horizontal = gopro_size_horizontal * 0.5
|
||||||
|
gopro_radius_vertical = gopro_size_vertical * 0.5
|
||||||
|
gopro_radius_diagonal = gopro_size_diagonal * 0.5
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/Fisheye_lens
|
# https://en.wikipedia.org/wiki/Fisheye_lens
|
||||||
|
|
||||||
equidistant_angle = lambda length: math.degrees(length / gopro_focal_length)
|
equidistant_angle = lambda radius: math.degrees(radius / gopro_focal_length)
|
||||||
|
|
||||||
gopro_fov_width = 2.0 * equidistant_angle(gopro_sensor_width * 0.5)
|
gopro_fov_horizontal = 2.0 * equidistant_angle(gopro_radius_horizontal)
|
||||||
gopro_fov_height = 2.0 * equidistant_angle(gopro_sensor_height * 0.5)
|
gopro_fov_vertical = 2.0 * equidistant_angle(gopro_radius_vertical)
|
||||||
gopro_fov_diagonal = 2.0 * equidistant_angle(gopro_sensor_diagonal * 0.5)
|
gopro_fov_diagonal = 2.0 * equidistant_angle(gopro_radius_diagonal)
|
||||||
|
|
||||||
print("gopro fov: width = %.6f, height = %.6f, diagonal = %.6f" % (
|
print("gopro fov : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
|
||||||
gopro_fov_width,
|
gopro_fov_horizontal,
|
||||||
gopro_fov_height,
|
gopro_fov_vertical,
|
||||||
gopro_fov_diagonal))
|
gopro_fov_diagonal))
|
||||||
|
|
||||||
print("\n--- rectilinear focal length (mm) ---\n")
|
print("\n--- rectilinear re-projection, preserving vertical fov ---\n")
|
||||||
|
|
||||||
rectilinear_focal_length = lambda length: length * math.tan(math.radians(90.0 - equidistant_angle(length)))
|
rectilinear_focal_length = lambda radius: radius * math.tan(math.radians(90.0 - equidistant_angle(radius)))
|
||||||
|
|
||||||
rectilinear_focal_length_width = rectilinear_focal_length(gopro_sensor_width * 0.5)
|
rectilinear_focal_length_horizontal = rectilinear_focal_length(gopro_radius_horizontal)
|
||||||
rectilinear_focal_length_height = rectilinear_focal_length(gopro_sensor_height * 0.5)
|
rectilinear_focal_length_vertical = rectilinear_focal_length(gopro_radius_vertical)
|
||||||
rectilinear_focal_length_diagonal = rectilinear_focal_length(gopro_sensor_diagonal * 0.5)
|
rectilinear_focal_length_diagonal = rectilinear_focal_length(gopro_radius_diagonal)
|
||||||
|
|
||||||
print("rectilinear focal length: width = %.6f, height = %.6f, diagonal = %.6f" % (
|
print("linear focal: horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
|
||||||
rectilinear_focal_length_width,
|
rectilinear_focal_length_horizontal,
|
||||||
rectilinear_focal_length_height,
|
rectilinear_focal_length_vertical,
|
||||||
rectilinear_focal_length_diagonal))
|
rectilinear_focal_length_diagonal))
|
||||||
|
|
||||||
|
rectilinear_radius = lambda angle, focal_length: focal_length * math.tan(math.radians(angle))
|
||||||
|
rectilinear_angle = lambda radius, focal_length: math.degrees(math.atan(radius / focal_length))
|
||||||
|
|
||||||
|
preserved_fov_horizontal = 2.0 * rectilinear_angle(gopro_radius_horizontal, rectilinear_focal_length_vertical)
|
||||||
|
preserved_fov_vertical = 2.0 * rectilinear_angle(gopro_radius_vertical, rectilinear_focal_length_vertical)
|
||||||
|
preserved_fov_diagonal = 2.0 * rectilinear_angle(gopro_radius_diagonal, rectilinear_focal_length_vertical)
|
||||||
|
|
||||||
|
print("linear fov : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
|
||||||
|
preserved_fov_horizontal,
|
||||||
|
preserved_fov_vertical,
|
||||||
|
preserved_fov_diagonal))
|
||||||
|
|
||||||
|
print("\n--- shader parameters ---\n")
|
||||||
|
|
||||||
|
rectilinear_angle_horizontal = rectilinear_angle(gopro_radius_horizontal, rectilinear_focal_length_horizontal)
|
||||||
|
preserved_radius_horizontal = rectilinear_radius(rectilinear_angle_horizontal, rectilinear_focal_length_vertical)
|
||||||
|
|
||||||
|
pixel_scale = gopro_radius_horizontal / preserved_radius_horizontal
|
||||||
|
|
||||||
|
print("""// parameters
|
||||||
|
const vec2 sensor_size = vec2(%.6f, %.6f);
|
||||||
|
const vec2 pixel_scale = vec2(%.6f, 1.0);
|
||||||
|
const float equidistant_focal_length = %.6f;
|
||||||
|
const float rectilinear_focal_length = %.6f;
|
||||||
|
""" % (
|
||||||
|
gopro_size_horizontal, gopro_size_vertical,
|
||||||
|
pixel_scale,
|
||||||
|
gopro_focal_length,
|
||||||
|
rectilinear_focal_length_vertical)
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user