-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Call .create() during copyTo for an empty matrix. #21059
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
base: 3.4
Are you sure you want to change the base?
Conversation
This ensures that the type is copied. The doc also mentions that .create is called: https://docs.opencv.org/4.5.4/d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77
Currently, there is no proper support for handling of empty matrices or distinguish them from just declared AFAIK, meta information should not be used if Mat is See also: #7710 |
I understand we cannot differentiate with a proper empty matrix created by cv::Mat m (which has a default type of CV_8UC1). opencv/modules/core/src/matrix.cpp Line 1026 in b19697e
My patch is actually to solve: cv::Mat(0,0,CV_16SC3).clone() returns cv::Mat(0,0,CV_8UC1) (and not an empty matrix of the right type CV_16SC3). So please advise on how we should fix the following (maybe by just updating the doc in the right places):
I still think my patch would bring some consistency but I would also need to have release() keep the type (which I can add). |
Main point here that "Mat" is a kind of smart pointer over some buffer.
Currently it is a gray zone which is not documented. |
I agree with There is actually a way to differentiate between cv::Mat() and cv::Mat(0,0,CV_8U) though their type is 0 for both: elemSize() is 0 in the first case, 1 in the other case. |
Probably, we should use the check, proposed by @vrabaud (e.g. |
where is code crashing?
Even |
And
Maybe we need a |
Right, it has dedicated handling for empty Mat: opencv/modules/core/include/opencv2/core/mat.inl.hpp Lines 667 to 672 in 4223495
I messed that with CV_ELEM_SIZE(flags). Also please note However original expression form |
Hi, what do I do with that PR ? Port it to 4.x or give up until 5.x which has better handling of 0d ? |
This ensures that the type is copied.
The doc also mentions that .create is called:
https://docs.opencv.org/4.5.4/d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request