Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using OpenTLD in a Managed Application #45

Open
vreddy1990 opened this issue Feb 27, 2014 · 1 comment
Open

Using OpenTLD in a Managed Application #45

vreddy1990 opened this issue Feb 27, 2014 · 1 comment

Comments

@vreddy1990
Copy link

I have tried compiling OpenTLD as a dll and importing into a c# application. I am able to create and delete objects in the unmanaged dll from the managed application using pInvoke. But as after I create a pointer to Main the application will crash if I do any of the following:

  • Delete the Unmanaged object containing a pointer to Main
  • Run any of the main->tld-> functions
  • Even cvReleaseImage(&img); crashes the application

The message that I get is 'System.AccessViolationException' occurred - Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Has anyone used OpenTLD as a dll in a managed application? Are there any memory issues that I should be aware of?

@vreddy1990
Copy link
Author

Adding "nnClassifier = NULL;" in the destructor for TLD and removing the if code below fixed nearly all of the problems.
if(nnClassifier)
{
delete nnClassifier;
nnClassifier = NULL;
}
The nnClassifier was already cleaned out in detectorCascade.nnClassifier and since they were pointing to the same object it was trying to delete a second time. I placed the delete nnClassifier in DetectorCascade destructor in the above if block and set it to NULL.

The cVReleaseImage(&img) should not have been called in my code since I was feeding OpenTLD an IplImage struct from my c# application.

So I do have OpenTLD working as an imported unmanaged dll in by c# application. Please consider changing the destructor code for nnClassifier as I mentioned above. It took me a few days to find this since Visual studio does not let me debug an unmanaged dll from within a managed application. This will prevent application crash when OpenTLD is used as a dll.

Vinay Reddy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant