OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 29 Mar 2020 06:33:36 -0500Inverse Matrix from a Decomposehomographyhttp://answers.opencv.org/question/228224/inverse-matrix-from-a-decomposehomography/I need to obtain the inverse of a rotation matrix I get from decomposehomography() but I'm having some trouble as it looks like the type of the matrix I obtain from that function does not seem to work with .inv(). Here's an example where Prev_rot_matrix is another matrix
int solutions = decomposeHomographyMat(H, cameraMatrix, Rs_decomp, ts_decomp, normals_decomp);
for (int i = 0; i < solutions; i++)
{
if(normals_decomp[i].at<double>(2)>0)
{
aux=FrameVar(Rs_decomp[i], Prev_rot_matrix); /*Prev_rot_matrix has the same structure as Rs_decomp[i]*/
if(aux<Var)
{
Var=aux;
SOL=i;
}
}
}
double FrameVar(Mat Rot_Curr, Mat Rot_Prev)
{
//Previous rotation: Rot_Prev ;
current rotation: Rot_Curr
double NewAngle, OldAngle, aux;
Mat Rot_Curr_vect, Rot_Prev_vect;
Mat VarAngle(cv::Size(1,1), CV_64FC1);
Rodrigues(Rot_Curr, Rot_Curr_vect);
Rot_Prev_vect=Rot_Prev.inv()*Rodrigues(Rot_Prev, Rot_Prev_vect);
...
So when I try to compile it I get:
> ‘cv::MatExpr’ is not derived from
> ‘const cv::Affine3<T>’
> Rot_Prev_vect=Rot_Prev.inv()*Rodrigues(Rot_Prev,
> Rot_Prev_vect);
and a bunch of other errors.
In case that that meant Rot_Prev class does not have .inv(), how can I obtain its inverse matrix? I want to get the previous rotation vector in the new frame coordinatesAquasSun, 29 Mar 2020 06:33:36 -0500http://answers.opencv.org/question/228224/Matrix, invert() memory leakhttp://answers.opencv.org/question/209033/matrix-invert-memory-leak/- OpenCV => 3.4.5
- Operating Systemp / Platform -> Windows10 64 bit
- Complier -> Visual Studio 2015
// C++ code example
int m = (int)xData.size();
cv::Mat J_k(m, 4, CV_64FC1);
cv::Mat invJ;
cv::invert(J_k, invJ, cv::DECOMP_SVD); // memory leak
Memory leak occurs when I using the invert function.
Please check this code and HELP me if you know why this leak occurs..
Thx..gaebalsaebalTue, 19 Feb 2019 03:08:03 -0600http://answers.opencv.org/question/209033/Swap black and whitehttp://answers.opencv.org/question/188351/swap-black-and-white/ Hello, I'm using Canny edge detection in a c++ opencv project and the output is in black and white (the lines of the detected objects are in white and the background is black) I would like to know if it's possible to swap/reverse the 2 colors and if so is there a predefined method for it.
Thank you for your help.SafaMon, 02 Apr 2018 04:38:45 -0500http://answers.opencv.org/question/188351/How to Invert 3x2 Transformation Matrixhttp://answers.opencv.org/question/39311/how-to-invert-3x2-transformation-matrix/Hi,
i am having trouble inveting an 3x2 Transformation Matrix. If my original transformation is rotation with +5°, i want the inverse, which rotation is -5°.
Then i want to transform some point with the new inverse Matrix.
If I use
cv::Mat inverse;
inverse = H.inv(cv::DECOMP_SVD);
I get back a matrxi, but it is 2x3 instead of 3x2, and then i cannt use cv::transform anymore because it gets a SIGABRT.
What am i doing wrong ?
regard Peter pkohoutWed, 13 Aug 2014 03:35:28 -0500http://answers.opencv.org/question/39311/why is cv::invert so incredibly slow?http://answers.opencv.org/question/28169/why-is-cvinvert-so-incredibly-slow/hi,
why is cv::invert so incredibly slow?
inverting a 465x465 matrix using svd takes 2minutes.
without svd it still takes ~2sec
octave is much faster
i try to invert a 48984x465 matrix (SVD) and it takes a lot of time (it does not even completed yet) to invert.
using octaves pinv finishes in <20sec;
calculating `inv(R'*R)*R'` in octave takes <10sec
in opencv (without SVD) it also took much more time than my patience allowed me to wait.
I use 2.4.1
has anyone a hint?
edit: the second test (inv(R'*R)*R') was done in debug. obviously it should finish in same time as the first one)
**Edit2:**
i did some tests with the 2.4.8 ocv version:
inverting 465 x 465 matrix without SVD took 0.5s<br>
inverting 465 x 465 matrix with SVD took 5s<br>
inverting 48984 x 465 matrix with SVD took 10min<br>
inverting 48984 x 465 matrix without SVD (inv(R'*R)*R') took 18s (only measured the inv(R'*R) part)
indeed there is a speed up in later opencv versions.
octave timings:
tic; inv(rand(465,465)); toc -> Elapsed time is 0.0780001 seconds.<br>
tic; pinv(rand(465,465)); toc -> Elapsed time is 1.232 seconds.<br>
tic; pinv(rand(48984,465)); toc -> Elapsed time is 15.023 seconds.<br>
R = rand(48984,465); tic;inv(R'*R);toc --> Elapsed time is 0.889 seconds.
In comparistion to octave that afaik also uses SVD to calculate pseudoinverses opencv implementation seems to be very slow. But also the normal inversion does not compare very well.vlad_tepeschTue, 11 Feb 2014 05:36:30 -0600http://answers.opencv.org/question/28169/How to use SIFT with a color inverted imagehttp://answers.opencv.org/question/7956/how-to-use-sift-with-a-color-inverted-image/For example I have two images, where first one is a regular and second one with a color inversion (I mean 255 - pixel color value).
I've applied SIFT algorithm to both of them, so now I have key points and descriptors of each image.
KeyPoints positions do match, but KeyPoints orientations and Descriptors values do not, because of color inversion.
I'm curious do anybody try to solve such a problem?
valgussevSat, 23 Feb 2013 02:50:29 -0600http://answers.opencv.org/question/7956/subtract from white - inverthttp://answers.opencv.org/question/3639/subtract-from-white-invert/I'm looking to invert an image, such that black would become white.
I'm using the C++ OpenCV. The documentation seems to suggest that:
cv::subtract(cv::Scalar:all(255),src,dst);
would work. It doesn't, though it compiles.
I know I can go through pixel by pixel, but I am writing a application that processes live video and need to take advantage of whatever optimizations I can.
Any suggestions are appreciated! I feel like I'm missing something, because the subtract function doesn't appear to be overloaded from looking at the header file...aliasofmikeWed, 31 Oct 2012 15:52:57 -0500http://answers.opencv.org/question/3639/