ovis_demo.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <opencv2/calib3d.hpp>
  2. #include <opencv2/videoio.hpp>
  3. #include <opencv2/ovis.hpp>
  4. #include <iostream>
  5. #define KEY_ESCAPE 27
  6. using namespace cv;
  7. int main()
  8. {
  9. Mat R;
  10. Vec3d t;
  11. const Size2i imsize(800, 600);
  12. const double focal_length = 800.0;
  13. //add some external resources
  14. ovis::addResourceLocation("packs/Sinbad.zip"); // shipped with Ogre
  15. //camera intrinsics
  16. Mat1d K = Mat1d::zeros(3, 3); // init empty matrix
  17. K.at<double>(0, 0) = focal_length; // f_x
  18. K.at<double>(1, 1) = focal_length; // f_y
  19. K.at<double>(0, 2) = 400; // t_x
  20. K.at<double>(1, 2) = 500; // t_y
  21. K.at<double>(2, 2) = 1; // f_z
  22. //observer scene
  23. Ptr<ovis::WindowScene> owin = ovis::createWindow(String("VR"), imsize);
  24. ovis::createGridMesh("ground", Size2i(10, 10), Size2i(10, 10));
  25. owin->createEntity("ground", "ground", Vec3f(1.57, 0, 0));
  26. owin->createCameraEntity("cam", K, imsize, 5);
  27. owin->createEntity("sinbad", "Sinbad.mesh", Vec3i(0, 0, 5), Vec3f(CV_PI/2.0, 0.0, 0.0)); // externally defined mesh
  28. owin->createLightEntity("sun", Vec3i(0, 0, -100));
  29. // setup and play idle animation
  30. owin->setEntityProperty("sinbad", ovis::EntityProperty::ENTITY_ANIMBLEND_MODE, Scalar(1)); // 1 = cumulative
  31. owin->playEntityAnimation("sinbad", "IdleBase");
  32. owin->playEntityAnimation("sinbad", "IdleTop");
  33. //interaction scene
  34. Ptr<ovis::WindowScene> iwin = ovis::createWindow(String("AR"), imsize, ovis::SCENE_SEPARATE | ovis::SCENE_INTERACTIVE);
  35. iwin->createEntity("sinbad", "Sinbad.mesh", Vec3i(0, -5, 0), Vec3f(CV_PI, 0.0, 0.0));
  36. iwin->createLightEntity("sun", Vec3i(0, 0, -100));
  37. iwin->setCameraIntrinsics(K, imsize);
  38. std::cout << "Press ESCAPE to exit demo" << std::endl;
  39. while (ovis::waitKey(1) != KEY_ESCAPE) {
  40. iwin->getCameraPose(R, t);
  41. owin->setEntityPose("cam", t, R);
  42. }
  43. return 1;
  44. }