001/******************************************************************************* 002 * Permission to use and distribute this software is granted under the BSD 2-Clause 003 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 004 * Copyright (c) 2016-2023 Wilhelm Burger. All rights reserved. 005 * Visit https://imagingbook.com for additional details. 006 ******************************************************************************/ 007package imagingbook.calibration.zhang.data; 008 009import imagingbook.calibration.zhang.Camera; 010import imagingbook.calibration.zhang.ViewTransform; 011import imagingbook.common.geometry.basic.Pnt2d; 012import org.apache.commons.math3.linear.MatrixUtils; 013 014 015/** 016 * Supplies all numeric data for Zhang's demo calibration test suite. 017 * 018 * @author WB 019 */ 020public abstract class ZhangData { 021 022 public static final int ImageWidth = 640; 023 public static final int ImageHeight = 480; 024 public static final int NumberOfViews = ObservedPoints.pointData.length; 025 026 public static Pnt2d[] getModelPoints() { 027 return StandardModel.getPoints(); 028 } 029 030 public static Pnt2d[] getObservedPoints(int viewNr) { 031 return ObservedPoints.getPoints(viewNr); 032 } 033 034 public static Pnt2d[][] getAllObservedPoints() { 035 Pnt2d obsPoints[][] = new Pnt2d[NumberOfViews][]; 036 for (int i = 0; i < NumberOfViews; i++) { 037 int viewNr = i + 1; 038 obsPoints[i] = getObservedPoints(viewNr); 039 } 040 return obsPoints; 041 } 042 043 public static ViewTransform[] getAllViewTransforms() { 044 ViewTransform[] viewtransforms = new ViewTransform[NumberOfViews]; 045 for (int i = 0; i < NumberOfViews; i++) { 046 viewtransforms[i] = getViewTransform(i); 047 } 048// return new ViewTransform[] 049// {getViewTransform(1), getViewTransform(2), getViewTransform(3), getViewTransform(4), getViewTransform(5)}; 050 return viewtransforms; 051 } 052 053 public static ViewTransform getViewTransform(int viewNr) { 054 double[][] RT = CameraViews.getViewMatrix(viewNr); 055 return (RT == null) ? null : new ViewTransform(MatrixUtils.createRealMatrix(RT)); 056 } 057 058 public static Camera getCameraIntrinsics() { 059 // http://research.microsoft.com/en-us/um/people/zhang/calib/Calibration/Calib.txt 060 return new Camera ( 061 832.5, 832.53, 0.204494, // alpha, beta, gamma, (!) 062 303.959, 206.585, // c_x, c_y 063 -0.228601, 0.190353); // k1, k2 064 } 065 066 public static int extractViewNumber(String imgShortTitle) { 067// String imgShortTitle = im.getShortTitle(); 068 String num = imgShortTitle.substring(imgShortTitle.length() - 1, imgShortTitle.length()); 069 return Integer.decode(num) - 1; 070 } 071 072}