我需要的
我需要扫描并检查图像是否为裸体。
我使用nude.js进行图像检测问题我在加载页面时包含nude.js后面临的错误出现在控制台中。
裸体.js
(function(){
var nude = (function(){
// private var definition
var canvas = null,
ctx = null,
resultFn = null,
// private functions
initCanvas = function(){
canvas = document.createElement("canvas");
// the canvas should not be visible
canvas.style.display = "none";
var b = document.getElementsByTagName("body")[0];
b.appendChild(canvas);
ctx = canvas.getContext("2d");
},
loadImageById = function(id){
// get the image
var img = document.getElementById(id);
// apply the width and height to the canvas element
canvas.width = img.width;
canvas.height = img.height;
// reset the result function
resultFn = null;
// draw the image into the canvas element
ctx.drawImage(img, 0, 0);
},
scanImage = function(){
// get the image data
var image = ctx.getImageData(0, 0, canvas.width, canvas.height),
imageData = image.data;
var myWorker = new Worker('worker.nude.js'),
message = [imageData, canvas.width, canvas.height];
myWorker.postMessage(message);
myWorker.onmessage = function(event){
resultHandler(event.data);
}
},
abc.html
<script>
$(document).ready(function(){
$("img").load(function(){
nude.load('testImage');
nude.scan(function(result)
{
if(!result) alert("no nude");
else
alert("nude)"); });
});
});
错误
Uncaught TypeError: Cannot read property 'width' of null
canvas.width = img.width; // line 28