Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read blender depth in different formats #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions vikit_common/include/vikit/blender_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
namespace vk {
namespace blender_utils {

enum class DepthType {
OPTICAL_AXIS, // Depth stored along optical axis
OPTICAL_RAY // Depth stored along optical ray
};

/*
* Loads depth along optical ray
*/
void loadBlenderDepthmap(
const std::string file_name,
const vk::AbstractCamera& cam,
cv::Mat& img)
cv::Mat& img,
DepthType type=DepthType::OPTICAL_RAY)
{
std::ifstream file_stream(file_name.c_str());
assert(file_stream.is_open());
Expand All @@ -35,8 +44,11 @@ void loadBlenderDepthmap(
{
file_stream >> depth;
// blender:
Eigen::Vector2d uv(vk::project2d(cam.cam2world(x,y)));
*img_ptr = depth * sqrt(uv[0]*uv[0] + uv[1]*uv[1] + 1.0);
if (type == DepthType::OPTICAL_AXIS) {
Eigen::Vector2d uv(vk::project2d(cam.cam2world(x,y)));
depth = depth * sqrt(uv[0]*uv[0] + uv[1]*uv[1] + 1.0);
}
*img_ptr = depth;

// povray
// *img_ptr = depth/100.0; // depth is in [cm], we want [m]
Expand Down