-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from habbes/dev
v0.7
- Loading branch information
Showing
26 changed files
with
880 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,94 @@ | ||
import { VideoSource } from '@/core/video'; | ||
|
||
/** | ||
* represents a library for managing files, | ||
* it provides access to add and read files of | ||
* different types | ||
* each file has unique name | ||
* the implementation is also assumed to track | ||
* metadata about each type internally (e.g. type) | ||
*/ | ||
export interface FileLibrary { | ||
|
||
/** | ||
* adds an image to the file source | ||
* @param fileUrl object url of the image | ||
* @param filename optional name for the file, if not provided, one will be auto-assigned | ||
*/ | ||
addImage(fileUrl: string, filename?: string): any; | ||
|
||
/** | ||
* adds a video to the file library | ||
* @param fileUrl object url of the image | ||
* @param filename optional name for the file, if not provided, one will be auto-assigned | ||
*/ | ||
addVideo(fileUrl: string, filename?: string): any; | ||
|
||
/** | ||
* adds a file of an arbitrary type | ||
* @param file blob containing the file | ||
* @param filename optional name assigned to the file in the library | ||
*/ | ||
addBinary(file: Blob, filename?: string): any; | ||
|
||
/** | ||
* reads a specified image from the library as an OpenCv matrix | ||
* @param name file name | ||
* @returns {cv.Mat} OpenCV matrix containing the image | ||
*/ | ||
readImage(name: string): any; | ||
|
||
/** | ||
* reads specified video from the library | ||
* @param name file name | ||
* @returns video | ||
*/ | ||
readVideo(name: string): VideoSource; | ||
|
||
/** | ||
* returns a reader to access the specified file as a blob | ||
* @param name | ||
*/ | ||
getReader(name: string): BinaryFileReader; | ||
|
||
/** | ||
* reads file based on its type | ||
* @param name file name | ||
* @returns depends on file type | ||
*/ | ||
read(name: string): any; | ||
|
||
/** | ||
* changes the name of a file in the library | ||
* @param oldName current name of the file | ||
* @param newName new name, should be unique in the library | ||
*/ | ||
rename(oldName: string, newName: string): any; | ||
} | ||
} | ||
|
||
export type FileType = 'image' | 'video' | 'binary'; | ||
|
||
/** | ||
* represents a wrapper around a blob | ||
*/ | ||
export interface BinaryFileReader { | ||
/** | ||
* the object url of the file. | ||
*/ | ||
url: string; | ||
|
||
/** | ||
* reads the contents of the file as text | ||
*/ | ||
readText(): Promise<any>; | ||
|
||
/** | ||
* returns the contents of the file as an ArrayBuffer | ||
*/ | ||
readBuffer(): Promise<any>; | ||
|
||
/** | ||
* returns the contents of the file as data url | ||
*/ | ||
readDataURL(): Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { applyMixins } from './mixins'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* applies mixins to a given class | ||
* @param derivedCtor target class | ||
* @param baseCtors mixins | ||
*/ | ||
export function applyMixins(derivedCtor: any, baseCtors: any[]) { | ||
baseCtors.forEach(baseCtor => { | ||
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { | ||
derivedCtor.prototype[name] = baseCtor.prototype[name]; | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import CAMERA from './camera'; | ||
import EDGE_DETECTION from './edge-detection'; | ||
import QUICK_INTRO from './quick-intro'; | ||
import SIMPLE_GREEN_SCREEN from './simple-green-screen'; | ||
import VIDEO from './video'; | ||
import WIDGETS from './widgets'; | ||
|
||
export { | ||
CAMERA, | ||
EDGE_DETECTION, | ||
QUICK_INTRO, | ||
SIMPLE_GREEN_SCREEN, | ||
VIDEO, | ||
WIDGETS | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export default | ||
`const { widgets, io: { imageViewer, files, cameras } } = xaval; | ||
const green = files.readVideo('green'); | ||
const greenStream = green.getStream({ fps: 30 }); | ||
const camera = cameras.getDefault(); | ||
const cameraStream = camera.getStream({ fps: 30 }); | ||
widgets.define('Blend', { | ||
params: { | ||
minG: { | ||
type: 'number', | ||
min: 0, | ||
max: 255, | ||
initial: 200 | ||
}, | ||
maxR: { | ||
type: 'number', | ||
min: 0, | ||
max: 255, | ||
initial: 50 | ||
}, | ||
maxB: { | ||
type: 'number', | ||
min: 0, | ||
max: 255, | ||
initial: 50 | ||
} | ||
}, | ||
inputs: ['green', 'target'], | ||
outputs: ['res'], | ||
onUpdate(ctx) { | ||
const { green, target } = ctx.inputs; | ||
const { minG, maxR, maxB } = ctx.params; | ||
const res = new cv.Mat(target.rows, target.cols, target.type()); | ||
cv.resize(green, res, res.size()); | ||
for (let row=0; row < res.rows; row++) { | ||
for (let col=0; col < res.cols; col++) { | ||
const [r, g, b] = res.ucharPtr(row, col); | ||
const tp = target.ucharPtr(row, col); | ||
if (r < maxR && b < maxB && g > minG) { | ||
res.data.set(tp, row * res.cols * res.channels() + col * res.channels()); | ||
} | ||
} | ||
} | ||
return { res }; | ||
} | ||
}); | ||
const widget = widgets.create('Blend'); | ||
widget.outputs.res.pipe(imageViewer); | ||
greenStream.pipe(widget.inputs.green); | ||
cameraStream.pipe(widget.inputs.target); | ||
camera.start(); | ||
green.looping = true; | ||
green.play(); | ||
`; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default | ||
`const { files, imageViewer } = xaval.io; | ||
// import video file in the file library | ||
// read imported video | ||
const video = files.readVideo('file1'); | ||
// get video stream and attach it to the image viewer | ||
const stream = video.getStream({ fps: 30 }); | ||
stream.pipe(imageViewer); | ||
// enable the following line if you want the video to loop | ||
// video.looping = true | ||
// play the video | ||
video.play(); | ||
`; |
Oops, something went wrong.