diff --git a/modules/ovis/samples/aruco_ar_demo.cpp b/modules/ovis/samples/aruco_ar_demo.cpp new file mode 100644 index 000000000..8e2464046 --- /dev/null +++ b/modules/ovis/samples/aruco_ar_demo.cpp @@ -0,0 +1,68 @@ +#include +#include +#include + +#include +#include + +#include + + +#define KEY_ESCAPE 27 + +using namespace cv; + +int main() +{ + Mat img; + std::vector> corners; + std::vector ids; + std::vector rvecs; + std::vector tvecs; + + const Size2i imsize(800, 600); + const double focal_length = 800.0; + + // aruco + Ptr adict = aruco::getPredefinedDictionary(aruco::DICT_4X4_50); + //Mat out_img; + //aruco::drawMarker(adict, 0, 400, out_img); + //imshow("marker", out_img); + + // random calibration data, your mileage may vary + Mat1d cm = Mat1d::zeros(3, 3); // init empty matrix + cm.at(0, 0) = focal_length; // f_x + cm.at(1, 1) = focal_length; // f_y + cm.at(2, 2) = 1; // f_z + Mat K = getDefaultNewCameraMatrix(cm, imsize, true); + + // AR scene + ovis::addResourceLocation("packs/Sinbad.zip"); // shipped with Ogre + + Ptr win = ovis::createWindow(String("arucoAR"), imsize, ovis::SCENE_INTERACTIVE | ovis::SCENE_AA); + win->setCameraIntrinsics(K, imsize); + win->createEntity("sinbad", "Sinbad.mesh", Vec3i(0, 0, 5), Vec3f(1.57, 0.0, 0.0)); + win->createLightEntity("sun", Vec3i(0, 0, 100)); + + // video capture + VideoCapture cap{0}; + cap.set(CAP_PROP_FRAME_WIDTH, imsize.width); + cap.set(CAP_PROP_FRAME_HEIGHT, imsize.height); + + std::cout << "Press ESCAPE to exit demo" << std::endl; + while (ovis::waitKey(1) != KEY_ESCAPE) { + cap.read(img); + win->setBackground(img); + aruco::detectMarkers(img, adict, corners, ids); + + waitKey(1); + + if (ids.size() == 0) + continue; + + aruco::estimatePoseSingleMarkers(corners, 5, K, noArray(), rvecs, tvecs); + win->setCameraPose(tvecs.at(0), rvecs.at(0), true); + } + + return 0; +} diff --git a/modules/ovis/samples/ovis_demo.cpp b/modules/ovis/samples/ovis_demo.cpp new file mode 100644 index 000000000..1eafa2c8f --- /dev/null +++ b/modules/ovis/samples/ovis_demo.cpp @@ -0,0 +1,54 @@ +#include +#include + +#include +#include + +#include + + +#define KEY_ESCAPE 27 + +using namespace cv; + +int main() +{ + Mat R; + Vec3d t; + + const Size2i imsize(800, 600); + const double focal_length = 800.0; + + //add some external resources + ovis::addResourceLocation("packs/Sinbad.zip"); // shipped with Ogre + + //camera intrinsics + Mat1d K = Mat1d::zeros(3, 3); // init empty matrix + K.at(0, 0) = focal_length; // f_x + K.at(1, 1) = focal_length; // f_y + K.at(0, 2) = 400; // t_x + K.at(1, 2) = 500; // t_y + K.at(2, 2) = 1; // f_z + + //observer scene + Ptr owin = ovis::createWindow(String("VR"), imsize); + ovis::createGridMesh("ground", Size2i(10, 10), Size2i(10, 10)); + owin->createEntity("ground", "ground", Vec3f(1.57, 0, 0)); + owin->createCameraEntity("cam", K, imsize, 5); + owin->createEntity("figure", "Sinbad.mesh", Vec3i(0, 0, 5), Vec3f(CV_PI/2.0, 0.0, 0.0)); // externally defined mesh + owin->createLightEntity("sun", Vec3i(0, 0, -100)); + + //interaction scene + Ptr iwin = ovis::createWindow(String("AR"), imsize, ovis::SCENE_SEPERATE | ovis::SCENE_INTERACTIVE); + iwin->createEntity("figure", "Sinbad.mesh", Vec3i(0, -5, 0), Vec3f(CV_PI, 0.0, 0.0)); + iwin->createLightEntity("sun", Vec3i(0, 0, -100)); + iwin->setCameraIntrinsics(K, imsize); + + std::cout << "Press ESCAPE to exit demo" << std::endl; + while (ovis::waitKey(1) != KEY_ESCAPE) { + iwin->getCameraPose(R, t); + owin->setEntityPose("cam", t, R); + } + + return 0; +}