【问题标题】:TypeError: src is not a numpy arrayTypeError: src 不是一个 numpy 数组
【发布时间】:2014-07-04 11:59:04
【问题描述】:

错误显示

Traceback(最近一次调用最后一次):

  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)))
  • @user3804674 你检查下面的答案了吗?

标签: python opencv numpy


【解决方案1】:

你应该这样做:

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

【讨论】:

    猜你喜欢
    • 2018-02-02
    • 1970-01-01
    • 2018-03-12
    • 2014-05-30
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多