【发布时间】:2019-09-25 07:48:01
【问题描述】:
当尝试在某些图像上使用 EAST text detector,在 Windows 10 上使用 Python 中的 OpenCV 时,我收到以下错误:
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'
(奇怪的是,我的文件系统上不存在该路径)
我从Adrian Rosebrock 的优秀tutorial 开始。这是一个代码 sn-p(它在最后一行失败):
# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32
# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
# calculate how much padding is necessary
iBottom = iRequiredUnit - iHr
# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
# calculate how much padding is necessary
iRight = iRequiredUnit - iWr
if iBottom > 0 or iRight > 0:
# add padding to make the image proportions correct
oImage = cv.copyMakeBorder(
src=oInputImage,
top=iTop,
bottom=iBottom,
left=iLeft,
right=iRight,
borderType=cv.BORDER_CONSTANT,
value=[0, 0, 0]
)
else:
# no need to add padding
oImage = oInputImage.copy()
(iH, iW) = oImage.shape[:2])
ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
oImage, 1.0, (iW, iH), (ib, ig, ir),
swapRB=True, crop=False
)
# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(EAST_path)
oNet.setInput(oBlob)
asLayerNames = [
"feature_fusion/Conv_7/Sigmoid",
"feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)
我做了一些修改,例如我重新计算平均值,而不是使用示例中显示的硬编码值。我还尝试不带平均值(或使用示例中的默认值)和swapRB=False 调用blobFromImage,但错误不断发生。
问题在某些文件 (here's an example) 中系统性地发生,而在其他文件中则没有,而 EAST 在这些文件上运行平稳。我无法确定导致图像麻烦的特征,但我倾向于认为错误与调整图像大小的需要无关,因为大多数可以毫无问题地分析的图像无论如何都必须调整大小。
我没有找到任何特定于该问题的文档,并且无法从源头(我猜是this)轻松地重建问题。
如何防止错误发生?
【问题讨论】: