日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective‘

作者:修煉之路 更新時間: 2022-02-13 編程語言

錯誤緣由

在使用opencv做透視變換的時候報error: (-215:Assertion failed) _src.total() > 0 in function 'warpPerspective',錯誤的詳細信息如下

cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-dglzv4yn/opencv/modules/imgproc/src/imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective’

透視變化的代碼如下:

def clip_image(img,points):
    if isinstance(points,list):
        points = np.array(points,dtype=np.float32)
    img_crop_width = max(np.linalg.norm(points[0] - points[1]),
                         np.linalg.norm(points[2] - points[3]))
    img_crop_height = max(np.linalg.norm(points[1] - points[2]),
                          np.linalg.norm(points[0] - points[3]))
    pts_std = np.float32([[0,0],[img_crop_width,0],[img_crop_width,img_crop_height],[0,img_crop_height]])
    M = cv2.getPerspectiveTransform(points,pts_std)
    dst_img = cv2.warpPerspective(img, M, (img_crop_width, img_crop_height), borderMode=cv2.BORDER_REPLICATE,
                                  flags=cv2.INTER_CUBIC)
    dst_img_height, dst_img_width = dst_img.shape[0:2]
    if dst_img_height * 1.0 / dst_img_width >= 1.5:
        dst_img = np.rot90(dst_img)
    return dst_img

錯誤原因分析

出現這種錯誤的原因可能有三種:

  • 檢查img是否為None
  • 檢查points坐標中是否出現負數
  • 檢查pointspts_std點的順序是否一致

原文鏈接:https://xiulian.blog.csdn.net/article/details/121666964

欄目分類
最近更新