Python on Raspbian - " TypeError: ' numpyint32 ' object is not iterable'

时间:2021-05-12 20:23:22

The following code runs on my desktop (Mint 17) with no issues, but when I try to run it on a RPi running Raspbian I get the above mentioned error message at line 58. The only thing I can think that's causing it is the Python version:

下面的代码在我的桌面上运行(Mint 17),没有任何问题,但是当我尝试在运行Raspbian的RPi上运行它时,我得到了上面提到的第58行错误消息。我能想到的唯一原因是Python版本:

Mint uses Python 2.7.6

薄荷使用Python 2.7.6

$ python -V
    Python 2.7.6

The RPi uses 2.7.3, but I've installed 2.7.8 and aliased it

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

I know there's similar questions on here, but the issue seems to be code related in those cases. I know this code's OK, so it must be an environment issue, right?

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

Here's the program anyway:

这是程序无论如何:

#!/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'

1 个解决方案

#1


0  

if you delete 'uname', it'll work;

如果你删除了“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)

#1


0  

if you delete 'uname', it'll work;

如果你删除了“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)