Skip to content

Commit 258f604

Browse files
authored
adds fix for unet image return for p5 (#625)
1 parent b078bd6 commit 258f604

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/UNET/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as tf from '@tensorflow/tfjs';
1111
import callCallback from '../utils/callcallback';
1212
import { array3DToImage } from '../utils/imageUtilities';
1313
import Video from '../utils/Video';
14+
import p5Utils from '../utils/p5Utils';
1415

1516
const URL = 'https://raw.githubusercontent.com/zaidalyafeai/HostedModels/master/unet-128/model.json';
1617
const imageSize = 128;
@@ -40,10 +41,10 @@ class UNET extends Video {
4041
}
4142

4243
// check if p5js
43-
static checkP5() {
44-
if (typeof window !== 'undefined' && window.p5 && window.p5.Image && typeof window.p5.Image === 'function') return true;
45-
return false;
46-
}
44+
// static checkP5() {
45+
// if (typeof window !== 'undefined' && window.p5 && window.p5.Image && typeof window.p5.Image === 'function') return true;
46+
// return false;
47+
// }
4748

4849
async segment(inputOrCallback, cb) {
4950
await this.ready;
@@ -108,8 +109,10 @@ class UNET extends Video {
108109
const raw = await tf.browser.toPixels(tensor);
109110
let image;
110111

111-
if (UNET.checkP5()) {
112-
image = window.loadImage(dom.src);
112+
if (p5Utils.checkP5()) {
113+
const blob1 = await p5Utils.rawToBlob(raw, imageSize, imageSize);
114+
const p5Image1 = await p5Utils.blobToP5Image(blob1);
115+
image = p5Image1;
113116
}
114117

115118
return {

0 commit comments

Comments
 (0)