jeromeetienne / AR.js

Efficient Augmented Reality for the Web - 60fps on mobile!
MIT License
15.79k stars 2.22k forks source link

Modifying thickness/width of the marker borders #296

Closed Angelo8828 closed 5 years ago

Angelo8828 commented 6 years ago

Hello, I'm currently working on an AR project and the client requested to reduce the border size from the current 25% to 20%. Is it possible to modify the current border dimension for markers? If possible, then how to modify it? Thanks

kvanderd commented 6 years ago

The markers come from artoolkit. They have a few constraints, the border size is one of them. Here is the relevant info from the docs:

"Square markers have only a few constraints.

more here: https://artoolkit.org/documentation/doku.php?id=3_Marker_Training:marker_training

Angelo8828 commented 6 years ago

@kvanderd, I'm sorry but I already read that page. What I'm asking is if it's possible to modify the default 25% border thickness.

Angelo8828 commented 6 years ago

Hello again, just commenting again after 2 days of finding if it is not possible or not and will comment again for those who will be encountering this issue/requests from their bosses/clients.

Yes, the border width, can be modified.

I asked another questions in StackOverflow and in the issue thread of JSARToolkit5 and the great @ThorstenBux answered both of my questions (kudos to him).

Then, I modified the AR.js/three.js/src/threex/threex-armarkercontrols.js and I tried adding some code in the postInit() function to be able to modify the default pattRatio in the ARController in the JSARToolkit5. Here is the sample code. You can be able to modify the values from 0.1 to 0.9, which 0.5 is the default. The value corresponds to the percentage of the pattern size in relation to the overall marker size. If you set the value as 0.5, you will have the default 50% image/pattern size, as illustrated here. In my case, I set it to 0.9 because I want the 90% of the image/pattern to occupy the marker. The larger the value, the image will be much bigger and thus the border decreases.

After this, I also modified the marker training module and modified it so that I will be able to have the markers to be printed.

Here is a sample output where I am displaying a Pikachu GIF using the Hiro marker which I custom-trained.

From imgur

TLDR:

  1. Add a code in the armarkercontrols.js like this.
  2. Modify the current trainer to this
  3. Run the make commands.
  4. Enjoy!

PS: As of this moment, I'm still not sure if there will be unintended consequences for modifying the borders, I hope none.

jvijaybhaskar commented 6 years ago

@Angelo8828 In your last response, you mentioned in step 3 to run make commands. Could you please provide more details on this step?? It will be useful for me to replicate this and test

ThorstenBux commented 6 years ago

@Angelo8828 No the marker thickness change shouldn't have any unintended consequences. (Maybe that you need to get closer to the marker for it to be recognized but besides that all good. @jvijaybhaskar Regarding make commands, I'm a bit unsure as of why they would be needed. Maybe to create the minified version of AR.js? ( https://github.com/jeromeetienne/AR.js#how-to-release- )

Angelo8828 commented 6 years ago

Sorry for the late reply @jvijaybhaskar (Easter holiday in my place). You need to install make if you have none and run make minify on your directory in the terminal/command prompt.

Make is a build automation tool, just like Webpack, Grunt, Gulp, etc that in our case, is being used to minify AR.js.

After you run the command, it will create a new version of AR.js file and the new file that will be generated will be the one you will include in your project.

jeromeetienne commented 6 years ago

Very good suggestion! reopening until your modifications are merged :)

jeromeetienne commented 6 years ago

NOTE: How to implement that

javismiles commented 6 years ago

How can I reduce the border in that way when using aframe-ar.js? is this integrated already? if not, what changes can I do manually in aframe-ar.js? thank you very much

ThorstenBux commented 6 years ago

without ever using aframe-ar I think this line might give you a clue: https://github.com/jeromeetienne/AR.js/pull/327/files#diff-e7a1251362f651dbea23121aabf1fa52R49531

javismiles commented 6 years ago

Thank you , yes arController.setPattRatio(_this.parameters.patternRatio), that may make it, but then the other question is that producing a new marker with that width, the app that trains the marker we would need a new version of it, right? oh but I see that the current version has a slider to choose the ratio? https://jeromeetienne.github.io/AR.js/three.js/examples/marker-training/examples/generator.html thats great, so I have to test doing something like arController.setPattRatio(0.8) and see if it works with aframe-ar

ThorstenBux commented 6 years ago

yes, just mind that comment https://github.com/jeromeetienne/AR.js/pull/327#commitcomment-28950160 on the merge

javismiles commented 6 years ago

oh thats not good news, that means that we cannot yet train markers with different pattern ratio, well then its not good, not usable then...

ThorstenBux commented 6 years ago

well you still can, just have to use the artoolkit native tools. https://github.com/artoolkitx/artoolkitx/tree/master/Source/Utilities/genTexData Which is part of the release builds: https://github.com/artoolkitx/artoolkitx/releases/tag/1.0.1 just pick your platform

javismiles commented 6 years ago

Thank you Thorsten, mmm, I dont do C, do u know of any version of it compiled for windows or online? mmmm, by the way I just managed to successfully change the patt ratio at var arController = _this.context.arController arController.setPattRatio(0.8); (output: Pattern ratio size set to 0.800000) and it works, so just need to do that training thing now mmm, not sure how to compile that native stuff though

ThorstenBux commented 6 years ago

this is the link to the windows release with everything prebuild: https://github.com/artoolkitx/artoolkitx/releases/download/1.0.1/artoolkitX.for.Windows.v1.0.1.zip

You don't need to compile anything

javismiles commented 6 years ago

I have just downloaded the windows version, uncompressed it, and found the windows application version of artoolkitx_genTexData , but it just hangs when executing.. a pity...

ThorstenBux commented 6 years ago

does it? It shouldn't I use that regularly. If you can produce some log I could look into that. But going to switch off for today.

javismiles commented 6 years ago

now i got it working on command line,

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_genTexData Error: no input file specified. Exiting. artoolkitx_genTexData -level=n (n is an integer in range 0 (few) to 4 (many). Default 2.' -sd_thresh= -max_thresh= -min_thresh= -leveli=n (n is an integer in range 0 (few) to 3 (many). Default 1.' -feature_density= -dpi=f: Override embedded JPEG DPI value. -max_dpi= -min_dpi= -background Run in background, i.e. as daemon detached from controlling terminal. (macOS and Linux only.) -log= -loglevel=x x is one of: DEBUG, INFO, WARN, ERROR. Default is INFO. -exitcode= --help -h -? Display this help

now i gotta know how to execute those parameters, i just have to pass the jpeg image and thats it? thank you Thorsten

ThorstenBux commented 6 years ago

yes, just the path to the jpeg

ThorstenBux commented 6 years ago

actually you might be better of with mkPatt, there you can set the ratio afaik

javismiles commented 6 years ago

and where do I specify the patt ratio?

javismiles commented 6 years ago

mkPatt is another app? let me see if i find it there, oh yes its artoolkitx_mk_patt

javismiles commented 6 years ago

oh that one really goes nuts :) FSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample.

javismiles commented 6 years ago

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_mk_patt [info] Setting video configuration '-format=BGRA'. [info] Opening artoolkitX video using configuration '-format=BGRA'. [info] Using supplied video config "-format=BGRA". [info] Using supplied video config "-format=BGRA". [info] Requesting images in BGRA format. [info] Video 1280x720 (AR_PIXEL_FORMAT_BGRA), rowBytes=5120. [info] Opened artoolkitX video 1280x720@4Bpp (AR_PIXEL_FORMAT_BGRA). [warning] Using default camera parameters for 1280x720 image size, 45 degrees vertical field-of-view. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample. [error] Error: IMFSourceReader::ReadSample.

javismiles commented 6 years ago

this looks promising

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_genMarkerSet Usage: artoolkitx_genMarkerSet [options]

Where is path to a JPEG or iset file.

Options: --pattRatio f: Specify the proportion of the marker width/height, occupied by the marker pattern. Range (0.0 - 1.0) (not inclusive). (I.e. 1.0 - 2*borderSize). Default value is 0.5. --borderSize f: DEPRECATED specify the width of the pattern border, as a percentage of the marker width. Range (0.0 - 0.5) (not inclusive). (I.e. (1.0 - pattRatio)/2). Default value is 0.25. -border=f: Alternate syntax for --borderSize f. --pattSize n: Specify the number of rows and columns in the pattern space for template (pictorial) markers. Default value 16 (required for compatibility with ARToolKit prior to version 5.2). Range is [16, 64] (inclusive). --pattCountMax n: Specify the maximum number of template (pictorial) markers that may be loaded for use in a single matching pass. Default value 50. Must be > 0. --labelingMode AR_LABELING_BLACK_REGION|AR_LABELING_WHITE_REGION -dpi=f: Override embedded JPEG DPI value. --version: Print artoolkitX version and exit. -loglevel=l: Set the log level to l, where l is one of DEBUG INFO WARN ERROR. -h -help --help: show this message

javismiles commented 6 years ago

So I tried and..

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_genMarkerSet --pattRatio 0.9 t1.jpg Reading JPEG file... Done. JPEG image 't1.jpg' is 918x918. JPEG image 't1.jpg' does not contain embedded resolution data, and no resolution specified on command-line. Enter resolution to use (in decimal DPI): 72 Pass 1: detected 3 marker candidates. Pass 2: 0 detected marker candidates are square. 918x918 input image will display in 1280x720 window at 78.4% size

and it stops there and does no more.. a pity, so close.. thats definitely the right tool to use

javismiles commented 6 years ago

so weird, it should work, it does this and then does nothing else, doesnt generate the patt and no error given

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_genMarkerSet --pattRatio 0.9 -dpi=72 t1.jpg Reading JPEG file... Done. JPEG image 't1.jpg' is 918x918. Pass 1: detected 3 marker candidates. Pass 2: 0 detected marker candidates are square. 918x918 input image will display in 1280x720 window at 78.4% size

javismiles commented 6 years ago

with the mk_patt.exe I managed to get here

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_mk_patt --pattRatio 0.9 [info] Setting video configuration '-format=BGRA'. [info] Opening artoolkitX video using configuration '-format=BGRA'. [info] Using supplied video config "-format=BGRA". [info] Using supplied video config "-format=BGRA". [info] Requesting images in BGRA format. [info] Video 1280x720 (AR_PIXEL_FORMAT_BGRA), rowBytes=5120. [info] Opened artoolkitX video 1280x720@4Bpp (AR_PIXEL_FORMAT_BGRA). [warning] Using default camera parameters for 1280x720 image size, 45 degrees vertical field-of-view. [info] arVideoLuma will use Intel SIMD acceleration. [info] Content 1280x720 (wxh) will display in GL context 1280x720. Enter filename: t1.jpg

and then it crashes.............. really frustrating.. weird..

javismiles commented 6 years ago

the best one should be genMarkerSet.c

unfortunately it just stops here and does nothing else

C:\Users\info\Downloads\artoolkitX.for.Windows.v1.0.1\a\SDK\bin>artoolkitx_genMarkerSet --pattRatio 0.9 -dpi=72 t1.jpg Reading JPEG file... Done. JPEG image 't1.jpg' is 918x918. Pass 1: detected 3 marker candidates. Pass 2: 0 detected marker candidates are square. 918x918 input image will display in 1280x720 window at 78.4% size

javismiles commented 6 years ago

I can see the help keyboard keys

static void printHelpKeys() { int i; GLfloat w, bw, bh; const char *helpText[] = { "Keys:\n", " ? or / Show/hide this help.", " q or [esc] Quit program.", " d Activate / deactivate debug mode.", " m Toggle display of mode info.", " a Toggle between available threshold modes.", " - and + Switch to manual threshold mode, and adjust threshhold up/down by 5.", " x Change image processing mode.", " b Change labeling mode.", " c Calulcate frame rate.", };

but still nothing that actually produces an output file

ThorstenBux commented 6 years ago

that is frustrating. But same result for me

javismiles commented 6 years ago

this is a bit absurd really, whoever created those tools, their entire UX is unbelievable not even mentioning how easy they crash, but we are not talking about a little project, we are talking about ArtToolKit!!! I am Speechless..........................

javismiles commented 6 years ago

so lets recap here, its easy to change the patt ratio in the js file, but we have absolutely no way to generate a .patt file that has any other ratio than 0.5 because nobody is able to provide a consistent tool anywhere that does that

ThorstenBux commented 6 years ago

I'll run tests and recompile. I know it worked because I used it recently. And btw. I'm one of the main contributors to artoolkit :) .

I completely agree in regards to UX. The tools aren't built with UX in mind.

If you can, maybe test the 1.0 release. Might be some bug got into 1.0.1. I should have time to check next week.

javismiles commented 6 years ago

Thank you Thorsten ;) btw you are really supportive and I really appreciate that ;) and as you are one of the main contributors to artoolkit let me say congratulations as I am a huge fan of your work then ;)

but yes, definitely, not done with UX in mind that's for sure ;)

so thank u if you help me check next week potential bugs in 1.0.1 and in the meantime I will follow your suggestion and see if I can test the 1.0 release, thank u again ;)

javismiles commented 6 years ago

Ive just installed release 1.0, and this produces exactly the same result

artoolkitx_genMarkerSet --pattRatio 0.9 -dpi=72 t1.jpg Reading JPEG file... Done. JPEG image 't1.jpg' is 918x918. Pass 1: detected 3 marker candidates. Pass 2: 0 detected marker candidates are square. 918x918 input image will display in 1280x720 window at 78.4% size

and it stops there, i dont know if im missing something, but really, i get exact same result

ThorstenBux commented 6 years ago

Hi @javismiles please excuse I didn't look at it properly. The app genMarkerSet works. The issue might be that you are using a .jpg file that doesn't have a white area around the black border and hence it won't detect the marker. You need to use something like this:

hiro_marker_arjs

then it generates a .pat file for you

javismiles commented 6 years ago

hey Thorsten, I know that it works but remember the problem, the .patt file it generates has a ratio of 0.5, if you change the ratio to 0.9 or anything else, it still generates a file .patt with .5 of ratio, that's why its useless for any ratio that is not 0.5, thats the prob

ThorstenBux commented 6 years ago

Is that true for the web or the windows version? Cause we were discussing the issue with the windows version.

javismiles commented 6 years ago

sorry Thorsten, I got confused here myself, now I see what you mean, you say that genMarkerSet works but that I have to provide the border as well, I was providing the same I provided to the online version which is the graphic without the border, ok so I can now try to put the border and I will tell u if it works, however if I want a 0.9 patt ratio I will have to make the border correct, ok let me try and I tell u thank u

javismiles commented 6 years ago

Doubt here , If I want a patt ratio of 0.9, what should be the thickness of the border be in relation to the inner graphic? 1/10 of it?

"You can be able to modify the values from 0.1 to 0.9, which 0.5 is the default. The value corresponds to the percentage of the pattern size in relation to the overall marker size. If you set the value as 0.5, you will have the default 50% image/pattern size, as illustrated here. In my case, I set it to 0.9 because I want the 90% of the image/pattern to occupy the marker. The larger the value, the image will be much bigger and thus the border decreases."

javismiles commented 6 years ago

p9

I will try with this

javismiles commented 6 years ago

well, I tried, pass 2 identifies a candidate, and I dont get any .patt file produced anywhere, how did you get a .patt file? can you try with that file I put above?

artoolkitx_genMarkerSet --pattRatio 0.9 -dpi=72 p9.jpg Reading JPEG file... Done. JPEG image 'p9.jpg' is 1300x1300. Pass 1: detected 3 marker candidates. Pass 2: 1 detected marker candidates are square. 1300x1300 input image will display in 1280x720 window at 55.4% size

javismiles commented 6 years ago

I even tried now with your very own Hiro graphic you posted above, and I get the below but I dont see any .patt being generated

artoolkitx_genMarkerSet --pattRatio 0.5 -dpi=72 hiro.jpg Reading JPEG file... Done. JPEG image 'hiro.jpg' is 600x600. Pass 1: detected 2 marker candidates. Pass 2: 1 detected marker candidates are square. 600x600 input image will display in 1280x720 window at 120.0% size

javismiles commented 6 years ago

so when you say "then it generates a .pat file for you", then when, how? :) when :) nothing being generated here ;)

javismiles commented 6 years ago

puff, now once it worked with the hiro graphic, but just once and I cannot replicate it again, generated the patt file, but just once, this is..

javismiles commented 6 years ago

ok now now I can generate the .pat file, cool, ok now I gotta test it and see if it works ;)

Thorsten, thank u so much again for your help, I will test and tell u if the patt works ;)

javismiles commented 6 years ago

I notice until now I always use .PATT with 2 Ts with AR.JS. but this is a .PAT file with 1 T, will it work the same?

javismiles commented 6 years ago

So I tested the whole thing but it doesnt work, a few points