TypeError:src不是一个numpy数组

时间:2014-07-04 11:59:04

标签: python opencv numpy

显示错误

追踪(最近一次呼叫最后一次):

  File "C:\Python27\sample\sample1.py", line 47, in <module>
   morphOps([threshold])
  File "C:\Python27\sample\sample1.py", line 20, in morphOps
   cv2.erode(thresh,thresh,erodeElement);
TypeError: src is not a numpy array

代码

import cv2 

import numpy as np

H_MIN = 0;
H_MAX = 256; 
S_MIN = 0;
S_MAX = 256;  
V_MIN = 0;  
V_MAX = 256;

def morphOps(thresh):     
    #create structuring element that will be used to "dilate" and "erode" image.
    #the element chosen here is a 3px by 3px rectangle

    erodeElement = cv2.getStructuringElement( cv2.MORPH_RECT, (3,3));
    #dilate with larger element so make sure object is nicely visible
    dilateElement = cv2.getStructuringElement( cv2.MORPH_RECT,(8,8));

    cv2.erode(thresh,thresh,erodeElement);
    cv2.erode(thresh,thresh,erodeElement);

    cv2.dilate(thresh,thresh,dilateElement);
    cv2.dilate(thresh,thresh,dilateElement);

videoCapture = cv2.VideoCapture('E:/Intern MNIT(gait motions)/Sample video.mp4')
fps = videoCapture.get(cv2.cv.CV_CAP_PROP_FPS)
print 'Frame per seconds :'; print fps
while 1 :
     _,cameraFeed = videoCapture.read()    
     HSV = cv2.cvtColor(cameraFeed,cv2.COLOR_BGR2HSV);  

     # define range of color in HSV 
     lower = np.array([0,0,0])
     upper = np.array([256,256,256])

     #thresholding image
     threshold = cv2.inRange(HSV,lower,upper)

     morphOps([threshold])

1 个答案:

答案 0 :(得分:0)

你应该这样做:

morphOps(np.array(list(threshold)))