convertPointsFromHomogeneous returning wrong values (Bug #1316)
Description
I am trying to create a 4D vector and pass it to
ConvertPointsHomogeneous to obtain a 3D vector (by dividing all
components by the last component).
If I create a vector like this:
cv::Mat V(4,1,cv::DataType<float>::type);
shouldn't V.checkVector(4) return 4? (it seems to return -1)
If I create the row vector instead:
cv::Mat V(4,1,cv::DataType<float>::type);
V.checkVector(4) returns 1 (I'm still expecting 4?)
With the column vector, convertPointsFromHomogeneous throws an error
on this line:
CV_Assert( npoints >= 0 && (src.depth() CV_32F || src.depth() CV_32S));
because npoints is < 0.
With the row vector, this conditional fails:
if( !((src->rows > 1) ^ (CV_MAT_CN(src->type) > 1)) )
CV_Error( CV_StsBadSize, "Either the number of channels or
columns or rows must be =1" );
Can anyone verify and/or explain this behavior?
Some compilable code is here: http://programmingexamples.net/index.php?title=OpenCV/WishList/ConvertPointsHomogeneous
Thanks,
David
[email protected]
Associated revisions
Merge pull request #1316 from asmorkalov:winrt_c4447_fix
History
Updated by Vadim Pisarevsky over 13 years ago
First of all, converting a single vector using convertFromHomogeneous() can be much slower than doing it by hand. But if you want to do it, use multi-channel mat.
#include "opencv2/calib3d/calib3d.hpp"
#include <stdio.h>
int main(int, char**)
{
float v[] = { 1, 2, 3, 4 }, wr3;
cv::Mat V(1, 1, CV_32FC4, v);
cv::Mat W(1, 1, CV_32FC3, w);
cv::convertPointsFromHomogeneous(V, W);
printf("%f %f %f\n", wr0, wr1, wr2);
return 0;
}
- Status changed from Open to Done
- (deleted custom field) set to worksforme
Updated by David Doria over 13 years ago
That does indeed work. However, the documentation does not say that it only works with multi-channel matrices (why is that??)
Shouldn't the code I showed initially work as well? Either we should show an example of using the type of vectors I showed, or add to the documentation that the way you showed is the only way.
Also, is there a way to get the equivalent of CV_32FC4 from something that looks more like cv::Mat V(4,1,cv::DataType?<float>::type); ?
Thanks,
David
- Status changed from Done to Cancelled
- (deleted custom field) deleted (
worksforme)
Updated by Vadim Pisarevsky over 13 years ago
there is ambiguity. when the function gets 4x1 matrix, it can be either a set of 4 single-element vectors (i.e. scalars) or a single 4-element vector. To avoid this ambiguity, we always treat MxN single-channel matrix as a set of M N-element vectors. Or you can use Mx1 or 1xM N-channel matrix, which is usually a recommended format. You can also use reshape to switch between the formats.
- Status changed from Cancelled to Done
- (deleted custom field) set to fixed