The Wayback Machine - https://web.archive.org/web/20220425094704/https://github.com/opencv/opencv/issues/20167
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
blazejdolicki opened this issue May 27, 2021 · 10 comments · Fixed by #21067
Closed
4 tasks done

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

blazejdolicki opened this issue May 27, 2021 · 10 comments · Fixed by #21067
Milestone

Comments

@blazejdolicki
Copy link

@blazejdolicki blazejdolicki commented May 27, 2021

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
@akshitadixit
Copy link

@akshitadixit akshitadixit commented Jun 2, 2021

Hello may I try and work on this?

@AkshatJindal1
Copy link

@AkshatJindal1 AkshatJindal1 commented Jun 19, 2021

I would like to work on this

@AjayNandoriya
Copy link

@AjayNandoriya AjayNandoriya commented Jun 21, 2021

Invalid image path should be handled with (before or after) imread() as imread() will return None in case of any error.
seamlessClone() is not aware of image path as it accepts image variables as input. The error being reported shows image size is smaller or Roi is bigger/ out of image.
The error can be handled by checking input image sizes and required roi before seamlessClone().

@ddiaaz ddiaaz mentioned this issue Jul 3, 2021
6 tasks
@ShadyD45
Copy link
Contributor

@ShadyD45 ShadyD45 commented Jul 23, 2021

Invalid image path should be handled with (before or after) imread() as imread() will return None in case of any error.
seamlessClone() is not aware of image path as it accepts image variables as input. The error being reported shows image size is smaller or Roi is bigger/ out of image.
The error can be handled by checking input image sizes and required roi before seamlessClone().

Yes. I don't think imread() neither seamlessClone() should display any error regarding wrong path. They both do their job.
Shouldn't it be programmers responsibility to check if imread() has been executed successfully by checking if image variable is None or not before using them for other function calls (in above case seamlessClone() ).

snehal2403 added a commit to snehal2403/opencv that referenced this issue Aug 27, 2021
…essClone() opencv#20167

This code will solve the problem. It will show the error if the file path supplied to seamlessclone() is invalid.
@Indu2204
Copy link

@Indu2204 Indu2204 commented Aug 30, 2021

I would like to work on this issue

@anavartpandya
Copy link

@anavartpandya anavartpandya commented Sep 16, 2021

Invalid image path should be handled with (before or after) imread() as imread() will return None in case of any error.
seamlessClone() is not aware of image path as it accepts image variables as input. The error being reported shows image size is smaller or Roi is bigger/ out of image.
The error can be handled by checking input image sizes and required roi before seamlessClone().

Yes. I don't think imread() neither seamlessClone() should display any error regarding wrong path. They both do their job.
Shouldn't it be programmers responsibility to check if imread() has been executed successfully by checking if image variable is None or not before using them for other function calls (in above case seamlessClone() ).

It is very true but wouldn't it be more beneficial to a programmer if the seamlessClone() shows an error stating that the input image has a none value rather than showing the error that is shown above? This change may easily alert the programmer that the image path is wrong or invalid.

@anavartpandya
Copy link

@anavartpandya anavartpandya commented Sep 16, 2021

I would like to work upon this issue and do the above mentioned changes.

@TopDogIRE
Copy link

@TopDogIRE TopDogIRE commented Sep 22, 2021

I'd like to work on this issue.

@amankumar-ds
Copy link

@amankumar-ds amankumar-ds commented Oct 25, 2021

I'd like to work on this issue

@Shaiks55
Copy link

@Shaiks55 Shaiks55 commented Nov 8, 2021

HI
I have 5 year Experience in this task CVAT
i would like to work with you.
Thanks..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.