Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html5摄像头模糊-getuserMedia自动对焦不工作_Html_Video_Camera_Html5 Video - Fatal编程技术网

html5摄像头模糊-getuserMedia自动对焦不工作

html5摄像头模糊-getuserMedia自动对焦不工作,html,video,camera,html5-video,Html,Video,Camera,Html5 Video,有人尝试过HTML5视频从手机上的摄像头拍摄图像,但有图像模糊的问题吗?我在三星手机上试过,图像清晰,在LG G4上图像模糊(两款手机上都有android浏览器和Chrome)。 有没有人有这样的经验或能解释解决方案?有些手机会有这些问题吗 下面是我使用的代码片段: function startCamera(newSource) { if (newSource) { var constraints = { audio: fa

有人尝试过HTML5视频从手机上的摄像头拍摄图像,但有图像模糊的问题吗?我在三星手机上试过,图像清晰,在LG G4上图像模糊(两款手机上都有android浏览器和Chrome)。 有没有人有这样的经验或能解释解决方案?有些手机会有这些问题吗

下面是我使用的代码片段:

function startCamera(newSource) {
        if (newSource) {
            var constraints = {
                audio: false,
                video: {
                    optional: [
                        { sourceId: newSource },
                    ]
                }
            };

            addVideoAndCanvas();

            navigator.getUserMedia(constraints, onMediaSuccess, onMediaError); 
        }
    }

    function addVideoAndCanvas() {
        self.video = $('<video muted autoplay>');
        self.canvas = $('<canvas id="qr-canvas" class="hide">');
        $('.modal-body .video-container', self.root).append(self.video).append(self.canvas);
    }

    function onMediaSuccess(stream) {
        self.stream = stream;
        self.video[0].src = (window.URL && window.URL.createObjectURL(stream)) || stream;

        self.video[0].onloadeddata = function () {                
            self.canvas[0].height = self.video[0].videoHeight;
            self.canvas[0].width = self.video[0].videoWidth;
            scan();
        }                   
    }

    function onMediaError(error) {            
    }

    function scan() {
        if (self.stream) {                
            try {
                var ctx = self.canvas[0].getContext('2d');
                ctx.drawImage(self.video[0], 0, 0);

            } catch (e) {
                setTimeout(scan, 20);
            }
        } else {
            setTimeout(scan, 20);
        }
    }
函数startCamera(新闻源){
如果(新闻源){
变量约束={
音频:错,
视频:{
可选:[
{sourceId:newSource},
]
}
};
添加VideoAndCanvas();
getUserMedia(约束、onMediaAccess、onMediaError);
}
}
函数addVideoAndCanvas(){
self.video=$('');
self.canvas=$('');
$('.modal body.video container',self.root).append(self.video).append(self.canvas);
}
函数onMediaAccess(流){
self.stream=流;
self.video[0].src=(window.URL&&window.URL.createObjectURL(stream))| | stream;
self.video[0]。onloadeddata=function(){
self.canvas[0]。高度=self.video[0]。视频高度;
self.canvas[0]。宽度=self.video[0]。videoWidth;
扫描();
}                   
}
函数onMediaError(错误){
}
函数扫描(){
if(self.stream){
试一试{
var ctx=self.canvas[0].getContext('2d');
ctx.drawImage(self.video[0],0,0);
}捕获(e){
设置超时(扫描,20);
}
}否则{
设置超时(扫描,20);
}
}

可能正在等待以下规范: