Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mods
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
mods
Commits
017762c4
Commit
017762c4
authored
3 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
start line scanner
parent
27ab50ac
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/input/video
+49
-2
49 additions, 2 deletions
modules/input/video
modules/processes/scan/line
+164
-0
164 additions, 0 deletions
modules/processes/scan/line
with
213 additions
and
2 deletions
modules/input/video
+
49
−
2
View file @
017762c4
...
...
@@ -28,7 +28,7 @@ var init = function() {
mod.width.value = 640
mod.height.value = 480
mod.flip.checked = false
star
t_video()
lis
t_video()
}
//
// inputs
...
...
@@ -67,6 +67,25 @@ var interface = function(div){
var canvas = document.createElement('canvas')
mod.img = canvas
//
// camera select
//
var select = document.createElement('select')
div.appendChild(select)
mod.select = select
div.appendChild(document.createElement('br'))
//
// start button
//
var btn = document.createElement('button')
btn.style.padding = mods.ui.padding
btn.style.margin = 1
btn.appendChild(document.createTextNode('start'))
btn.addEventListener('click',function() {
start_video()
})
div.appendChild(btn)
div.appendChild(document.createTextNode(' '))
//
// capture button
//
var btn = document.createElement('button')
...
...
@@ -149,6 +168,24 @@ var interface = function(div){
//
// local functions
//
// add cameras to list
//
function list_video() {
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
if (device.kind == 'videoinput') {
var el = document.createElement('option')
el.textContent = device.label
el.value = device.deviceId
mod.select.appendChild(el)
}
})
})
}
//
// start video
//
function start_video() {
var w = parseInt(mod.width.value)
var h = parseInt(mod.height.value)
...
...
@@ -157,19 +194,26 @@ function start_video() {
ctx.canvas.height = h
var constraints = {
audio:false,
video:{width:w,height:h}
video:{
width:w,height:h,
deviceId:{exact:mod.select.options[mod.select.selectedIndex].value}
}
}
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
mod.video.srcObject = stream
mod.video.onloadedmetadata = function(e) {
mod.video.play()
capture_video()
}
})
.catch(function(err) {
console.log(err.name+': '+err.message)
})
}
//
// update video
//
function update_video() {
var w = parseInt(mod.width.value)
var h = parseInt(mod.height.value)
...
...
@@ -179,6 +223,9 @@ function update_video() {
ctx.canvas.width = w
ctx.canvas.height = h
}
//
// capture video
//
function capture_video() {
var w = parseInt(mod.width.value)
var h = parseInt(mod.height.value)
...
...
This diff is collapsed.
Click to expand it.
modules/processes/scan/line
0 → 100644
+
164
−
0
View file @
017762c4
//
// line scan
//
// (c) MIT CBA Neil Gershenfeld 9/26/21
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the fab modules
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// closure
//
(function(){
//
// module globals
//
var mod = {}
//
// name
//
var name = 'line scan'
//
// initialization
//
var init = function() {
mod.width.value = 10
//
// open scan window
//
var win = window.open('')
win.document.title = "scan window"
win.document.body.appendChild(document.createElement('br'))
var canvas = document.createElement('canvas')
win.document.body.appendChild(canvas)
mod.scan = canvas
mod.win = win
}
//
// inputs
//
var inputs = {
image:{type:'RGBA',
event:function(evt) {
scanloop(evt.detail)
}
}
}
//
// outputs
//
var outputs = {
trigger:{type:'event',
event:function(){
mods.output(mod,'trigger',null)
}
}
}
//
// interface
//
var interface = function(div){
mod.div = div
//
// on-screen drawing canvas
//
var canvas = document.createElement('canvas')
canvas.width = mods.ui.canvas
canvas.height = mods.ui.canvas
canvas.style.backgroundColor = 'rgb(255,255,255)'
div.appendChild(canvas)
mod.img = canvas
div.appendChild(document.createElement('br'))
//
// line width
//
div.appendChild(document.createTextNode('scan line width (pixels): '))
var input = document.createElement('input')
input.type = 'text'
input.size = 6
input.addEventListener('change',function(){
alert('width')
})
div.appendChild(input)
mod.width = input
//
// start scan button
//
div.appendChild(document.createElement('br'))
div.appendChild(document.createTextNode(' '))
var btn = document.createElement('button')
btn.style.padding = mods.ui.padding
btn.style.margin = 1
btn.appendChild(document.createTextNode('start scan'))
btn.addEventListener('click',function(){
linescan()
})
div.appendChild(btn)
}
//
// local functions
//
// line scan
//
function linescan() {
mod.l = parseFloat(mod.width.value)
mod.w = mod.win.innerWidth
mod.h = mod.win.innerHeight
mod.scan.width = mod.w
mod.scan.height = mod.h
mod.y = 0
mod.state = 'start'
scanloop(null)
}
//
// scan loop
//
function scanloop(input) {
if (mod.state == 'start') {
//
// take background
//
var ctx = mod.scan.getContext("2d")
ctx.fillStyle = "black"
ctx.fillRect(0,0,mod.w,mod.h)
mod.state = 'background'
outputs.trigger.event()
}
else if (mod.state == 'background') {
//
// save background, start scan
//
mod.state = 'scan'
outputs.trigger.event()
}
else if (mod.state == 'scan') {
//
// scan
//
mod.y += mod.l
var ctx = mod.scan.getContext("2d")
ctx.lineWidth = mod.l
ctx.fillStyle = "black"
ctx.fillRect(0,0,mod.w,mod.h)
ctx.strokeStyle = "white"
ctx.beginPath()
ctx.moveTo(0,mod.y)
ctx.lineTo(mod.w,mod.y)
ctx.stroke()
if (mod.y < mod.h)
outputs.trigger.event()
}
}
//
// return values
//
return ({
name:name,
init:init,
inputs:inputs,
outputs:outputs,
interface:interface
})
}())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment