Git Product home page Git Product logo

stereo-img's Introduction

<stereo-img>

<stereo-img> is a web component to display stereographic pictures on web pages, with VR support. It supports various stereo picture formats: VR Photos (VR180, Google Camera panorama, Photosphere), left-right, and anaglyph.

See the demo for an example.

How to use

Load the module:

<script type="module" src="https://stereo-img.steren.fr/stereo-img.js"></script>

Then use the <stereo-img> custom element anywhere in your page or app, reference a stereo picture in the src attribute:

<stereo-img src="picture.vr.jpg"></stereo-img>

Alternatively, you can serve the module from your own server, install it via npm:

npm install stereo-img

Attributes

  • src: (Required) source of the stereo picture (absolute or relative)
  • type: (Optional) type of stereo picture:
    • If unset, type is inferred from heuristics
    • vr: VR Photo - VR180, Google Camera panorama, Cardboard Camera, Photosphere images (Where right eye image and angle of view info are embedded in the image metadata)
    • left-right: left eye on the left, right eye on the right, Exif angle of view is used if present.
    • right-left: left eye on the right, right eye on the left, Exif angle of view is used if present.
    • top-bottom: left eye on the top, right eye on the bottom, Exif angle of view is used if present.
    • bottom-top: left eye on the bottom, right eye on the top, Exif angle of view is used if present.
    • anaglyph: Anaglyph 3D - currently only supporting red / green
    • depth: Picture with depth map (e.g. portrait mode on Google Camera)
  • angle: (Optional) hint at angle of view for left-right or top-bottom types
    • If unset, Exif angle of view is used if present.
    • 180: Half sphere (VR180)
    • 360: Full sphere
  • projection: (Optional) hint at projection (most VR pictures use equirectangular projection)
    • If unset, projection is inferred from heuristics.
    • equirectangular: Equirectangular projection
    • fisheye: Fisheye projection
  • wiggle: (Optional) When viewing in 2D, alternate between left and right images to help the user see the 3D effect
    • enabled: wiggle is enabled
    • disabled: wiggle is disabled

Compatibility

Supported cameras

This component has been manually tested to load pictures taken with the following cameras:

Status Camera Picture type Attributes required Field of view Orientation
✔️ Lenovo Mirage Camera VR180 (none)
✔️ Canon RF5.2mm F2.8 L Duel Fisheye unprocessed left-right fisheye (none) X X
✔️ Canon RF5.2mm F2.8 L Duel Fisheye processed with EOS VR Utility left-right (none) X X
✔️ Insta360 Evo left-right (none) X X
✔️ CALF VR180 left-right (none) X X
✔️ CALF VR180 "vr180" angle="180" X X
✔️ Kandao QooCam EGO 3D Camera left-right (none) X X
✔️ Pixel phone depth type="depth" X X
Vision Pro

Supported viewers and headsets

This component has been manually tested on the following hardware, OS and browsers:

Hardware OS Browser Status
HTC Vive Windows Chrome ✔️
HTC Vive Windows Firefox ✔️⚠️ With WebXR polyfill
HTC Vive Windows Firefox Reality ✔️
Cardboard Android Chrome ✔️
Cardboard Android Firefox
Cardboard iOS #18
Quest 1 Default ✔️
Quest 2 Default ✔️️
Quest 3 Default ✔️️
Vision Pro Safari #34

Installing using npm

Instead of a CDN, you can install the module locally using npm:

npm install stereo-img

Then, use a JavaScript builder or import-maps to load the module and its dependencies:

If using import-maps:

<!-- Shim for importmap -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
  {
    "imports": {
      "stereo-img": "./node_modules/stereo-img/stereo-img.js",
      "exifr": "./node_modules/exifr/dist/full.esm.js",
      "three": "./node_modules/three/build/three.module.js",
      "three/": "./node_modules/three/"
    }
  }
</script>

Then load the stereo-img module:

<script type="module">import "stereo-img";</script>

Contributing

See development instructions and contribution guidelines

stereo-img's People

Contributors

34j avatar steren avatar tenkabuto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

stereo-img's Issues

Quest 3 as Viewer/Headset

The component seems to be working on my Quest 3's Default browser. That is, I'm able to enter the immersive mode and view the photo.

Add detector for fisheye

In #21, I hardcoded the assumption that any picture taken with Canon EOS R5 RF5.2mm F2.8 L Dual Fisheye was fisheye, but that's not true if they have been processed.

We should look at pixel colors in the corner and middle of the image to see if they are black. If they are, assume fisheye

Optimize impact on page performances

Do not start a Three.js scene before the user interacts with the component (to avoid potentially creating too many WebGL contexts), use a canvas2d fallback in the meanwhile.

Canon EOS R5 Duel Fisheye not properly supported

  1. The projection isn't right (see example with vertical lines): is it due to 190deg fov?
  2. the auto cropping isn't working properly (black at top / bottom): maybe start at least by assuming top / bottom are from a circle

Use 6 degrees of freedom?

Viewing VR180 leads to a strange sensation, it seems that only head rotation is used and the position stays fixed?

Images from Insta360 Evo not supported

sample

When using this image as a sample, I get an error :-

stereo-img.js:204 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'width')
    at StereoImg.createEye (stereo-img.js:204:21)
    at StereoImg.initialize3DScene (stereo-img.js:311:18)
    at async StereoImg.parseImageAndInitialize3DScene (stereo-img.js:320:7)
    at async StereoImg.init (stereo-img.js:366:7)

You can keep this image as an example for your project, thanks

Optimize network calls

Looks like the image is downlowded 4 times, which doesn't play well if the server doesn't cache

Better handling of images not served over HTTPS

I've tried a few SBS 3D images and I always get the same result: views fine in non-VR mode but the 'Enter VR' mode doesn't seem to enter the WebXR mode and instead just displays a binocular stereo view with image data only in the left eye, which does respond to headset movement but the right eye is empty and it just doesn't enter the WebXR view so there's no 3D visualisation. Here's two examples, one a VR180 fisheye SBS image from a Insta360 Evo and a non VR-180 3d image from a Sony Bloggie 3d camera. Example code :-

<stereo-img src="media/bloggie.jpg" wiggle="false"></stereo-img>

20200207_194652_700

bloggie

Update three.js

When I try switching to three 0.160, the render appears brighter.

Support images from arbitrary origins

Hello, firstly, thank you for your work on this project! I found this project somewhat randomly, searching on Github, so please bear with me.

I'm running into an issue when I started serving my images through S3, that hopefully has an easy fix.

Uncaught (in promise) DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
    at parseStereo (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:84:128)
    at async HTMLElement.parse (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:220:25)
    at async HTMLElement.parseImageAndInitialize3DScene (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:275:5)
    at async HTMLElement.init (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/stereo-img.js:292:5)

I poked around a little bit, and apparently you can set an option to allow anonymous cross-origin on the canvas image: https://stackoverflow.com/questions/22097747/how-to-fix-getimagedata-error-the-canvas-has-been-tainted-by-cross-origin-data

Setting the headers as outlined in the answer there is easy to do on my end.

Perhaps there are alternative solutions as well?

Thanks for taking a look.

Image distortion -L-R jpg format

Left-right photos are anamorphic at the top and bottom of the screen.
Whatever the format !
Tested on Quest 3.

You can compare your pictures with stereo photo maker results
(Make html5 stereo viewer option)

I cannot use your component !

Ensure pictures taken with CALF VR180 are supported

My Wordpress site is stripping the metadata and it results in an error after parsing the EXIF and other headers:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'GPano')
    at parseVR (stereo-img.js:23:19)
    at async HTMLElement.parse (stereo-img.js:218:25)
    at async HTMLElement.parseImageAndInitialize3DScene (stereo-img.js:275:5)
    at async HTMLElement.init (stereo-img.js:292:5)

A simple null-coalesce should solve the problem, or just short-circuiting and going with defaults if exif is undefined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.