Skip to content

Friendlier error messages when image path does not exist in cv2.seamlessClone() #20167

@blazejdolicki

Description

@blazejdolicki
System information (version)
  • OpenCV => 4.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio Code 1.56.2
Detailed description

When running cv2.seamlessClone() the error is a bit misleading when the incorrect image path is supplied. It doesn't make it obvious that the problem is in the path

Steps to reproduce
import cv2
# Read images
DATA_PATH = "data_set/data"
source = cv2.imread(f"{DATA_PATH}/this image doesn't exist.png")
target = cv2.imread(f"{DATA_PATH}/10226_bg_27794.png")
swap = cv2.imread(f"{DATA_PATH}/10226_sw_27794_19200.png")
mask = cv2.imread(f"{DATA_PATH}/10226_mask_27794_19200.png")
# mask = mask/255
center = (112, 112)
output_normal = cv2.seamlessClone(swap, target, mask, center, cv2.NORMAL_CLONE)
output_mixed = cv2.seamlessClone(swap, target, mask, center, cv2.MIXED_CLONE)

# Output
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-3-faf121550370> in <module>
     10 # mask = mask/255
     11 center = (112, 112)
---> 12 output_normal = cv2.seamlessClone(swap, target, mask, center, cv2.NORMAL_CLONE)
     13 output_mixed = cv2.seamlessClone(swap, target, mask, center, cv2.MIXED_CLONE)

error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-kh7iq4w7\opencv\modules\core\src\matrix.cpp:811: error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'cv::Mat::Mat'
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions