22#ifndef EOS_RENDER_OPENCV_DRAW_UTILS_HPP
23#define EOS_RENDER_OPENCV_DRAW_UTILS_HPP
25#include "eos/core/Mesh.hpp"
26#include "eos/render/matrix_projection.hpp"
27#include "eos/render/detail/utils.hpp"
31#include "opencv2/core/core.hpp"
32#include "opencv2/imgproc/imgproc.hpp"
53 Eigen::Matrix4f projection, Eigen::Vector4f viewport,
54 cv::Scalar color = cv::Scalar(0, 255, 0, 255))
56 for (
const auto& triangle : mesh.
tvi)
58 const auto p1 =
project(mesh.
vertices[triangle[0]], modelview, projection, viewport);
59 const auto p2 =
project(mesh.
vertices[triangle[1]], modelview, projection, viewport);
60 const auto p3 =
project(mesh.
vertices[triangle[2]], modelview, projection, viewport);
61 if (render::detail::are_vertices_ccw_in_screen_space<float>(p1.head<2>(), p2.head<2>(), p3.head<2>()))
63 cv::line(image, cv::Point(p1.x(), p1.y()), cv::Point(p2.x(), p2.y()), color);
64 cv::line(image, cv::Point(p2.x(), p2.y()), cv::Point(p3.x(), p3.y()), color);
65 cv::line(image, cv::Point(p3.x(), p3.y()), cv::Point(p1.x(), p1.y()), color);
88 image = cv::Mat(512, 512, CV_8UC4, Scalar(0.0f, 0.0f, 0.0f, 255.0f));
91 for (
const auto& triIdx : mesh.
tvi)
95 Point2f(mesh.
texcoords[triIdx[0]][0] * image.cols, mesh.
texcoords[triIdx[0]][1] * image.rows),
96 Point2f(mesh.
texcoords[triIdx[1]][0] * image.cols, mesh.
texcoords[triIdx[1]][1] * image.rows),
97 Scalar(255.0f, 0.0f, 0.0f));
100 Point2f(mesh.
texcoords[triIdx[1]][0] * image.cols, mesh.
texcoords[triIdx[1]][1] * image.rows),
101 Point2f(mesh.
texcoords[triIdx[2]][0] * image.cols, mesh.
texcoords[triIdx[2]][1] * image.rows),
102 Scalar(255.0f, 0.0f, 0.0f));
105 Point2f(mesh.
texcoords[triIdx[2]][0] * image.cols, mesh.
texcoords[triIdx[2]][1] * image.rows),
106 Point2f(mesh.
texcoords[triIdx[0]][0] * image.cols, mesh.
texcoords[triIdx[0]][1] * image.rows),
107 Scalar(255.0f, 0.0f, 0.0f));
cv::Mat draw_texcoords(core::Mesh mesh, cv::Mat image=cv::Mat())
Definition: draw_utils.hpp:82
Eigen::Vector3< T > project(const Eigen::Vector3< T > &point_3d, const Eigen::Matrix4< T > &modelview_matrix, const Eigen::Matrix4< T > &projection_matrix, const Eigen::Vector4< T > &viewport)
Definition: matrix_projection.hpp:148
void draw_wireframe(core::Image3u &image, const core::Mesh &mesh, Eigen::Matrix4f modelview, Eigen::Matrix4f projection, Eigen::Vector4f viewport, Eigen::Vector3f color=Eigen::Vector3f(0, 255, 0))
Definition: draw_utils.hpp:134
core::Image4u render(const core::Mesh &mesh, const Eigen::Matrix4f &model_view_matrix, const Eigen::Matrix4f &projection_matrix, int viewport_width, int viewport_height, bool enable_backface_culling=false, bool enable_near_clipping=true, bool enable_far_clipping=true)
Definition: render.hpp:52
Namespace containing all of eos's 3D model fitting functionality.
This class represents a 3D mesh consisting of vertices, vertex colour information and texture coordin...
Definition: Mesh.hpp:45
std::vector< Eigen::Vector3f > vertices
3D vertex positions.
Definition: Mesh.hpp:46
std::vector< std::array< int, 3 > > tvi
Triangle vertex indices.
Definition: Mesh.hpp:50
std::vector< Eigen::Vector2f > texcoords
Texture coordinates.
Definition: Mesh.hpp:48