首页 > 解决方案 > 类型错误:预期的 Ptr对于参数'src'?

问题描述

每当我使用 cv2.dilate 来扩大图像时,我得到 TypeError: Expected Ptr<cv::UMat> for argument 'src' 错误,我作为输入提供的图像。

frameDelta = cv2.absdiff(firstFrame, gray)
cv2.imshow("frameDelta",frameDelta)
thresh = cv2.threshold(frameDelta, 25,255,cv2.THRESH_BINARY)
thresh = cv2.dilate(thresh, None, iterations = 2)   

我已经尝试过 cv2.UMat(thresh),当我使用它时,我得到 TypeError: Required argument 'ranges' (pos 2) not found

标签: pythonopencv

解决方案


cv2.threshold 确实产生两个返回值。你分配它的方式,“thresh”将是一个元组,第一个条目是整数类型,第二个条目是阈值图像。采用

frameDelta = cv2.absdiff(firstFrame, gray)
cv2.imshow("frameDelta",frameDelta)
thresh = cv2.threshold(frameDelta, 25,255,cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations = 2)

反而。


推荐阅读