Raspbian 上的 Python - "TypeError: ' numpy.int3 2' object is not iterable'“

标签 python opencv numpy raspberry-pi raspbian

以下代码在我的桌面 (Mint 17) 上运行时没有任何问题,但是当我尝试在运行 Raspbian 的 RPi 上运行它时,我在第 58 行收到上述错误消息。我认为这是造成它的唯一原因是Python版本:

Mint 使用 Python 2.7.6

$ python -V
    Python 2.7.6

RPi 使用 2.7.3,但我安装了 2.7.8 并为其取了别名

$ python -V
    Python 2.7.3
$ alias python=/usr/local/bin/python2.7
$ python -V
    Python 2.7.8

我知道这里有类似的问题,但在这些情况下问题似乎与代码相关。我知道这段代码没问题,所以一定是环境问题吧?

无论如何,这是程序:

#!/usr/bin/env python

# Determines if a set of three images contains at least one person
# Images are taken in quick succession, the 2nd and 3rd are diff images of the first
# Adapted from sample file: /opencv/samples/python2/peopledetect.py
#
# Example:  ./pdTriple.py IMG_000.JPG IMG_001.JPG IMG_002.JPG 


import numpy as np
import cv2
import sys
from glob import glob
import itertools as it
from array import *

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

def draw_detections(img, rects, thickness = 1):
    for x, y, w, h in rects:
        # the HOG detector returns slightly larger rectangles than the real objects.
        # so we slightly shrink the rectangles to get a nicer output.
        pad_w, pad_h = int(0.15*w), int(0.05*h)
        cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)

if __name__ == '__main__':

    hog = cv2.HOGDescriptor()
    hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )

    count = 0
    results = np.array([0,0,0])

    for fn in it.chain(*map(glob, sys.argv[1:])):
        print fn, ' - ',

        try:
            img = cv2.imread(fn)
            if img is None:
                print 'Failed to load image file:', fn
                continue
        except:
            print 'loading error'
            continue

        # modify winstride and padding values to optimise results
        found, w = hog.detectMultiScale(img, winStride=(4,4), padding=(8,8), scale=1.05)

        found_filtered = []
        for ri, r in enumerate(found):
            for qi, q in enumerate(found):
                if ri != qi and inside(r, q):uname # errors here
                    break
            else:
                found_filtered.append(r)

        print '%d found (%d filtered)' % (len(found_filtered), len(found))
        results[count] = len(found_filtered)
        count += 1

if np.all(results>0):
    print '\n--------------', fn, 'contains a person --------------\n'

最佳答案

如果你删除'uname',它会起作用;

for ri, r in enumerate(found):
        for qi, q in enumerate(found):
            if ri != qi and inside(r, q): # errors here
                break
        else:
            found_filtered.append(r)

关于Raspbian 上的 Python - "TypeError: ' numpy.int3 2' object is not iterable'“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25180567/

相关文章:

python - 多次更新python numpy数组列

python - 如何创建关键点来计算 SIFT?

python - "ValueError: Unrecognized marker style -d"在标记上循环时

python-3.x - openvino 在树莓派 4 中运行推理几秒钟后崩溃

python - 将列表转换为np数组

python - 使用 numpy 在第一个矩阵列中搜索数组并获取下一列值

python - 如何根据字符数和分隔符将字符串拆分为 block ?

python - 如何使用列表中的值作为 pydantic 验证器?

algorithm - 检测物体之间距离的最快方法?

Python "TypeError: unhashable type: ' slice'"用于编码分类数据