Search code examples
c#emgucv

C# EmguCV error "OpenCV: u != 0"


I keep getting this OpenCV: u != 0 error when trying to match some photos. My method looks like this. ImageFile class has some variables. It does this even if I am trying to match one photo. Stacktrace being:

Unhandled Exception: Emgu.CV.Util.CvException: OpenCV: u != 0

at Emgu.CV.CvInvoke.CvErrorHandler(Int32 status, IntPtr funcName, IntPtr errMsg, IntPtr fileName, Int32 line, IntPtr userData)

at Emgu.CV.Features2D.Feature2DInvoke.CvFeature2DDetectAndCompute(IntPtr feature2D, IntPtr image, IntPtr mask, IntPtr keypoints, IntPtr descriptors, Boolean useProvidedKeyPoints)

at Emgu.CV.Features2D.Feature2D.DetectAndCompute(IInputArray image, IInputArray mask, VectorOfKeyPoint keyPoints, IOutputArray descriptors, Boolean useProvidedKeyPoints)

public async Task<List<ImageFile>> BeginSearchAsync()
{
    var foundImageFiles = new List<ImageFile>();
    Mat img = CvInvoke.Imread(_imageFileToBeSearched.FileInfo.FullName, ImreadModes.AnyColor);

    var thredi = new Thread(() =>
    {
        foreach (var imageFile in _listOfSearchableImageFiles)
        {
            try
            {
                using (var tempImage = CvInvoke.Imread(imageFile.FileInfo.FullName, ImreadModes.AnyColor))
                {
                    var result = DrawMatches.Draw(tempImage, img, out long matchTime, out long score);
                    var window = new ResultWindow(result, score);
                    window.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error during matching file {imageFile.Name}");
                Console.WriteLine(ex.Message);
            }
        }
    });

    thredi.SetApartmentState(ApartmentState.STA);
    thredi.Start();
    return foundImageFiles;
}

Solution

  • That exception seems to indicate that app is taking too much memory. In my case I just seemed to have too good quality for the pictures. Reducing them to half fixed the problem.