PXCMFaceAnalysis.Recognition.Model returning Error in C#

PXCMFaceAnalysis.Recognition.Model returning Error in C#

Hello!

I'm using the code provided in the documentation to determine the differences between two faces for the facial recognition module. I did everything as I was suppose to, and I keep getting an Access Violation. I've even tried this on a clean project only using the Facial Recognition module, running on it's own thread, and boom! This same Error slaps me in the face.
 

 

 

 PXCMFaceAnalysis.Recognition.Model createModelFromImage(PXCMImage image)
        {
          

                PXCMFaceAnalysis face3 = QueryFace();
                PXCMImage[] images = new PXCMImage[] { image, null, null, null };
                PXCMScheduler.SyncPoint sp;
                
                face3.ProcessImageAsync(images, out sp);
                sp.Synchronize();
                sp.Dispose();
                int fid; ulong ts;
                face3.QueryFace(0, out fid, out ts);

                PXCMFaceAnalysis.Recognition recta = face3.DynamicCast<PXCMFaceAnalysis.Recognition>(PXCMFaceAnalysis.Recognition.CUID);
                PXCMFaceAnalysis.Recognition.Model m111;
                recta.CreateModel(fid, out m111);
                return m111;
                
           

        }

 

This piece is where I'm getting the Error at this line : recta.CreateModel(fid, out m111);

 

Any idea on what's going on here? I'm pretty lost, because I've been trying to do this multiple ways for the past 5 days with no avail.

Here is the exception I'm being thrown:

System.AccessViolationException was unhandled
  _HResult=-2147467261
  _message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  HResult=-2147467261
  IsTransient=false
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=libpxcclr
  StackTrace:
       at PXCMFaceAnalysis.Recognition.CreateModel(Int32 fid, Model& model)
       at WindowsFormsApplication2.pipeline.createModelFromImage(PXCMImage image) in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 132
       at WindowsFormsApplication2.pipeline.IsSimilar(PXCMImage image1, PXCMImage image2) in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 107
       at WindowsFormsApplication2.pipeline.convertimage(String file, PXCMImage cface) in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 241
       at WindowsFormsApplication2.pipeline.processusers(String directory) in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 199
       at WindowsFormsApplication2.pipeline.checkusers(String directory) in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 175
       at WindowsFormsApplication2.pipeline.checkfaces() in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 153
       at WindowsFormsApplication2.pipeline.OnNewFrame() in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 95
       at WindowsFormsApplication2.Pipe.pipelines() in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Pipe.cs:line 299
       at WindowsFormsApplication2.Form1..ctor() in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs:line 18
       at WindowsFormsApplication2.Program.Main() in c:\Users\Wezeys\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Program.cs:line 23
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

 

This is on a blank project just to see if this exception was being thrown just because or if it was something to do with my main code. Here is the full C# script for it.
http://pastebin.com/Ukh9Yire

 

 

Thank you! 

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Have you followed the sequence face detection, landmark detection, and face recognition in your code? Provide some detail info so I can help you find the issue. Thanks! 

Thanks for the quick reply David!

My full source code is right here for the pipeline. http://pastebin.com/Ukh9Yire 

All I'm doing from there is calling the pipelines function inside the Pipe class to start everything up. 
I don't understand why it's returning an access violation for the CreateModel. Unless it's because I'm calling 
       PXCMFaceAnalysis face3 = QueryFace();

Inside of the createModelFromeImage function. In the documentation I found another bit where it calls PXCMFaceAnalysis face; outside of the createModelFromImage function and then creates a session out of it and later has it used there. I've tried that method but then it gives me a null reference error. The way I currently have it in the pastebin source above is the closest I've been able to get it to work, but it just gives me the Access Violation exception, and the Error details are in my original post.

Thank you for your support! I hope you can help me fix this issue. 

 

Attached is the sample project that I used for this post. If you run it then it'll yield the null reference exception at recta.CreateModel.

Attachments: 

AttachmentSize
Download FaceAnalysisSampleProjectC#.rar197.17 KB

Leave a Comment

Please sign in to add a comment. Not a member? Join today