Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Anyone can help me with Emgu.Cv.Matrix<float> to int When i run the codes without converting;

Argument 1: cannot convert from 'Emgu.CV.Matrix' to 'int'

When i try to Convert.ToInt32(rsmmatrixtanimlayici)

Argument 2: An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll<br />
<br />
Additional information: 'Emgu.CV.Matrix`1[System.Single]' türündeki nesne 'System.IConvertible' türüne atılamadı.


C#
eslestirici = new BruteForceMatcher<Single>(DistanceType.L2);
           eslestirici.Add(aranacakrsmmatrixtanimlayici);
           matrixtanimlayiciindeksleri = new Matrix<int>(rsmmatrixtanimlayici.Rows, enyakinkomsu);
           matrixuzaklik = new Matrix<Single>(Convert.ToInt32(rsmmatrixtanimlayici), enyakinkomsu);
           eslestirici.KnnMatch(rsmmatrixtanimlayici, matrixtanimlayiciindeksleri, matrixuzaklik, enyakinkomsu, null);


[ScreenShot1]

matrixuzaklik is Single matrixuzaklik = new Matrix<single>(rsmmatrixtanimlayici, enyakinkomsu);

[ScreenShot2]

What I have tried:

i have tried to Convert.ToInt32(rsmmatrixtanimlayici) it's not working.
Posted
Updated 27-Oct-16 15:14pm
v3

A matrix is a two dimensional entity in the Emgu CV library whereas you are trying to cast it to a single entity object. That is the problem #1. Secondly, any object that is used under Convert.ToType() function must implement the IConvertible interface (thus, the error that was shown to you).

There are two ways that you can do this, first of all being accessing the data from the Matrix itself,
C#
int value = rsmmatrixtanimlayici[0]; // Is the type int, or single, or float?

Secondly, you may want to use any built-in helper that can do the trick for you, even then you would require to use an integer array (int[] not int) to accommodate for the data in that matrix.

Then again, that all depends on the depth of the Matrix it can be 3-dimensional too, in the case of a color image for instance.

IConvertible Interface (System)[^]
c# - Work with matrix in emgu cv - Stack Overflow[^]
 
Share this answer
 
v2
Comments
dnmxlsm 28-Oct-16 2:59am    
Matrix<single> rsmmatrixtanimlayici;

so it's single
C#
matrixuzaklik = new Matrix<single>(rsmmatrixtanimlayici.Rows, enyakinkomsu);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900