Skip to content

Commit a05d30e

Browse files
committed
ovis: add cpp samples
ovis, aruco_ar_demo, remove trailing whitespace
1 parent 66aba49 commit a05d30e

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <opencv2/highgui.hpp>
2+
#include <opencv2/calib3d.hpp>
3+
#include <opencv2/videoio.hpp>
4+
5+
#include <opencv2/ovis.hpp>
6+
#include <opencv2/aruco.hpp>
7+
8+
#include <iostream>
9+
10+
11+
#define KEY_ESCAPE 27
12+
13+
using namespace cv;
14+
15+
int main()
16+
{
17+
Mat img;
18+
std::vector<std::vector<Point2f>> corners;
19+
std::vector<int> ids;
20+
std::vector<Vec3d> rvecs;
21+
std::vector<Vec3d> tvecs;
22+
23+
const Size2i imsize(800, 600);
24+
const double focal_length = 800.0;
25+
26+
// aruco
27+
Ptr<aruco::Dictionary> adict = aruco::getPredefinedDictionary(aruco::DICT_4X4_50);
28+
//Mat out_img;
29+
//aruco::drawMarker(adict, 0, 400, out_img);
30+
//imshow("marker", out_img);
31+
32+
// random calibration data, your mileage may vary
33+
Mat1d cm = Mat1d::zeros(3, 3); // init empty matrix
34+
cm.at<double>(0, 0) = focal_length; // f_x
35+
cm.at<double>(1, 1) = focal_length; // f_y
36+
cm.at<double>(2, 2) = 1; // f_z
37+
Mat K = getDefaultNewCameraMatrix(cm, imsize, true);
38+
39+
// AR scene
40+
ovis::addResourceLocation("packs/Sinbad.zip"); // shipped with Ogre
41+
42+
Ptr<ovis::WindowScene> win = ovis::createWindow(String("arucoAR"), imsize, ovis::SCENE_INTERACTIVE | ovis::SCENE_AA);
43+
win->setCameraIntrinsics(K, imsize);
44+
win->createEntity("sinbad", "Sinbad.mesh", Vec3i(0, 0, 5), Vec3f(1.57, 0.0, 0.0));
45+
win->createLightEntity("sun", Vec3i(0, 0, 100));
46+
47+
// video capture
48+
VideoCapture cap{0};
49+
cap.set(CAP_PROP_FRAME_WIDTH, imsize.width);
50+
cap.set(CAP_PROP_FRAME_HEIGHT, imsize.height);
51+
52+
std::cout << "Press ESCAPE to exit demo" << std::endl;
53+
while (ovis::waitKey(1) != KEY_ESCAPE) {
54+
cap.read(img);
55+
win->setBackground(img);
56+
aruco::detectMarkers(img, adict, corners, ids);
57+
58+
waitKey(1);
59+
60+
if (ids.size() == 0)
61+
continue;
62+
63+
aruco::estimatePoseSingleMarkers(corners, 5, K, noArray(), rvecs, tvecs);
64+
win->setCameraPose(tvecs.at(0), rvecs.at(0), true);
65+
}
66+
67+
return 0;
68+
}

modules/ovis/samples/ovis_demo.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <opencv2/calib3d.hpp>
2+
#include <opencv2/videoio.hpp>
3+
4+
#include <opencv2/ovis.hpp>
5+
#include <opencv2/aruco.hpp>
6+
7+
#include <iostream>
8+
9+
10+
#define KEY_ESCAPE 27
11+
12+
using namespace cv;
13+
14+
int main()
15+
{
16+
Mat R;
17+
Vec3d t;
18+
19+
const Size2i imsize(800, 600);
20+
const double focal_length = 800.0;
21+
22+
//add some external resources
23+
ovis::addResourceLocation("packs/Sinbad.zip"); // shipped with Ogre
24+
25+
//camera intrinsics
26+
Mat1d K = Mat1d::zeros(3, 3); // init empty matrix
27+
K.at<double>(0, 0) = focal_length; // f_x
28+
K.at<double>(1, 1) = focal_length; // f_y
29+
K.at<double>(0, 2) = 400; // t_x
30+
K.at<double>(1, 2) = 500; // t_y
31+
K.at<double>(2, 2) = 1; // f_z
32+
33+
//observer scene
34+
Ptr<ovis::WindowScene> owin = ovis::createWindow(String("VR"), imsize);
35+
ovis::createGridMesh("ground", Size2i(10, 10), Size2i(10, 10));
36+
owin->createEntity("ground", "ground", Vec3f(1.57, 0, 0));
37+
owin->createCameraEntity("cam", K, imsize, 5);
38+
owin->createEntity("figure", "Sinbad.mesh", Vec3i(0, 0, 5), Vec3f(CV_PI/2.0, 0.0, 0.0)); // externally defined mesh
39+
owin->createLightEntity("sun", Vec3i(0, 0, -100));
40+
41+
//interaction scene
42+
Ptr<ovis::WindowScene> iwin = ovis::createWindow(String("AR"), imsize, ovis::SCENE_SEPERATE | ovis::SCENE_INTERACTIVE);
43+
iwin->createEntity("figure", "Sinbad.mesh", Vec3i(0, -5, 0), Vec3f(CV_PI, 0.0, 0.0));
44+
iwin->createLightEntity("sun", Vec3i(0, 0, -100));
45+
iwin->setCameraIntrinsics(K, imsize);
46+
47+
std::cout << "Press ESCAPE to exit demo" << std::endl;
48+
while (ovis::waitKey(1) != KEY_ESCAPE) {
49+
iwin->getCameraPose(R, t);
50+
owin->setEntityPose("cam", t, R);
51+
}
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)