Posts

Showing posts with the label Opengl

Can I Use A Grayscale Image With The OpenGL GlTexImage2D Function?

Answer : Change it to GL_LUMINANCE. See https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml in the FragmentShader, you can write: uniform sampler2D A; vec3 result = vec3(texture(A, TexCoord).r); in the cpp file,you can write: glTexImage2D( GL_TEXTURE_2D, 0, GL_RED, dicomImage->GetColumns(), dicomImage->GetRows(), 0, GL_RED, GL_UNSIGNED_BYTE, pixelArrayPtr);

Camera Position In World Coordinate From Cv::solvePnP

Answer : If with "world coordinates" you mean "object coordinates", you have to get the inverse transformation of the result given by the pnp algorithm. There is a trick to invert transformation matrices that allows you to save the inversion operation, which is usually expensive, and that explains the code in Python. Given a transformation [R|t] , we have that inv([R|t]) = [R'|-R'*t] , where R' is the transpose of R . So, you can code (not tested): cv::Mat rvec, tvec; solvePnP(..., rvec, tvec, ...); // rvec is 3x1, tvec is 3x1 cv::Mat R; cv::Rodrigues(rvec, R); // R is 3x3 R = R.t(); // rotation of inverse tvec = -R * tvec; // translation of inverse cv::Mat T = cv::Mat::eye(4, 4, R.type()); // T is 4x4 T( cv::Range(0,3), cv::Range(0,3) ) = R * 1; // copies R into T T( cv::Range(0,3), cv::Range(3,4) ) = tvec * 1; // copies tvec into T // T is a 4x4 matrix with the pose of the camera in the object frame Update: Later, to use T with OpenGL ...