如何解决裁剪图像的cv2.dnn.blobFromImage(帧)错误



cv2.error: OpenCV(4.4.0) C:UsersappveyorAppDataLocalTemp1pip-req-build-71670pojopencvmodulesdnnsrcdnn.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] #Cropping the original image to use only desired coordinates
if (crop.shape) > (300, 300):
crop = cv.resize(crop, (300, 300)) #resize only if the crop is larger than required size
img_blob = cv.dnn.blobFromImage(crop) #This model requires 300*300 images since I'm using it with res10_300x300_ssd_iter_140000

最新更新