cameraIntrinsicsPinhole.cpp
Go to the documentation of this file.00001
00016 #include <iomanip>
00017 #include <dlrCommon/inputStream.h>
00018 #include <dlrComputerVision/cameraIntrinsicsPinhole.h>
00019
00020 using namespace dlr::numeric;
00021 using namespace dlr::geometry;
00022
00023 namespace dlr {
00024
00025 namespace computerVision {
00026
00027
00028
00029
00030 CameraIntrinsicsPinhole::
00031 CameraIntrinsicsPinhole()
00032 : CameraIntrinsics(),
00033 m_centerU(50),
00034 m_centerV(50),
00035 m_focalLength(1.0),
00036 m_kX(1.0),
00037 m_kY(1.0),
00038 m_numPixelsX(100),
00039 m_numPixelsY(100)
00040 {
00041
00042 }
00043
00044
00045
00046
00047 CameraIntrinsicsPinhole::
00048 CameraIntrinsicsPinhole(size_t numPixelsX,
00049 size_t numPixelsY,
00050 double focalLength,
00051 double pixelSizeX,
00052 double pixelSizeY,
00053 double centerU,
00054 double centerV)
00055 : CameraIntrinsics(),
00056 m_centerU(centerU),
00057 m_centerV(centerV),
00058 m_focalLength(focalLength),
00059 m_kX(focalLength / pixelSizeX),
00060 m_kY(focalLength / pixelSizeY),
00061 m_numPixelsX(numPixelsX),
00062 m_numPixelsY(numPixelsY)
00063 {
00064
00065 }
00066
00067
00068
00069
00070 dlr::numeric::Array2D<double>
00071 CameraIntrinsicsPinhole::
00072 getProjectionMatrix() const
00073 {
00074 dlr::numeric::Array2D<double> result(3, 4);
00075 result[0] = m_kX; result[1] = 0.0; result[2] = m_centerU; result[3] = 0.0;
00076 result[4] = 0.0; result[5] = m_kY; result[6] = m_centerV; result[7] = 0.0;
00077 result[8] = 0.0; result[9] = 0.0; result[10] = 1.0; result[11] = 0.0;
00078 return result;
00079 }
00080
00081
00082
00083
00084 Vector2D
00085 CameraIntrinsicsPinhole::
00086 project(const dlr::numeric::Vector3D& point) const
00087 {
00088 return Vector2D(m_kX * point.x() / point.z() + m_centerU,
00089 m_kY * point.y() / point.z() + m_centerV);
00090 }
00091
00092
00093
00094
00095 std::istream&
00096 CameraIntrinsicsPinhole::
00097 readFromStream(std::istream& stream)
00098 {
00099
00100 if (!stream){
00101 return stream;
00102 }
00103
00104
00105
00106 InputStream inputStream(stream, InputStream::SKIP_WHITESPACE);
00107
00108 double centerU, centerV, kX, kY;
00109 size_t numpixelsX, numpixelsY;
00110 inputStream.expect("CameraIntrinsicsPinhole");
00111 inputStream.expect("{");
00112 stream >> numpixelsX;
00113 inputStream.expect(",");
00114 stream >> numpixelsY;
00115 inputStream.expect(",");
00116 stream >> kX;
00117 inputStream.expect(",");
00118 stream >> kY;
00119 inputStream.expect(",");
00120 stream >> centerU;
00121 inputStream.expect(",");
00122 stream >> centerV;
00123 inputStream.expect("}");
00124
00125 if(stream) {
00126 m_centerU = centerU;
00127 m_centerV = centerV;
00128 m_kX = kX;
00129 m_kY = kY;
00130 m_numPixelsX = numpixelsX;
00131 m_numPixelsY = numpixelsY;
00132 }
00133 return stream;
00134 }
00135
00136
00137
00138
00139
00140
00141 geometry::Ray3D
00142 CameraIntrinsicsPinhole::
00143 reverseProject(const Vector2D& pixelPosition,
00144 bool normalize) const
00145 {
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 return Ray3D(Vector3D(0.0, 0.0, 0.0),
00165 Vector3D((pixelPosition.x() - m_centerU) / m_kX,
00166 (pixelPosition.y() - m_centerV) / m_kY,
00167 1.0, normalize));
00168 }
00169
00170
00171
00172
00173
00174 std::ostream&
00175 CameraIntrinsicsPinhole::
00176 writeToStream(std::ostream& stream) const
00177 {
00178 stream << "CameraIntrinsicsPinhole {"
00179 << std::fixed << std::setw(14)
00180 << m_numPixelsX << ", "
00181 << m_numPixelsY << ", "
00182 << m_kX << ", "
00183 << m_kY << ", "
00184 << m_centerU << ", "
00185 << m_centerV << "}";
00186 return stream;
00187 }
00188
00189
00190 }
00191
00192 }