python - 类型错误 : src is not a numpy array

标签 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])

最佳答案

你应该这样做:

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

关于python - 类型错误 : src is not a numpy array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24573818/

相关文章:

python - 如何理解 scipy.linalg.lu_factor 的主元矩阵?

python - 添加在 TensorFlow 中检测到的对象

opencv - 下载打开的简历时 cmake 出错

python - 无需缝合图像的OpenCV曝光补偿

python - 在python中的3D numpy数组中绘制三角形

python - 不同长度的 2D 绘图 xy 列表

python - 为什么删除 else 会导致递归函数重复结果?

python - 什么用户应该拥有我的 Python 脚本和应用程序目录?

python - 使用 python 调试器 (pdb) 时调试 cython 代码 (.pyx) - 最佳实践

python - 如何在Flask中异步调用函数?