takuya-takeuchi / UltraFaceDotNet

C# version of Ultra-Light-Fast-Generic-Face-Detector-1MB for Windows, MacOS, Linux, iOS and Android
MIT License
80 stars 16 forks source link

always memory is corrupt #11

Closed danijerez closed 3 years ago

danijerez commented 3 years ago

Hi,

I have tried different configurations but I always get the exception

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

private static void Test()
        {
            string apppath = AppDomain.CurrentDomain.BaseDirectory;

            var param = new UltraFaceParameter
            {
                BinFilePath = apppath + @"\Resources\RFB-320.bin",
                ParamFilePath = apppath + @"\Resources\RFB-320.param",
                InputWidth = 320,
                InputLength = 240,
                NumThread = 1,
                ScoreThreshold = 0.7f
            };

            using (var ultraFace = UltraFace.Create(param))
            {

                var imageFile = apppath+ @"\Resources\faces.jpg";
                Console.WriteLine($"Processing {imageFile}");

                using var frame = Cv2.ImRead(imageFile);
                using var inMat = NcnnDotNet.Mat.FromPixels(frame.Data, NcnnDotNet.PixelType.Bgr2Rgb, frame.Cols, frame.Rows);

                var faceInfos = ultraFace.Detect(inMat).ToArray();
                for (var j = 0; j < faceInfos.Length; j++)
                {
                    var face = faceInfos[j];
                    var pt1 = new Point<float>(face.X1, face.Y1);
                    var pt2 = new Point<float>(face.X2, face.Y2);
                    Cv2.Rectangle(frame, pt1, pt2, new Scalar<double>(0, 255, 0), 2);
                }

                Cv2.ImShow("UltraFace", frame);
                Cv2.WaitKey();
                Cv2.ImWrite("result.jpg", frame);

                frame.Dispose();
                imageFile = null;
                inMat.Dispose();
                faceInfos = null;

            }
        }
tristanrenaud commented 3 years ago

I got this same exception with a similar code. Did you check RFB-320.param file’s content? Every line should be the same than https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB/blob/master/ncnn/data/version-RFB/RFB-320.param (It was the root cause for me).