vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/geometry.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
|
||||
#include <opencv2/ovis.hpp>
|
||||
#include <opencv2/aruco.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#define KEY_ESCAPE 27
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main()
|
||||
{
|
||||
Mat img;
|
||||
std::vector<std::vector<Point2f>> corners;
|
||||
std::vector<int> ids;
|
||||
std::vector<Vec3d> rvecs;
|
||||
std::vector<Vec3d> tvecs;
|
||||
|
||||
const Size2i imsize(800, 600);
|
||||
const double focal_length = 800.0;
|
||||
|
||||
// aruco
|
||||
aruco::Dictionary adict = aruco::getPredefinedDictionary(aruco::DICT_4X4_50);
|
||||
|
||||
aruco::ArucoDetector detector(adict);
|
||||
Mat out_img;
|
||||
adict.generateImageMarker(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<double>(0, 0) = focal_length; // f_x
|
||||
cm.at<double>(1, 1) = focal_length; // f_y
|
||||
cm.at<double>(2, 2) = 1; // f_z
|
||||
Mat K = getDefaultNewCameraMatrix(cm, imsize, true);
|
||||
|
||||
// AR scene
|
||||
ovis::addResourceLocation("packs/Sinbad.zip"); // shipped with Ogre
|
||||
|
||||
Ptr<ovis::WindowScene> 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);
|
||||
detector.detectMarkers(img, 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;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import numpy as np
|
||||
import cv2 as cv
|
||||
|
||||
# aruco
|
||||
adict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50)
|
||||
cv.imshow("marker", adict.generateImageMarker(0, 400))
|
||||
|
||||
# random calibration data. your mileage may vary.
|
||||
imsize = (800, 600)
|
||||
K = cv.getDefaultNewCameraMatrix(np.diag([800, 800, 1]), imsize, True)
|
||||
|
||||
# AR scene
|
||||
cv.ovis.addResourceLocation("packs/Sinbad.zip") # shipped with Ogre
|
||||
|
||||
win = cv.ovis.createWindow("arucoAR", imsize, flags=0)
|
||||
win.setCameraIntrinsics(K, imsize)
|
||||
win.createEntity("figure", "Sinbad.mesh", (0, 0, 5), (1.57, 0, 0))
|
||||
win.createLightEntity("sun", (0, 0, 100))
|
||||
|
||||
# video capture
|
||||
cap = cv.VideoCapture(0)
|
||||
cap.set(cv.CAP_PROP_FRAME_WIDTH, imsize[0])
|
||||
cap.set(cv.CAP_PROP_FRAME_HEIGHT, imsize[1])
|
||||
|
||||
while cv.ovis.waitKey(1) != 27:
|
||||
img = cap.read()[1]
|
||||
win.setBackground(img)
|
||||
corners, ids = cv.aruco.detectMarkers(img, adict)[:2]
|
||||
|
||||
cv.waitKey(1)
|
||||
|
||||
if ids is None:
|
||||
continue
|
||||
|
||||
rvecs, tvecs = cv.aruco.estimatePoseSingleMarkers(corners, 5, K, None)[:2]
|
||||
win.setCameraPose(tvecs[0].ravel(), rvecs[0].ravel(), invert=True)
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <opencv2/geometry.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
|
||||
#include <opencv2/ovis.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#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<double>(0, 0) = focal_length; // f_x
|
||||
K.at<double>(1, 1) = focal_length; // f_y
|
||||
K.at<double>(0, 2) = 400; // t_x
|
||||
K.at<double>(1, 2) = 500; // t_y
|
||||
K.at<double>(2, 2) = 1; // f_z
|
||||
|
||||
//observer scene
|
||||
Ptr<ovis::WindowScene> 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("sinbad", "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));
|
||||
|
||||
// setup and play idle animation
|
||||
owin->setEntityProperty("sinbad", ovis::EntityProperty::ENTITY_ANIMBLEND_MODE, Scalar(1)); // 1 = cumulative
|
||||
owin->playEntityAnimation("sinbad", "IdleBase");
|
||||
owin->playEntityAnimation("sinbad", "IdleTop");
|
||||
|
||||
//interaction scene
|
||||
Ptr<ovis::WindowScene> iwin = ovis::createWindow(String("AR"), imsize, ovis::SCENE_SEPARATE | ovis::SCENE_INTERACTIVE);
|
||||
iwin->createEntity("sinbad", "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 1;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import numpy as np
|
||||
import cv2 as cv
|
||||
|
||||
# add some external resources
|
||||
cv.ovis.addResourceLocation("packs/Sinbad.zip")
|
||||
|
||||
# camera intrinsics
|
||||
imsize = (800, 600)
|
||||
K = np.diag([800, 800, 1])
|
||||
K[:2, 2] = (400, 500) # offset pp
|
||||
|
||||
# observer scene
|
||||
owin = cv.ovis.createWindow("VR", imsize)
|
||||
cv.ovis.createGridMesh("ground", (10, 10), (10, 10))
|
||||
owin.createEntity("ground", "ground", rot=(1.57, 0, 0))
|
||||
owin.createCameraEntity("cam", K, imsize, 5)
|
||||
owin.createEntity("sinbad", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0)) # externally defined mesh
|
||||
owin.createLightEntity("sun", (0, 0, -100))
|
||||
|
||||
# setup and play idle animation
|
||||
owin.setEntityProperty("sinbad", cv.ovis.ENTITY_ANIMBLEND_MODE, 1) # 1 = cumulative
|
||||
owin.playEntityAnimation("sinbad", "IdleBase")
|
||||
owin.playEntityAnimation("sinbad", "IdleTop")
|
||||
|
||||
# interaction scene
|
||||
iwin = cv.ovis.createWindow("AR", imsize, cv.ovis.SCENE_SEPARATE | cv.ovis.SCENE_INTERACTIVE)
|
||||
iwin.createEntity("sinbad", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0))
|
||||
iwin.createLightEntity("sun", (0, 0, -100))
|
||||
iwin.setCameraIntrinsics(K, imsize)
|
||||
|
||||
while cv.ovis.waitKey(1) != 27:
|
||||
R, t = iwin.getCameraPose()
|
||||
owin.setEntityPose("cam", t, R)
|
||||
|
||||
del iwin # must be destroyed in reverse creation order
|
||||
Reference in New Issue
Block a user