opencvsharp
opencvsharp copied to clipboard
question ColorMomentHash
Summary of your issue
public override void Compute( InputArray inputArr, OutputArray outputArr ) outputArr Type: OpenCvSharp.OutputArray 42 hash values with type CV_64F(double) Excuse me , the bytes of size is (42 * 64 = 2688 ) bytes ? but :
Mat mat = new Mat(@"2022-06-19-10-09-8176.jpg");
Mat mat2 = new Mat();
var hashfun = ColorMomentHash.Create();
hashfun.Compute(mat, mat2);
byte[] bs = mat2.ToBytes();
Console.WriteLine("字节长度:" + bs.Length.ToString());
result = 69 bytes , why ?
Environment
Write your environment.
What did you do when you faced the problem?
Write here
Example code:
paste your core code
Output:
paste your output
What did you intend to be?
The test code below may help you. https://github.com/shimat/opencvsharp/blob/master/test/OpenCvSharp.Tests/img_hash/ColorMomentHashTest.cs
using Mat mat = new Mat(@"2022-06-19-10-09-8176.jpg");
using Mat mat2 = new Mat();
using var hashfun = ColorMomentHash.Create();
hashfun.Compute(mat, mat2);
mat2.GetArray(out double[] hashValues);
Console.WriteLine(hashValues.Length); // 42
win7 , net 3.5, OpenCvSharp3-AnyCPU I found the following , var hash = new Mat<double>() but in my code , an error was generated , I write the following, var hash = new Mat(new Size(1,42), MatType.CV_64FC1)
The Rows is ok . The Cols is ok . but the data is not ok , I don't have the ToArraymethod here. I use the following method . hash.ToBytes() hash.ToMemoryStream().ToArray() but the number of byte is 69
I try win10,net4.6.1,opencvsharp4.windows
` static void Main(string[] args) { using (var model = ColorMomentHash.Create()) using (var img = new Mat(@"2022-06-19-10-09-8176.jpg")) using (var hash = new Mat(new Size(1, 42), MatType.CV_64FC1)) {
model.Compute(img, hash);
var bs = hash.ToBytes();
Console.WriteLine("number of byte" + bs.Length);
}
}
`
the tesult is 69
You should not use ToBytes, since ToBytes is an alias for ImEncode, which returns the PNG-encoded result of its Mat data.
You should not use ToBytes, since ToBytes is an alias for ImEncode, which returns the PNG-encoded result of its Mat data.
Thank you . i use the following .
double[] dbl = new double[42]; hash.GetArray(0, 0, dbl);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.