[英]opencv - TypeError: Cannot read property 'length' of undefined
I recently installed opencv
and executed npm install
. 我最近安装了
opencv
并执行了npm install
。
After doing that, I was given some sample code to see if it works, but it does not work, and I don't know why. 完成此操作后,我得到了一些示例代码来查看它是否有效,但它不起作用,我也不知道为什么。 Maybe I installed it incorrectly, I am a newbie to this.
也许我安装不正确,这是我的新手。 Here is the code:
这是代码:
cv.readImage("./examples/files/mona.png", function(err, im){
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
for (var i=0;i<faces.length; i++){
var x = faces[i]
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
}
im.save('./out.jpg');
});
})
You should install it by "npm install opencv --save" But since there is no dependency issue so you installed it right. 您应该通过“ npm install opencv --save”安装它,但是由于没有依赖性问题,因此您安装正确。 Try doing console.log(faces) because it is giving null as result in faces that's why length is undefined.
尝试执行console.log(faces),因为它会在faces中给出null作为结果,这就是未定义长度的原因。 Also make sure the image at that path you are giving "./examples/files/mona.png" do exist.
还要确保您提供的路径“ ./examples/files/mona.png”中的图像确实存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.