gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:50 24 4
gpt4 key购买 nike

显示错误

追溯(最近的调用最后):

  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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com