程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

'numpy.ndarray' 对象没有属性 'detectMultiScale' 属性错误

发布于2023-02-03 21:17     阅读(607)     评论(0)     点赞(5)     收藏(4)


在这里更新成face to img后发现报错。错误说:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
0 549 374
1 518 362
2 487 351
3 462 353
4 449 359
5 469 318
6 428 348
7 438 367
8 453 371
9 473 321
10 434 363
11 447 382
12 463 387
13 479 334
14 443 377
15 456 396
16 471 402
17 487 352
18 457 385
19 458 402
20 463 413
Traceback (most recent call last):
  File "/home/maruf/Documents/python/opencv/YouTube/Hand Tracking/basic.py", line 35, in <module>
    faceDetails = img.detectMultiScale(
AttributeError: 'numpy.ndarray' object has no attribute 'detectMultiScale'

Process finished with exit code 1

这是我这部分的源代码:

col = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faceDetails = img.detectMultiScale(
        col,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

for (x, y, w, h) in faceDetails:
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

为什么它说那个错误... 'numpy.ndarray' 对象没有属性 'detectMultiScale'


解决方案


您的错误原因:
detectMultiScale确实不是的方法numpy.ndarray,这显然是您img对象的类型。

解决方法:
detectMultiScale其实是opencvCascadeClassifier类的一个方法。
请参阅此处的文档:detectMultiScale
img应该作为第一个参数传递给detectMultiScale(还有其他可选参数,您可以在文档链接中看到)。

请注意,为了获得CascadeClassifier对象,您必须从模型文件中加载分类器数据。上面的链接提供了一个 C++ 示例。我相信快速搜索会给您一个 python 示例。



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/1895303/056feb526f4964cba438/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)