Compare commits
	
		
			4 Commits
		
	
	
		
			main
			...
			d7f0cb427d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						d7f0cb427d
	
				 | 
					
					
						|||
| 
						
						
							
						
						95175afb5d
	
				 | 
					
					
						|||
| 
						
						
							
						
						1385b3e6f3
	
				 | 
					
					
						|||
| 
						
						
							
						
						e6c417f0f6
	
				 | 
					
					
						
@ -1,36 +0,0 @@
 | 
				
			|||||||
# RozK
 | 
					 | 
				
			||||||
# Computes fisheye removal parameters for GoPro 11+, 8:7 ratio, without hypersmooth,
 | 
					 | 
				
			||||||
# keeping the vertical FOV and widening the frame to preserve the diagonal FOV
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# https://www.bobatkins.com/photography/technical/field_of_view.html
 | 
					 | 
				
			||||||
# https://community.gopro.com/s/article/HERO11-Black-Mini-Digital-Lenses-FOV-Information?language=fr
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import math
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
frame_width = 8
 | 
					 | 
				
			||||||
frame_height = 7
 | 
					 | 
				
			||||||
input_ratio = frame_width / frame_height
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
input_vertical_fov = 108.0
 | 
					 | 
				
			||||||
input_diagonal_fov = 156.0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
input_vertical_length = math.radians(input_vertical_fov * 0.5)
 | 
					 | 
				
			||||||
input_diagonal_length = math.radians(input_diagonal_fov * 0.5)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
output_horizontal_length = math.sqrt((input_diagonal_length ** 2) / (input_vertical_length ** 2))
 | 
					 | 
				
			||||||
output_diagonal_length = math.hypot(output_horizontal_length, input_vertical_length)
 | 
					 | 
				
			||||||
output_diagonal_fov = math.degrees(math.atan(output_diagonal_length)) * 2.0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
output_ratio = 1.0 / (output_horizontal_length / input_vertical_length)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("Output FOV   = %f" % output_diagonal_fov)
 | 
					 | 
				
			||||||
print("Output Ratio = %f" % output_ratio)
 | 
					 | 
				
			||||||
print("= Resolutions =====================")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def width_rounded_8(height):
 | 
					 | 
				
			||||||
    width = int(round(height * input_ratio))
 | 
					 | 
				
			||||||
    return ((width + 4) // 8) * 8
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
print("HD             = %i x 720" % width_rounded_8(720))
 | 
					 | 
				
			||||||
print("Full HD        = %i x 1080" % width_rounded_8(1080))
 | 
					 | 
				
			||||||
print("4K             = %i x 2160" % width_rounded_8(2160))
 | 
					 | 
				
			||||||
@ -1,12 +1,14 @@
 | 
				
			|||||||
 | 
					#version 130
 | 
				
			||||||
// RozK
 | 
					// RozK
 | 
				
			||||||
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
					// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
 | 
				
			||||||
// Adapted from https://github.com/duducosmos/defisheye
 | 
					 | 
				
			||||||
// itself based on http://www.fmwconcepts.com/imagemagick/defisheye/index.php
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#extension GL_ARB_texture_rectangle: enable
 | 
					#extension GL_ARB_texture_rectangle: enable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: investigate
 | 
					#undef highp // defined by Qt-OpenGl
 | 
				
			||||||
// precision highp float;
 | 
					#define rotate_180
 | 
				
			||||||
 | 
					//#define debug_borders
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					precision highp float;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// uniforms
 | 
					// uniforms
 | 
				
			||||||
uniform sampler2DRect myTextureY;
 | 
					uniform sampler2DRect myTextureY;
 | 
				
			||||||
@ -16,25 +18,50 @@ uniform vec2 myResolution;
 | 
				
			|||||||
uniform float pts;
 | 
					uniform float pts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// parameters
 | 
					// parameters
 | 
				
			||||||
const float input_fov = 156.0;
 | 
					const vec2 sensor_size = vec2(5.949440, 5.205760);
 | 
				
			||||||
const float output_fov = 124.45;
 | 
					const vec2 pixel_scale = vec2(0.871558, 1.0);
 | 
				
			||||||
const vec2 pixel_scale = vec2(0.652485, 1.0);
 | 
					const float equidistant_focal_length = 2.920000;
 | 
				
			||||||
const int subsampling = 4;
 | 
					const float rectilinear_focal_length = 2.102263;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// subsampling constants
 | 
					// constants
 | 
				
			||||||
const float substep = 1.0 / float(subsampling);
 | 
					const int subsampling = 4;
 | 
				
			||||||
const float substart = substep * 0.5 - 0.5;
 | 
					const vec2 subsampling_step = vec2(1.0 / float(subsampling));
 | 
				
			||||||
const float subscale = 1.0 / float(subsampling * subsampling);
 | 
					const vec2 subsampling_start = subsampling_step * 0.5 - vec2(0.5);
 | 
				
			||||||
 | 
					const float subsampling_scale = 1.0 / float(subsampling * subsampling);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// variables
 | 
					// variables
 | 
				
			||||||
vec2 center;
 | 
					vec2 texture_center;
 | 
				
			||||||
float diameter;
 | 
					vec2 texture_to_sensor;
 | 
				
			||||||
float input_len;
 | 
					vec2 sensor_to_texture;
 | 
				
			||||||
float inv_output_len;
 | 
					
 | 
				
			||||||
 | 
					void initialize() {
 | 
				
			||||||
 | 
					    texture_center = myResolution * 0.5;
 | 
				
			||||||
 | 
					    texture_to_sensor = (sensor_size / myResolution) * pixel_scale;
 | 
				
			||||||
 | 
					#ifdef rotate_180
 | 
				
			||||||
 | 
					    texture_to_sensor *= -1.0;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    sensor_to_texture = (myResolution / sensor_size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec2 unfish_coord(const in vec2 coord) {
 | 
				
			||||||
 | 
					    float rectilinear_radius = length(coord);
 | 
				
			||||||
 | 
					    float rectilinear_angle = atan(rectilinear_radius / rectilinear_focal_length);
 | 
				
			||||||
 | 
					    float equidistant_radius = rectilinear_angle * equidistant_focal_length;
 | 
				
			||||||
 | 
					    return coord * (equidistant_radius / rectilinear_radius);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vec4 unfish_pixel(const in vec2 coord) {
 | 
				
			||||||
 | 
					    vec2 unfished = unfish_coord((coord - texture_center) * texture_to_sensor);
 | 
				
			||||||
 | 
					    vec2 y_coord = texture_center + unfished * sensor_to_texture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // y_coord.y = coord.y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef debug_borders
 | 
				
			||||||
 | 
					    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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec4 unfish(const in vec2 coord) {
 | 
					 | 
				
			||||||
    float len = max(0.001, length(coord));
 | 
					 | 
				
			||||||
    vec2 y_coord = center + coord * ((input_len / len) * atan(len * inv_output_len));
 | 
					 | 
				
			||||||
    vec2 uv_coord = y_coord * 0.5;
 | 
					    vec2 uv_coord = y_coord * 0.5;
 | 
				
			||||||
    return vec4(
 | 
					    return vec4(
 | 
				
			||||||
        texture2DRect(myTextureY, y_coord).r,
 | 
					        texture2DRect(myTextureY, y_coord).r,
 | 
				
			||||||
@ -45,21 +72,17 @@ vec4 unfish(const in vec2 coord) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void main() {
 | 
					void main() {
 | 
				
			||||||
    center = myResolution * 0.5;
 | 
					    initialize();
 | 
				
			||||||
    diameter = length(myResolution);
 | 
					 | 
				
			||||||
    input_len = diameter / radians(input_fov);
 | 
					 | 
				
			||||||
    inv_output_len = (2.0 * tan(radians(output_fov * 0.5))) / diameter;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vec2 coord = gl_TexCoord[0].xy - center;
 | 
					    vec2 coord = gl_TexCoord[0].xy;
 | 
				
			||||||
    vec4 pixel = vec4(0.0, 0.0, 0.0, 0.0);
 | 
					    vec4 pixel = vec4(0.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    float x, y = substart;
 | 
					    for (int y = 0; y < subsampling; y++) {
 | 
				
			||||||
    for (int column = 0; column < subsampling; column++, y += substep) {
 | 
					        for (int x = 0; x < subsampling; x++) {
 | 
				
			||||||
        x = substart;
 | 
					            vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
 | 
				
			||||||
        for (int row = 0; row < subsampling; row++, x += substep) {
 | 
					            pixel += unfish_pixel(coord + offset);
 | 
				
			||||||
            pixel += unfish((coord + vec2(x, y)) * pixel_scale);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gl_FragColor = pixel * subscale;
 | 
					    gl_FragColor = pixel * subsampling_scale;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										102
									
								
								gopro_8:7/unfish_gopro_8:7.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								gopro_8:7/unfish_gopro_8:7.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,102 @@
 | 
				
			|||||||
 | 
					# RozK
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import math
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("\n--- physical sensor ---\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# https://www.sony-semicon.com/files/62/pdf/p-13_IMX677-AAPH5-J_Flyer.pdf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sensor_array_horizontal = 5700 # p
 | 
				
			||||||
 | 
					sensor_array_vertical   = 5160 # p
 | 
				
			||||||
 | 
					sensor_array_diagonal   = math.hypot(sensor_array_horizontal, sensor_array_vertical)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sensor_pixel_size = 1.12 * 0.001 # mm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sensor_size_horizontal = sensor_array_horizontal * sensor_pixel_size
 | 
				
			||||||
 | 
					sensor_size_vertical   = sensor_array_vertical   * sensor_pixel_size
 | 
				
			||||||
 | 
					sensor_size_diagonal   = math.hypot(sensor_size_horizontal, sensor_size_vertical)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("sensor size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
 | 
				
			||||||
 | 
					    sensor_size_horizontal,
 | 
				
			||||||
 | 
					    sensor_size_vertical,
 | 
				
			||||||
 | 
					    sensor_size_diagonal))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# https://community.gopro.com/s/article/HERO11-Black-Video-Settings-And-Resolutions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gopro_array_horizontal = 5312 # p
 | 
				
			||||||
 | 
					gopro_array_vertical   = 4648 # p
 | 
				
			||||||
 | 
					gopro_array_diagonal   = math.hypot(gopro_array_horizontal, gopro_array_vertical)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gopro_size_horizontal = (gopro_array_horizontal / sensor_array_horizontal) * sensor_size_horizontal
 | 
				
			||||||
 | 
					gopro_size_vertical   = (gopro_array_vertical   / sensor_array_vertical)   * sensor_size_vertical
 | 
				
			||||||
 | 
					gopro_size_diagonal   = (gopro_array_diagonal   / sensor_array_diagonal)   * sensor_size_diagonal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("gopro  size : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
 | 
				
			||||||
 | 
					    gopro_size_horizontal,
 | 
				
			||||||
 | 
					    gopro_size_vertical,
 | 
				
			||||||
 | 
					    gopro_size_diagonal))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# https://thinglabs.io/gopro-focal-radius-guide
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gopro_focal_length = 2.92 # mm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					equidistant_angle  = lambda radius: math.degrees(radius / gopro_focal_length)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					gopro_fov_horizontal = 2.0 * equidistant_angle(gopro_radius_horizontal)
 | 
				
			||||||
 | 
					gopro_fov_vertical   = 2.0 * equidistant_angle(gopro_radius_vertical)
 | 
				
			||||||
 | 
					gopro_fov_diagonal   = 2.0 * equidistant_angle(gopro_radius_diagonal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("gopro  fov  : horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (deg)" % (
 | 
				
			||||||
 | 
					    gopro_fov_horizontal,
 | 
				
			||||||
 | 
					    gopro_fov_vertical,
 | 
				
			||||||
 | 
					    gopro_fov_diagonal))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("\n--- rectilinear re-projection, preserving vertical fov ---\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rectilinear_focal_length = lambda radius: radius * math.tan(math.radians(90.0 - equidistant_angle(radius)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rectilinear_focal_length_horizontal = rectilinear_focal_length(gopro_radius_horizontal)
 | 
				
			||||||
 | 
					rectilinear_focal_length_vertical   = rectilinear_focal_length(gopro_radius_vertical)
 | 
				
			||||||
 | 
					rectilinear_focal_length_diagonal   = rectilinear_focal_length(gopro_radius_diagonal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("linear focal: horizontal = %7.3f, vertical = %7.3f, diagonal = %7.3f (mm)" % (
 | 
				
			||||||
 | 
					    rectilinear_focal_length_horizontal,
 | 
				
			||||||
 | 
					    rectilinear_focal_length_vertical,
 | 
				
			||||||
 | 
					    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