OpenCV:错误:(-215:断言失败)_crc :: warpPerspective中的_src.total()> 0

时间:2019-04-22 12:38:05

标签: python python-3.x opencv cv2

我的图像路径内部带有中文字符,我尝试在Python3中使用cv2解码路径:

def main(src):
    global img, img2, ROI, src_path, dst_path
    src_path = src
    main_path = os.path.dirname(src)
    dst_path = main_path + '/output.jpg'
    stream = open(src_path, "rb")
    bytes = bytearray(stream.read())
    numpyarray = np.asarray(bytes, dtype = np.uint8)
    img = cv2.imdecode(numpyarray, cv2.IMREAD_UNCHANGED)
    print(img)

图像已正确读取,我具有以下输出:

[[[58 63 64]
  [52 57 58]
  [56 61 62]
  ...
  [65 55 71]
  [63 53 69]
  [64 54 70]]

 [[54 59 60]
  [48 53 54]
  [49 54 55]
  ...
  [65 55 71]
  [68 58 74]
  [68 58 74]]

 [[55 60 61]
  [62 67 68]
  [53 58 59]
  ...
  [71 61 77]
  [76 66 82]
  [73 63 79]]

 ...

 [[38 46 45]
  [38 46 45]
  [42 48 47]
  ...
  [55 58 62]
  [57 60 64]
  [51 54 58]]

 [[32 40 39]
  [30 38 37]
  [35 43 42]
  ...
  [50 54 55]
  [58 62 63]
  [54 58 59]]

 [[28 36 35]
  [26 34 33]
  [38 46 45]
  ...
  [26 30 31]
  [51 55 56]
  [75 79 80]]]

但是我得到Traceback的同时将选择的点坐标转移到dst,以便使perspective transform为通过鼠标单击选择的感兴趣区域。

Traceback (most recent call last):

  File "D:\roi_pt_ocr\roi_perspective_transform.py", line 77, in on_mouse
    perspective_transform(tpPointsChoose, src_path, dst_path)

  File "D:\roi_pt_ocr\roi_perspective_transform.py", line 109, in perspective_transform
    dst = cv2.warpPerspective(img, M, (x_length, y_length))

error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:2903: error: (-215:Assertion failed) _src.total() > 0 in function 'cv::warpPerspective'

有人可以帮助我弄清楚为什么正确读取图像时会发生此错误吗?谢谢。

0 个答案:

没有答案