Tastenkunst / brfv4_javascript_examples

BRFv4 - HTML5/Javascript - examples project. Reference implementation for all other platform example packages.
463 stars 148 forks source link

No tracking with camera tilted 90 degrees for Portrait mode. #62

Closed akshajb closed 5 years ago

akshajb commented 5 years ago

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?

MarcelKlammer commented 5 years ago

Are you working with Manja?

akshajb commented 5 years ago

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

akshajb commented 5 years ago

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

MarcelKlammer commented 5 years ago

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.

akshajb commented 5 years ago

Okaay. Any pointers on how to achieve that.

MarcelKlammer commented 5 years ago

https://stackoverflow.com/questions/23346166/rotate-image-by-90-degrees-on-html5-canvas

akshajb commented 5 years ago

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

MarcelKlammer commented 5 years ago

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.

akshajb commented 5 years ago

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

akshajb commented 5 years ago

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?

MarcelKlammer commented 5 years ago

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.

akshajb commented 5 years ago

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

MarcelKlammer commented 5 years ago

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

akshajb commented 5 years ago

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

akshajb commented 5 years ago

I am working on the color libs example

akshajb commented 5 years ago

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

MarcelKlammer commented 5 years ago

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.

akshajb commented 5 years ago

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

akshajb commented 5 years ago

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

akshajb commented 5 years ago

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.