Skip to content

Commit

Permalink
refactor: remove unused $player reference and add segmenter initializ…
Browse files Browse the repository at this point in the history
…ation log
  • Loading branch information
zhw2590582 committed Oct 8, 2024
1 parent ffe4dd0 commit b8c29f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
17 changes: 3 additions & 14 deletions docs/uncompiled/artplayer-plugin-danmuku-mask/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var _tfjsBackendCpu = require("@tensorflow/tfjs-backend-cpu");
var _bodySegmentation = require("@tensorflow-models/body-segmentation");
function artplayerPluginDanmukuMask(option = {}) {
return (art)=>{
const { template: { $player, $video, $danmuku } } = art;
const { template: { $video, $danmuku } } = art;
let segmenter = null;
let canvas = null;
let ctx = null;
Expand All @@ -173,8 +173,7 @@ function artplayerPluginDanmukuMask(option = {}) {
async function initTensorFlow() {
try {
await _tfjsCore.setBackend("webgl");
console.log("Using WebGL backend");
} catch (e) {
} catch (error) {
console.warn("WebGL backend not available, falling back to CPU");
await _tfjsCore.setBackend("cpu");
}
Expand All @@ -194,8 +193,8 @@ function artplayerPluginDanmukuMask(option = {}) {
};
try {
segmenter = await _bodySegmentation.createSegmenter(model, segmenterConfig);
console.log("Segmenter initialized:", segmenter);
isInitialized = true;
console.log("Segmenter initialized successfully");
} catch (error) {
console.error("Error initializing segmenter:", error);
isInitialized = false;
Expand All @@ -213,16 +212,6 @@ function artplayerPluginDanmukuMask(option = {}) {
function createCanvas() {
canvas = document.createElement("canvas");
ctx = canvas.getContext("2d");
Object.assign(canvas.style, {
position: "absolute",
top: "0",
left: "0",
width: "100%",
height: "100%",
pointerEvents: "none",
opacity: "0"
});
$player.appendChild(canvas);
}
function makeWhiteTransparent(imageData) {
const data = imageData.data;
Expand Down
2 changes: 1 addition & 1 deletion docs/uncompiled/artplayer-plugin-danmuku-mask/index.js.map

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions packages/artplayer-plugin-danmuku-mask/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as bodySegmentation from '@tensorflow-models/body-segmentation';
export default function artplayerPluginDanmukuMask(option = {}) {
return (art) => {
const {
template: { $player, $video, $danmuku },
template: { $video, $danmuku },
} = art;

let segmenter = null;
Expand Down Expand Up @@ -54,6 +54,7 @@ export default function artplayerPluginDanmukuMask(option = {}) {

try {
segmenter = await bodySegmentation.createSegmenter(model, segmenterConfig);
console.log('Segmenter initialized:', segmenter);
isInitialized = true;
} catch (error) {
console.error('Error initializing segmenter:', error);
Expand All @@ -74,16 +75,6 @@ export default function artplayerPluginDanmukuMask(option = {}) {
function createCanvas() {
canvas = document.createElement('canvas');
ctx = canvas.getContext('2d');
Object.assign(canvas.style, {
position: 'absolute',
top: '0',
left: '0',
width: '100%',
height: '100%',
pointerEvents: 'none',
opacity: '0',
});
$player.appendChild(canvas);
}

function makeWhiteTransparent(imageData) {
Expand Down

0 comments on commit b8c29f2

Please sign in to comment.