SuperimposeMesh
All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
tutorial_background.cpp
Go to the documentation of this file.
1 #include <cmath>
2 #include <exception>
3 #include <iostream>
4 #include <string>
5 
6 #include <glm/glm.hpp>
7 #include <glm/gtc/matrix_transform.hpp>
8 #include <opencv2/core/core.hpp>
9 #include <opencv2/imgcodecs/imgcodecs.hpp>
10 #include <opencv2/imgproc/imgproc.hpp>
11 #include <SuperimposeMesh/SICAD.h>
12 
13 
14 int main()
15 {
16  const unsigned int cam_width = 320;
17  const unsigned int cam_height = 240;
18  const float cam_fx = 257.34;
19  const float cam_cx = 160;
20  const float cam_fy = 257.34;
21  const float cam_cy = 120;
22 
24  obj.emplace("alien", "./spaceinvader.obj");
25 
26  SICAD si_cad(obj, cam_width, cam_height, cam_fx, cam_fy, cam_cx, cam_cy);
27 
28  Superimpose::ModelPose obj_pose(7);
29  obj_pose[0] = 0;
30  obj_pose[1] = 0;
31  obj_pose[2] = -0.1;
32  obj_pose[3] = 1;
33  obj_pose[4] = 0;
34  obj_pose[5] = 0;
35  obj_pose[6] = 0;
36 
38  objpose_map.emplace("alien", obj_pose);
39 
40  double cam_x[] = { 0, 0, 0};
41  double cam_o[] = {1.0, 0, 0, 0};
42 
43  /**
44  * It's background time!
45  * The steps are the same, but this time the cv::Mat is created from an
46  * existing image and we instruct the SICAD class to use it as a background
47  * with setBackgroundOpt(true).
48  * That's it!
49  **/
50  cv::Mat img = cv::imread("./space.png");
51  si_cad.setBackgroundOpt(true);
52  si_cad.superimpose(objpose_map, cam_x, cam_o, img);
53  cv::imwrite("./spaceinvader.jpg", img);
54 
55  return EXIT_SUCCESS;
56 }
std::unordered_map< std::string, std::string > ModelPathContainer
Definition: SICAD.h:33
void setBackgroundOpt(bool show_background)
Definition: SICAD.cpp:1291
bool superimpose(const ModelPoseContainer &objpos_map, const double *cam_x, const double *cam_o, cv::Mat &img) override
Render the mesh models in the pose specified in objpos_map and move the virtual camera in cam_x posit...
Definition: SICAD.cpp:464
std::vector< double > ModelPose
Definition: Superimpose.h:23
int main()
A Superimpose derived class to superimpose mesh models on images.
Definition: SICAD.h:30
std::multimap< std::string, ModelPose > ModelPoseContainer
Definition: Superimpose.h:25