AttributeError的:' numpy.ndarray'对象没有属性' read'

时间:2016-03-31 04:32:27

标签: python opencv

我已经在python中编写了一个程序,首先对视频进行平均,然后执行背景减法以检测视频中的无人参与对象。但是它显示了一些错误。有没有人帮我通过纠正我的程序来解决这个问题.i在这里发布我的程序。或者任何人有任何其他代码来做同样的问题,请发给我代码。我的邮件ID是vishnuke143@gmail.com.thank你。<​​/ p>

程序: -

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
_,f=cap.read()
avg=np.float32(f)

count=1
while 1:
        _,f=cap.read()
        cv2.accumulateWeighted(f,avg,0.01)
        res=cv2.convertScaleAbs(avg)
        cv2.imshow('img',f)
        cv2.imshow('avg',res)
        cv2.waitKey(0)
        _, frame =res.read()

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        pix = np.array(gray);

        #cv2.imshow('gray',gray)
        #cv2.waitKey(0)
        #cv2.destroyAllWindows()
        if count==1:
            bckgnd=gray
            count=0

        change=abs(np.double(gray)-np.double(bckgnd))
        ch=abs(gray-bckgnd)
        pix = np.array(change)
        maxval=np.amax(pix)
        #print maxval
        #cv2.imshow('gray',ch)
        #cv2.waitKey(0)
        #cv2.destroyAllWindows()
        if maxval>100:
            thresh=maxval/2
        else:
            thresh=255
        ret,thresh4 = cv2.threshold(ch,thresh,255,cv2.THRESH_BINARY)    

        cv2.imshow('gray',thresh4)

        output = cv2.connectedComponentsWithStats(thresh4, 4, cv2.CV_32S)
        num_labels=output[0]
        labels=output[1]
        stats=output[2]
        centroids=output[3]
        print num_labels
        k = cv2.waitKey(30) & 0xff
        if k == 27:
            break   

0 个答案:

没有答案