This commit is contained in:
Blair MacIntyre 2018-04-16 10:44:52 -04:00
Родитель c4010a301c
Коммит 6753144b36
5 изменённых файлов: 20 добавлений и 73 удалений

Просмотреть файл

@ -189,8 +189,8 @@ self.addEventListener('message', function(event){
parameter.minMarkerDistanceRate = 0.05;
parameter.cornerRefinementMethod = cv.CORNER_REFINE_SUBPIX; // cv.CORNER_REFINE_NONE;
parameter.cornerRefinementWinSize = 5;
parameter.cornerRefinementMaxIterations = 30;
parameter.cornerRefinementMinAccuracy = 0.1;
parameter.cornerRefinementMaxIterations = 50;
parameter.cornerRefinementMinAccuracy = 0.01;
parameter.markerBorderBits = 1;
parameter.perspectiveRemovePixelPerCell = 4;
//parameter.perspectiveRemovePixelPerCell = 2;

Просмотреть файл

@ -59,27 +59,6 @@
<script src="../libs/stats.js"></script>
<script type="module" src="../../polyfill/XRPolyfill.js"></script>
<script nomodule src="../../dist/webxr-polyfill.js"></script>
<script>
var cvStatusTxt = "";
// Needed if you want to run the OpenCV code inside the web page. Doesn't hurt to have it here
// otherwise. We have it up here so it gets executed before opencv.js is loaded
var Module = {
preRun: [function() {
Module.FS_createPreloadedFile('/', 'haarcascade_eye.xml', 'haarcascade_eye.xml', true, false);
Module.FS_createPreloadedFile('/', 'haarcascade_frontalface_default.xml', 'haarcascade_frontalface_default.xml', true, false);
Module.FS_createPreloadedFile('/', 'haarcascade_profileface.xml', 'haarcascade_profileface.xml', true, false);
}],
onRuntimeInitialized: function() {
opencvIsReady();
},
setStatus: function(msg) {
cvStatusTxt = msg;
}
};
</script>
<!--script src="opencv.js"></script-->
<script src="../common.js"></script>
</head>
<body>
@ -94,6 +73,7 @@
</div>
<script>
var cvStatusTxt = "";
// set up for collecting different stats
var beginTime = ( performance || Date ).now(), prevTime = beginTime, frames = 0;
var stats = new Stats();
@ -415,48 +395,6 @@
cvImageCtx.resetTransform()
}
// function imshow(canvasSource, mat) {
// var canvas=null;
// if(typeof canvasSource==="string") {
// canvas=document.getElementById(canvasSource)
// } else {
// canvas=canvasSource
// }
// if(!(canvas instanceof HTMLCanvasElement)) {
// throw new Error("Please input the valid canvas element or id.");
// return
// }
// if(!(mat instanceof cv.Mat)) {
// throw new Error("Please input the valid cv.Mat instance.");
// return
// }
// var img=new cv.Mat;
// var depth=mat.type()%8;
// var scale=depth<=cv.CV_8S?1:depth<=cv.CV_32S?1/256:255;
// var shift=depth===cv.CV_8S||depth===cv.CV_16S?128:0;
// mat.convertTo(img,cv.CV_8U,scale,shift);
// switch(img.type()) {
// case cv.CV_8UC1:
// cv.cvtColor(img,img,cv.COLOR_GRAY2RGBA);
// break;
// case cv.CV_8UC3:
// cv.cvtColor(img,img,cv.COLOR_RGB2RGBA);
// break;
// case cv.CV_8UC4:
// break;
// default:
// throw new Error("Bad number of channels (Source image must have 1, 3 or 4 channels)");
// return
// }
// var imgData=new ImageData(new Uint8ClampedArray(img.data),img.cols,img.rows);
// var ctx=canvas.getContext("2d");
// ctx.clearRect(0,0,canvas.width,canvas.height);
// canvas.width=imgData.width;
// canvas.height=imgData.height;
// ctx.putImageData(imgData,0,0);
// img.delete()
// }
}
function opencvIsReady() {
console.log('OpenCV.js is ready');

Просмотреть файл

@ -16,6 +16,8 @@ export default class XRSession extends EventHandlerBase {
this._baseLayer = null
this._stageBounds = null
this._skip = false;
this._frameAnchors = []
this._tempMatrix = MatrixMath.mat4_generateIdentity()
this._tempMatrix2 = MatrixMath.mat4_generateIdentity()
@ -53,12 +55,16 @@ export default class XRSession extends EventHandlerBase {
if(typeof callback !== 'function'){
throw 'Invalid callback'
}
var skip = false;
return this._handleRequestFrame(callback)
}
_handleRequestFrame(callback) {
return this._display._requestAnimationFrame(() => {
if (skip) {
skip = false;
return;
if (this._skip) {
this._skip = false;
return this._handleRequestFrame(callback)
}
//this._skip = true; // try skipping every second raf
const frame = this._createPresentationFrame()
this._updateCameraAnchor(frame)
@ -120,9 +126,9 @@ export default class XRSession extends EventHandlerBase {
MatrixMath.mat4_invert(this._tempMatrix, anchorCoords._poseModelMatrix)
// get camera to world by inverting world to camera
MatrixMath.mat4_invert(this._tempMatrix2, matrix)
MatrixMath.mat4_multiply(camera.viewMatrix, this._tempMatrix, this._tempMatrix2)
// MatrixMath.mat4_invert(this._tempMatrix2, matrix)
// MatrixMath.mat4_multiply(camera.viewMatrix, this._tempMatrix, this._tempMatrix2)
MatrixMath.mat4_multiply(camera.viewMatrix, this._tempMatrix, matrix)
}
setVideoFrameHandler(callback) {

Просмотреть файл

@ -962,6 +962,7 @@ export default class ARKitWrapper extends EventHandlerBase {
// wouldn't be rotating the content / UI)
detail.camera.arCamera = true;
var orientation = detail.camera.interfaceOrientation;
detail.camera.viewMatrix = detail.camera.inverse_viewMatrix;
// mat4.copy(this._mTemp, detail.camera.viewMatrix)
switch (orientation) {
case 1:

Просмотреть файл

@ -215,7 +215,9 @@ export default class CameraReality extends Reality {
// set from frame
var view = frame.views[0];
this._videoViewMatrix.set(view.viewMatrix);
//this._videoViewMatrix.set(view.viewMatrix);
MatrixMath.mat4_invert(this._videoViewMatrix, view.viewMatrix)
this._videoProjectionMatrix.set(view.projectionMatrix)
var camera = {