Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

javascript - 如何从网络摄像头Reactjs获取每个帧(How to get each frame from the webcam Reactjs)

I am running web cam from navigator.media devices and its working fine, but I want to get each single frame from a video how can I achieve that?

(我正在从navigator.media设备运行网络摄像头,并且运行正常,但是我想从视频中获取每个帧,我该如何实现?)

class Recognize extends Component {
    constructor(props) {
        super(props);
        this.videoTag = React.createRef();
        this.myStream = null;
        this.state = {
            baseimage:null,
            iterator:0,
            flag:false,
            stop:false,
            screenshot:null
        };
    }

    componentDidMount() {
        navigator.mediaDevices
            .getUserMedia({ video: true })
            .then(this.handleStream)
            .catch(err => console.log(err));
    }

    componentWillUnmount() {
        this.myStream.getTracks()
            .forEach((track) => track.stop());
    }

    handleStream = async stream => {
        // start receiving stream from webcam
        this.myStream=stream;
        this.videoTag.current.srcObject = stream;

        // let img=stream.getScreenshot();
        // console.log(typeof (img));
        console.log("The video is ready");
    };






    render() {


        return (
            <Grid fluid>

                <video
                    id="myvideo"
                    ref={this.videoTag}
                    width={0}
                    height={0}
                    autoPlay
                    title="video"
                />

                <br></br>



            </Grid>
        );
    }
}


export default Recognize

I have tried to use ImageCapture in handlestream(),so I can grabFrame afterwards but unable to achieve

(我试图在handlestream()中使用ImageCapture,所以以后可以抓取Frame但无法实现)

let mediaStreamTrack = stream.getVideoTracks()[0];
        imageCapture =new ImageCamera(mediaStreamTrack)  // its constructor is not working

but when I initialize the new object of Imagecapture it won't work.

(但是当我初始化Imagecapture的新对象时,它将无法工作。)

  ask by Nabeel Ayub translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...