Caputre Cam with JS
How do I make an caputre cam with js?
Here we use a phpacademy video tutorial as a base of creating javascript that grabs the user's video and draws it to a canvas element. This drawn video's rgb-values are then changed with javascript.. What is a caputre cam with js? How do you make a caputre cam with js? This script and codes were developed by KimmoCommit on 14 January 2023, Saturday.
Caputre Cam with JS - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Caputre Cam with JS</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="booth"> <video id="video" width="400" height="300" autoplay></video>
<canvas id="canvas" width="400" height="300"></canvas>
</div> <script src="js/index.js"></script>
</body>
</html>
Caputre Cam with JS - Script Codes CSS Codes
#booth { width: 400px; border: 10px solid grey; margin: 0 auto; background-color: #ccc;
}
Caputre Cam with JS - Script Codes JS Codes
//self inwoking function that is run when page loads
(function() { var canvas = document.getElementById('canvas'), context = canvas.getContext("2d"), video = document.getElementById('video'), vendorUrl = window.URL || window.webkitURL; navigator.getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; //js object navigator.getMedia({ video: true, audio: false }, function(stream){ video.src = vendorUrl.createObjectURL(stream); video.play(); }, function(error){ //some errors occured //console.log(error.code()); }); function draw(video, context, width, height){ // i is set to be the variable that represents the pixels that we loop through (increment) var image, data, i, r, g, b, brightness; context.drawImage(video, 0, 0, width, height); //getImageData returns color values in each pixel that are found canva's context - try running console.log(data) to see the results in the log image = context.getImageData(0,0, width, height); data = image.data; //here we loop through all of the pixels and turn their color which we want and set them back up again for(i = 0; i < data.length; i = i + 4){ r = data[i]; g = data[i + 1]; b = data[i + 2]; brightness = ( (r + 22) + (g + 0) + (b + 10) ) / 3; //here we assign one value to all of the three data[i] = data[i + 1] = data[i + 2] = brightness; } image.data = data; context.putImageData(image, 0, 0); //to not only call "draw" functon only once, we set this timeout setTimeout(draw, 22, video, context, width, height); } video.addEventListener("play", function(){ alert("There is some issues with loading this draw function - this alert helps it appear on FireFox"); draw(this, context, 400, 300); }, false); })();
Developer | KimmoCommit |
Username | KimmoCommit |
Uploaded | January 14, 2023 |
Rating | 3 |
Size | 2,795 Kb |
Views | 6,072 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Animate Divs on top of each other | 0 Kb |
Overflow ellipsis with own dot color | 0 Kb |
A Pen by KimmoCommit | 0 Kb |
Copy to clipboard JS | 0 Kb |
Hole to an image with SVG | 0 Kb |
Custom Checkboxes with pop-effect | 0 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Plotting Points with D3.js | Laurakelly | 31,996 Kb |
Ripples in water | Nobitagit | 2,704 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
Getting Started | Viblast | 1,500 Kb |
Masonry | Uriuriuriu | 5,005 Kb |
A Pen by Huan Nghiem | Nightshade | 10,646 Kb |
Css3 only dropdown menu | Riogrande | 2,519 Kb |
3D-box | Parthviroja | 2,346 Kb |
Awesome | Samarthpd | 2,901 Kb |
3d css cube | Semenchenko | 4,578 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!