Tastenkunst/brfv4_javascript_examples

No tracking with camera tilted 90 degrees for Portrait mode.

akshajb opened this issue · 20 comments

I am using an IntelliSense camera, which gives a landscape view, the tracking works well, but if i turn the camera 90 degrees, for portrait, there is no tracking. Is it possible for the camera to track in a different orientation?

Are you working with Manja?

I don't really know what or who that is.

I am trying to deploy a mirror-like experience, For that, it should be in portrait mode. But when I tilt the camera, i need to tilt my head too , for it to track

That orientation question came up in a recent email contact I had. Anyway...

If you want to track in portrait you need to draw the canvas 90 degress rotated.

Okaay. Any pointers on how to achieve that.

When I inspect, there are around 5 canvas tags. I need to rotate all of them or only the ones that are for the webcam feed

Take a look at the minimal example:
https://github.com/Tastenkunst/brfv4_javascript_examples/blob/master/minimalWebcam.html
https://github.com/Tastenkunst/brfv4_javascript_examples/blob/master/js/BRFv4DemoMinimalWebcam.js#L255

In that line the video is drawn onto the canvas. the drawing happens mirrored.
Depending on the physical rotation of your camera you need to either rotate the canvas clockwise or counter clockwise and then draw.

Thank you for your help, will get back if I get stuck. !

imageDataCtx.setTransform(-1.0, 0, 0, 1, resolution.width, 0); // A virtual mirror should be... mirrored imageDataCtx.drawImage(webcam, 0, 0, resolution.width, resolution.height); imageDataCtx.setTransform( 1.0, 0, 0, 1, 0, 0); // unmirrored for drawing the results
the results is the vertices on the face right?

Yes. The Canvas needs to take the video (scaled (mirrored) and/or rotated). But after that drawing of the video onto the canvas, that's the input for BRF. So canvas transform needs to be not scaled/rotated to draw the tracking results correctly.

So the result need not be transformed. only then top one.

Only the video drawing into the canvas needs to take scale and rotation of the video/camera into account.

Currently I am unable to get the setTransorm to transform my video feed. But even if it does, will the tracking happen, when the camera is in portrait mode

I am working on the color libs example

Currently I am unable to get the setTransorm to transform my video feed. But even if it does, will the tracking happen, when the camera is in portrait mode

I am able to rotate the imageData canvas, so the camera turns to portrait mode. but but tracking does not happen yet

Did you set the correct image size?

BRF needs to know the image data size (eg. 480x640), so resolution needs the correct size.
Also make sure that

imageDataCtx.getImageData(0, 0, resolution.width, resolution.height).data

width and height are correct here as well.

I used setTransform in BRFvSetupWebcam.js, before drawImage. And tracking works in portrait mode.

Also any idea on how to get my webcam aspect ratio 16:9, now width and height are both equal in Portrait mode

I am using the following code for rotating before drawImage

function degs_to_rads (degs) { return degs / (360/Math.PI); } function rads_to_degs (rads) { return rads * (180/Math.PI); } var rotation_degs = 180, rotation_rads = degs_to_rads(rotation_degs), angle_sine = Math.sin(rotation_rads), angle_cosine = Math.cos(rotation_rads); var _imageDataCtx = imageDataCanvas.getContext("2d"); _imageDataCtx.setTransform(angle_cosine, angle_sine, -angle_sine, angle_cosine, resolution.width, 0); _imageDataCtx.drawImage(webcamVideo, 0, 0, resolution.width, resolution.height);

With this I am able to mount my camera vertically and it still tracks, BUT the feed i get in default is portrait mode, and when i turn it to vertical it still becomes landscape feed. Any help in transforming the right way.