cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-71670poj\opencv\modules\dnn\src\dnn.cpp:371: error: (-215:Assertion failed) image.depth() == blob_.depth() in function 'cv::dnn::dnn4_v20200609::blobFromImages'
当我运行以下代码时会出现这个错误:
crop = frame[y:y + h, x:x + w]
img_blob = cv.dnn.blobFromImage(crop)
回答:
我已经找到了解决方案,伙伴们!
crop = frame[y:y + h, x:x + w] #裁剪原始图像,只使用所需坐标
if (crop.shape) > (300, 300):
crop = cv.resize(crop, (300, 300)) #仅当裁剪图像大于所需尺寸时进行调整大小
img_blob = cv.dnn.blobFromImage(crop) #由于我使用的是res10_300x300_ssd_iter_140000模型,这个模型需要300*300的图像