Commit 6c25e874 by vincent

remove unused stuff

parent 83d51e42
import { TMediaElement, TNetInput } from './types'; import { Dimensions, TMediaElement, TNetInput } from './types';
import { Dimensions, getContext2dOrThrow, getElement, getMediaDimensions } from './utils'; import { getContext2dOrThrow, getElement, getMediaDimensions } from './utils';
export class NetInput { export class NetInput {
private _canvases: HTMLCanvasElement[] private _canvases: HTMLCanvasElement[]
......
export type TMediaElement = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement export type TMediaElement = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement
export type TNetInputArg = string | TMediaElement export type TNetInputArg = string | TMediaElement
export type TNetInput = TNetInputArg | Array<TNetInputArg> export type TNetInput = TNetInputArg | Array<TNetInputArg>
export type Dimensions = {
width: number
height: number
}
export type DrawBoxOptions = {
lineWidth: number
color: string
}
export type DrawTextOptions = {
fontSize: number
fontStyle: string
color: string
}
\ No newline at end of file
import { FaceDetectionNet } from './faceDetectionNet/types'; import { FaceDetectionNet } from './faceDetectionNet/types';
import { DrawBoxOptions, DrawTextOptions } from './types';
export function isFloat(num: number) {
return num % 1 !== 0
}
export function round(num: number) {
return Math.floor(num * 100) / 100
}
export function getElement(arg: string | any) { export function getElement(arg: string | any) {
if (typeof arg === 'string') { if (typeof arg === 'string') {
...@@ -22,93 +31,6 @@ export function getMediaDimensions(media: HTMLImageElement | HTMLVideoElement) { ...@@ -22,93 +31,6 @@ export function getMediaDimensions(media: HTMLImageElement | HTMLVideoElement) {
return media return media
} }
export function isFloat(num: number) {
return num % 1 !== 0
}
export function round(num: number) {
return Math.floor(num * 100) / 100
}
export type Dimensions = {
width: number
height: number
}
export function toNetInput(
canvasArg: string | HTMLCanvasElement,
mediaArg: string | HTMLImageElement | HTMLVideoElement,
dims?: Dimensions
): HTMLCanvasElement {
const canvas = getElement(canvasArg)
const media = getElement(mediaArg)
if (!(canvas instanceof HTMLCanvasElement)) {
throw new Error('drawMediaToCanvas - expected canvas to be of type: HTMLCanvasElement')
}
if (!(media instanceof HTMLImageElement || media instanceof HTMLVideoElement)) {
throw new Error('drawMediaToCanvas - expected media to be of type: HTMLImageElement | HTMLVideoElement')
}
const { width, height } = dims || getMediaDimensions(media)
canvas.width = width
canvas.height = height
const ctx = getContext2dOrThrow(canvas)
ctx.drawImage(media, 0, 0, width, height)
return canvas
}
export function mediaToImageData(media: HTMLImageElement | HTMLVideoElement, dims?: Dimensions): ImageData {
if (!(media instanceof HTMLImageElement || media instanceof HTMLVideoElement)) {
throw new Error('mediaToImageData - expected media to be of type: HTMLImageElement | HTMLVideoElement')
}
const canvas = toNetInput(document.createElement('canvas'), media)
const ctx = getContext2dOrThrow(canvas)
const { width, height } = dims || getMediaDimensions(media)
return ctx.getImageData(0, 0, width, height)
}
export function mediaSrcToImageData(
src: string | HTMLImageElement | HTMLVideoElement
): Promise<ImageData> {
return new Promise((resolve, reject) => {
if (typeof src !== 'string') {
if (!(src instanceof HTMLImageElement || src instanceof HTMLVideoElement)) {
return reject('mediaSrcToImageData - expected src to be of type: string | HTMLImageElement | HTMLVideoElement')
}
return resolve(mediaToImageData(src))
}
const img = new Image()
img.onload = () => resolve(mediaToImageData(img))
img.onerror = reject
img.src = src
})
}
export function bufferToImgSrc(buf: Blob): Promise<string> {
return new Promise((resolve, reject) => {
if (!(buf instanceof Blob)) {
return reject('bufferToImgSrc - expected buf to be of type: Blob')
}
const reader = new FileReader()
reader.onload = () => resolve(reader.result)
reader.onerror = reject
reader.readAsDataURL(buf)
})
}
export async function bufferToImageData(buf: Blob): Promise<ImageData> {
if (!(buf instanceof Blob)) {
throw new Error('bufferToImageData - expected buf to be of type: Blob')
}
return mediaSrcToImageData(await bufferToImgSrc(buf))
}
export function bufferToImage(buf: Blob): Promise<HTMLImageElement> { export function bufferToImage(buf: Blob): Promise<HTMLImageElement> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!(buf instanceof Blob)) { if (!(buf instanceof Blob)) {
...@@ -127,11 +49,6 @@ export function bufferToImage(buf: Blob): Promise<HTMLImageElement> { ...@@ -127,11 +49,6 @@ export function bufferToImage(buf: Blob): Promise<HTMLImageElement> {
}) })
} }
export type DrawBoxOptions = {
lineWidth: number
color: string
}
export function drawBox( export function drawBox(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
x: number, x: number,
...@@ -145,12 +62,6 @@ export function drawBox( ...@@ -145,12 +62,6 @@ export function drawBox(
ctx.strokeRect(x, y, w, h) ctx.strokeRect(x, y, w, h)
} }
export type DrawTextOptions = {
fontSize: number
fontStyle: string
color: string
}
export function drawText( export function drawText(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
x: number, x: number,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment