鍍金池/ 問(wèn)答/人工智能  PHP  Python  HTML/ ndarray和ops如何在瀏覽器中引入并處理圖片data

ndarray和ops如何在瀏覽器中引入并處理圖片data

function preprocess(imageData) {
        const {
            width,
            height,
            data
    } = imageData;
        const dataTensor = ndarray(new Float32Array(data), [width, height, 4])
        
        const dataProcessedTensor = ndarray(new Float32Array(width * height * 3), [width, height, 3])
        //從[0,255]轉(zhuǎn)化到[0,1]
        ops.divseq(dataTensor, 255)
        //獲取R數(shù)據(jù)
        ops.assign(dataProcessedTensor.pick(null, null, 0), dataTensor.pick(null, null, 0))
        //獲取G數(shù)據(jù)
        ops.assign(dataProcessedTensor.pick(null, null, 1), dataTensor.pick(null, null, 1))
        //獲取B數(shù)據(jù)
        ops.assign(dataProcessedTensor.pick(null, null, 2), dataTensor.pick(null, null, 2))
        const preprocessedData = dataProcessedTensor.data;
        console.log('via process');
        return preprocessedData;
    }   

找不到 ndarray 和 ops 請(qǐng)問(wèn)我該如何引用 ?謝謝 謝謝

回答
編輯回答
淡墨

scijs/ndarray,用npm安裝,然后通過(guò)browserify在瀏覽器使用。

2017年12月29日 17:41