【问题标题】:How can I solve ` cv2.dnn.blobFromImage (frame) error for cropped images`?如何解决裁剪图像的 cv2.dnn.blobFromImage (frame) 错误?
【发布时间】:2020-12-04 00:26:02
【问题描述】:

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)

【问题讨论】:

  • numpy 索引是frame[y:y+h, x:x+w],除非你做了一些很奇怪的事情
  • 其实听上去顺序倒了
  • 您可能还需要在图像导入的某处使用dtype='uint8' ddepth=np.uint8.astype(np.uint8)。从这里看不出来,粘贴的代码不够看。
  • 是的,numpy 反转 [col, row]。在这里阅读 cmets -- stackoverflow.com/a/15589825/3342050
  • 谢谢。我裁剪了 muy 图像,因为我只需要那个特定区域。使用dtype='uint8' ddepth=np.uint8 or .astype(np.uint8) 是什么意思?

标签: python opencv machine-learning computer-vision


【解决方案1】:

伙计们,我刚刚找到了解决方案!

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 2012-11-16
    相关资源
    最近更新 更多