How to properly set imageTarget size

0 votes
asked Sep 11, 2017 by goblin67 (230 points)

Hello. I am fiddling with the ARVideo sample and I have added a square 360x360 image as a target with a new video. It works ok but of course the video is square as well.

So I tried to set the size of the new image in the json, like this:

{        "image" : "bunny2.jpg",

        "name" : "bunny",

        "size" : [320, 240],

        "uid" : "001"

    },

in order to respect the aspect ratio of the mp4 video, but no matter which values do I set, the result is always a square video, ratio 1:1

What am I doing wrong?

Thanks in advance,

P

1 Answer

0 votes
answered Sep 11, 2017 by albert52 (31,850 points)

hi,

You can set it by transform.localScale.Such as:

subGameObject.transform.localScale = new Vector3(0.08f, 0.07f, 0.1f);

commented Sep 12, 2017 by goblin67 (230 points)
Hi Albert, thanks for your reply but I don't understand what you're referring to.
I am using the native SDK for iOS, maybe your answer is relevanto to the Unity API.

For the record, the code I am trying to modify is this:

 [current_video_renderer render:[camera projectionGL:0.2f farPlane:500.f] cameraview:[targetInstance poseGL] size:[imagetarget size]];

I am trying to modify [imagetarget size], but no matter how I set it, the aspect ratio is still locked to 1:1, for example if I set it to (320, 240) it gets set automatically to (320, 320).

Documentation says: When the size is set to have the same aspect ratio as image resolution, it will make no difference after recalculation and the size will not actually change

But I can't find a way NOT to set the imageTarget object to have the same aspect ratio as image resolution.

Looking for help, thanks.

P
commented Sep 12, 2017 by goblin67 (230 points)
Never mind, I have managed to find a way, don't know if it's best practice but it works:

                        // force video aspect ratio to 4:3
                        easyar_Vec2F *newSize = imagetarget.size;
                        NSMutableArray *newData = [newSize.data mutableCopy];
                        newData[0] = [NSNumber numberWithFloat:1.0];
                        newData[1] = [NSNumber numberWithFloat:0.75];
                        newSize.data = newData;
                        
                        [current_video_renderer render:[camera projectionGL:0.2f farPlane:500.f] cameraview:[targetInstance poseGL] size:newSize];

Feel free to suggest a better solution, though :-)

Cheers,

P
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...