Skip to content

Commit

Permalink
Add focusDistance constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed May 16, 2017
1 parent 6e2307d commit b742bc9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions implementation-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Feature/Platform | Android | Linux/ChromeOS | Windows | Mac |
└ contrast | | ✓ | M60 [1] | |
└ exposureCompensation | ✓ | | M60 [1] | |
└ exposureMode | ✓ | ✓ | M60 [1] | |
└ focusDistance | | | | |
└ focusMode | ✓ | ✓ | M60 [1] | |
└ iso | ✓ | | | |
└ pointsOfInterest | ✓ | | | |
Expand Down
77 changes: 77 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ This Section defines a number of new set of <a>Constrainable Properties</a> for
boolean contrast = true;
boolean saturation = true;
boolean sharpness = true;
boolean focusDisance = true;
boolean zoom = true;
boolean torch = true;
};
Expand Down Expand Up @@ -379,6 +380,9 @@ This Section defines a number of new set of <a>Constrainable Properties</a> for
<dt><dfn dict-member for="MediaTrackSupportedConstraints"><code>sharpness</code></dfn></dt>
<dd>Whether <a>sharpness</a> constraining is recognized.</dd>

<dt><dfn dict-member for="MediaTrackSupportedConstraints"><code>focusDistance</code></dfn></dt>
<dd>Whether <a>focus distance</a> constraining is recognized.</dd>

<dt><dfn dict-member for="MediaTrackSupportedConstraints"><code>zoom</code></dfn></dt>
<dd>Whether configuration of the <a>zoom</a> level is recognized.</dd>

Expand All @@ -405,6 +409,7 @@ This Section defines a number of new set of <a>Constrainable Properties</a> for
MediaSettingsRange saturation;
MediaSettingsRange sharpness;

MediaSettingsRange focusDistance;
MediaSettingsRange zoom;

boolean torch;
Expand Down Expand Up @@ -444,6 +449,9 @@ This Section defines a number of new set of <a>Constrainable Properties</a> for
<dt><dfn dict-member for="MediaTrackCapabilities"><code>sharpness</code></dfn></dt>
<dd>This reflects the permitted <a>sharpness</a> range of the camera. Values are numeric. Increasing values indicate increasing sharpness, and the minimum value always implies no sharpness enhancement or processing.</dd>

<dt><dfn dict-member for="MediaTrackCapabilities"><code>focusDistance</code></dfn></dt>
<dd>This reflects the <a>focus distance</a> value range supported by the UA.</dd>

<dt><dfn dict-member for="MediaTrackCapabilities"><code>zoom</code></dfn></dt>
<dd>This reflects the <a>zoom</a> value range supported by the UA.</dd>

Expand Down Expand Up @@ -475,6 +483,7 @@ This Section defines a number of new set of <a>Constrainable Properties</a> for
ConstrainDouble saturation;
ConstrainDouble sharpness;

ConstrainDouble focusDistance;
ConstrainDouble zoom;

ConstrainBoolean torch;
Expand Down Expand Up @@ -517,6 +526,9 @@ This Section defines a number of new set of <a>Constrainable Properties</a> for
<dt><dfn dict-member for="MediaTrackConstraintSet"><code>sharpness</code></dfn></dt>
<dd>See <a>sharpness</a> constrainable property.</dd>

<dt><dfn dict-member for="MediaTrackConstraintSet"><code>focusDistance</code></dfn></dt>
<dd>See <a>focus distance</a> constrainable property.</dd>

<dt><dfn dict-member for="MediaTrackConstraintSet"><code>zoom</code></dfn></dt>
<dd>See <a>zoom</a> constrainable property.</dd>

Expand Down Expand Up @@ -544,6 +556,7 @@ When the {{getSettings()}} method is invoked on a video stream track, the user a
double saturation;
double sharpness;

double focusDistance;
double zoom;

boolean torch;
Expand Down Expand Up @@ -586,6 +599,9 @@ When the {{getSettings()}} method is invoked on a video stream track, the user a
<dt><dfn dict-member for="MediaTrackSettings"><code>sharpness</code></dfn></dt>
<dd>This reflects the current <a>sharpness</a> setting of the camera.</dd>

<dt><dfn dict-member for="MediaTrackSettings"><code>focusDistance</code></dfn></dt>
<dd>This reflects the current <a>focus distance</a> setting of the camera.</dd>

<dt><dfn dict-member for="MediaTrackSettings"><code>zoom</code></dfn></dt>
<dd>This reflects the current <a>zoom</a> setting of the camera.</dd>

Expand Down Expand Up @@ -670,6 +686,8 @@ When the {{getSettings()}} method is invoked on a video stream track, the user a
</div>
</li>

<li><dfn>Focus distance</dfn> is a numeric camera setting that controls the focus distance of the lens. The setting usually represents distance in millimeters to the optimal focus distance.</li>

<li><dfn>Zoom</dfn> is a numeric camera setting that controls the focal length of the lens. The setting usually represents a ratio, e.g. 4 is a zoom ratio of 4:1. The minimum value is usually 1, to represent a 1:1 ratio (i.e. no zoom).</li>

<li><dfn>Fill light mode</dfn> describes the flash setting of the capture device (e.g. |auto|, |off|, |on|). <dfn>Torch</dfn> describes the setting of the source's fill light as continuously connected, staying on as long as {{track}} is active.</li>
Expand Down Expand Up @@ -894,6 +912,65 @@ A {{Point2D}} represents a location in a two dimensional space. The origin of co
</pre>
</div>

## Update camera focus distance and {{takePhoto()}} ## {#example4}

<div class="example" highlight="javascript">
<pre>
&lt;html>
&lt;body>
&lt;video autoplay>&lt;/video>
&lt;img>
&lt;input type="range" hidden>
&lt;script>
var imageCapture;

navigator.mediaDevices.getUserMedia({video: true})
.then(gotMedia)
.catch(err => console.error('getUserMedia() failed: ', err));

function gotMedia(mediastream) {
const video = document.querySelector('video');
video.srcObject = mediastream;

const track = mediastream.getVideoTracks()[0];
imageCapture = new ImageCapture(track);

const capabilities = track.getCapabilities()
// Check whether focus distance is supported or not.
if (!capabilities.focusDistance) {
return;
}

// Map focus distance to a slider element.
const input = document.querySelector('input[type="range"]');
input.min = capabilities.focusDistance.min;
input.max = capabilities.focusDistance.max;
input.step = capabilities.focusDistance.step;
input.value = track.getSettings().focusDistance;

input.oninput = function(event) {
track.applyConstraints({
advanced : [{focusMode: "manual", focusDistance: event.target.value}]
});
}
input.hidden = false;
}

function takePhoto() {
imageCapture.takePhoto()
.then(blob => {
console.log('Photo taken: ' + blob.type + ', ' + blob.size + 'B');

const image = document.querySelector('img');
image.src = URL.createObjectURL(blob);
})
.catch(err => console.error('takePhoto() failed: ', err));
}
&lt;/script>
&lt;/body>
&lt;/html>
</pre>
</div>



Expand Down

0 comments on commit b742bc9

Please sign in to comment.