Does anyone know someone with extensive knowledge of c#?

We need some help with the emguCV libraries and pointers/handles in c#. If anyone could help us out with either topic, It would be greatly appreciated.

Never used emguCV, but I have a fair amount of experience with both OpenCV and interfacing with native code in C#.

Do you have a specific question?

Yes, we need help with pointers and handles in c#, which EmguCV uses very often. EmguCV is a .net wrapper for OpenCV.

That’s a very broad topic to talk about in any kind of concrete detail. I’ll start with describing the basic concepts, and then maybe you can provide a piece of example code you’re having trouble understanding, describe a piece of code you’re trying to create, or follow up with a more specific question that I can help you with.

Pointers are, at their simplest, a reference to a location in the computer’s memory. Since the variables in a program are each stored at a certain location in memory, pointers are often used to pass references to a variable to other parts of a program [sorta like ref method parameters in C#]. I’m pretty sure the pointers used by emguCV aren’t for this purpose, though.

The other main use for pointers (and the way emguCV is using them) is to refer to objects that are created at runtime. For example, when you ask emguCV to create an image of a certain size, it will claim enough memory to store the data for that image. The way emguCV remembers where the image data is stored in memory is by keeping a pointer to it.

When a program claims memory to store an object, it’s also responsible for releasing that claim on that memory when it’s done with it. If the program doesn’t do this, it’s called a memory leak, and this is bad. For example, if you create an image each time you process a camera frame, but never release the memory associated with that image when you’re done processing that frame, then your program will start using more and more memory over time, since it can’t reuse any of that memory when it creates more images for processing new frames.

The reason you don’t have to worry about this with C# is that C# uses something called garbage collection, where it automatically keeps track of which objects you’re still using and releases an object’s memory once your program is done with it.

If you use the CvInvoke class members from emguCV, you’re calling directly to the unmanaged functions and you’ll get pointers back that you’ll have to manage and remember to release manually. However, part of the power of emguCV is that it’ll do this memory management automatically, by leveraging C#'s memory management. To use these features, use classes like Image<>.

To talk briefly about handles: handles are another type of reference to an object in memory, but when you call something a “handle,” the value of this reference is not necessarily the actual memory address of the object. The value of handle is understood by the code that gave that handle to you, but you shouldn’t try to interpret the value yourself. For example, with emguCV, suppose you use the CvInvoke class and get an IntPtr back. You then pass this IntPtr value around your program so that whenever you call another image processing function, emguCV will know which image it’s supposed to process. The actual value of the IntPtr means nothing to your program, though, and reading from the memory it points to won’t necessarily yield any meaningful data, so these IntPtrs are functioning more like handles. Handles are sometimes called “opaque references” because you can’t “see through” the reference to “look at” the actual object.

Being mainly a C# programmer my self, I have used EmguCV and had very bad experiences with it throwing all kinds of errors because it didn’t wrap OpenCV correctly.

What about syntax? What are the common uses of pointer & handles in emgucv? What are the biggest things I’d need to know about while working with emguCV in c# (like pointers and how they work with some structs and junk)?

Thanks for the advice so far. Work has been going really slowly since we started running into pointers in emgu.

I don’t know what’s up with your emgu version, but our installation seems to be working just fine. You might have been using an unstable version or something.

While it’s possible to use unsafe pointers directly in C# using a similar syntax to that of C, this is generally advised against. Usually pointers are stored as IntPtr-typed values in C# - you can see an example of this here: http://www.emgu.com/wiki/index.php/Tutorial#Function_Mapping_-_Emgu.CV.CvInvoke Note that this is a rather low-level interface in emguCV, though, and like I said earlier, you should probably be using the managed classes instead: http://www.emgu.com/wiki/index.php/Working_with_Images

What makes you think you think you need to use pointers with emguCV?

Well I tried about 3 different versions, starting with the most recent and ending with the very first one. I don’t know what I could be doing wrong:/

I need to know more about using pointers in emgu because emgu has some methods, specifically optical flow and the PyrLK method, that only accept pointers as parameters. Not to mention knowing how to work pointers would be a good skill to have.