Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove artoolkitNFT gloabl variable #276

Open
2 of 3 tasks
kalwalt opened this issue Feb 16, 2023 · 0 comments
Open
2 of 3 tasks

remove artoolkitNFT gloabl variable #276

kalwalt opened this issue Feb 16, 2023 · 0 comments

Comments

@kalwalt
Copy link
Member

kalwalt commented Feb 16, 2023

Remove artoolkitNFT gloabl variable

The global artoolkitNFT variable is not necessary and we can remove it, there are other way to pass data and objects.
I will try to summarize how we can do this and which steps are required to accomplish this.

Remove artoolkitNFT from getNFTMarkerInfo()

First step is to remove the artoolkitNFT global variable defined here

EM_ASM_({
var $a = arguments;
var i = 0;
if (!artoolkitNFT["NFTMarkerInfo"]) {
artoolkitNFT["NFTMarkerInfo"] = ({
id: 0,
error: -1,
found: 0,
pose: [0,0,0,0, 0,0,0,0, 0,0,0,0]
});
}
var markerInfo = artoolkitNFT["NFTMarkerInfo"];
markerInfo["id"] = $a[i++];
markerInfo["error"] = $a[i++];
markerInfo["found"] = 1;
markerInfo["pose"][0] = $a[i++];
markerInfo["pose"][1] = $a[i++];
markerInfo["pose"][2] = $a[i++];
markerInfo["pose"][3] = $a[i++];
markerInfo["pose"][4] = $a[i++];
markerInfo["pose"][5] = $a[i++];
markerInfo["pose"][6] = $a[i++];
markerInfo["pose"][7] = $a[i++];
markerInfo["pose"][8] = $a[i++];
markerInfo["pose"][9] = $a[i++];
markerInfo["pose"][10] = $a[i++];
markerInfo["pose"][11] = $a[i++];
},
markerIndex,
err,
#if WITH_FILTERING
transFLerp[0][0],
transFLerp[0][1],
transFLerp[0][2],
transFLerp[0][3],
transFLerp[1][0],
transFLerp[1][1],
transFLerp[1][2],
transFLerp[1][3],
transFLerp[2][0],
transFLerp[2][1],
transFLerp[2][2],
transFLerp[2][3]
#else
trans[0][0],
trans[0][1],
trans[0][2],
trans[0][3],
trans[1][0],
trans[1][1],
trans[1][2],
trans[1][3],
trans[2][0],
trans[2][1],
trans[2][2],
trans[2][3]
#endif
);
we can output data thanks to emscripten::val and avoid the global variable. I'm working on this in PR #275

Remove artoolkitNFT from setup

Second step is remove it from setup() method

int setup(int width, int height, int cameraID) {
int id = gARControllerID++;
arController *arc = &(arControllers[id]);
arc->id = id;
arc->width = width;
arc->height = height;
arc->videoFrameSize = width * height * 4 * sizeof(ARUint8);
arc->videoFrame = (ARUint8*) malloc(arc->videoFrameSize);
arc->videoLuma = (ARUint8*) malloc(arc->videoFrameSize / 4);
setCamera(id, cameraID);
webarkitLOGi("Allocated videoFrameSize %d", arc->videoFrameSize);
EM_ASM_({
if (!artoolkitNFT["frameMalloc"]) {
artoolkitNFT["frameMalloc"] = ({});
}
var frameMalloc = artoolkitNFT["frameMalloc"];
frameMalloc["framepointer"] = $1;
frameMalloc["framesize"] = $2;
frameMalloc["camera"] = $3;
frameMalloc["transform"] = $4;
frameMalloc["videoLumaPointer"] = $5;
},
arc->id,
arc->videoFrame,
arc->videoFrameSize,
arc->cameraLens,
gTransform,
arc->videoLuma //$5
);
return arc->id;
}
frameMalloc is not required anymore if we pass videoFrame and videoLuma data directly where is required that is in detectMarker()
int detectMarker(int id) {
if (arControllers.find(id) == arControllers.end()) { return ARCONTROLLER_NOT_FOUND; }
arController *arc = &(arControllers[id]);
// Convert video frame to AR2VideoBufferT
AR2VideoBufferT buff = {0};
buff.buff = arc->videoFrame;
buff.fillFlag = 1;
buff.buffLuma = arc->videoLuma;
return arDetectMarker( arc->arhandle, &buff);
}

in detectNFTMarker()
kpmMatching( arc->kpmHandle, arc->videoLuma );

and lastly in getNFTMarkerInfo()
int trackResult = ar2TrackingMod(arc->ar2Handle, arc->surfaceSet[arc->detectedPage], arc->videoFrame, trans, &err);

arc->videoLuma and arc->videoFrame are pointers used to pass the grayscale data and the video data stream, but we need to pass this data in another way (not with frameMalloc).

Summarizing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant