Color tracking - dynamic plugin

Heyy guys!

I would like to ask for some tips and help regarding my school project. We have to write a color tracker which returns the center point of the tracked object.

The “ColorTracker (FreeFrame DShow9)” node works perfectly, but it would be way better if I could write my own code for something similar.

Is it possible to write a dynamic plugin that takes a texture input which then I can store in an array and work with that? Or what about a pixel shader? Or how can I use the openCV library? What would be the best solution?

Sorry for the too many question, I’m a bit confused about how to proceed?

Thanks in advance!
Geri

you could write your own cv-node. see this: https://github.com/elliotwoods/VVVV.Packs.Image

Telling from a short google about color detection with EmguCV, a plugin like that is indeed perfectly possible.

I am not sure how proficient you are in c#, but I think a basic introduction to the Image framework is helpful anyway. When Elliot introduced his concepts during last Node it helped me a lot, and I think I might have not have figured it out on my own.

Contour is a good example of a tracker (maybe just a little convoluted). Also, it shows the basic principle of most (all?) Image plugins.

The main plugin class is ContourNode:

#region PluginInfo
	[PluginInfo(Name = "Contour", Category = "CV.Image", Version = "", Help = "Finds contours in binary image", Tags = "analysis")](PluginInfo(Name = "Contour", Category = "CV.Image", Version = "", Help = "Finds contours in binary image", Tags = "analysis"))
	#endregion PluginInfo
	public class ContourNode : IDestinationNode<ContourInstance>

You will see, that there is no Evaluate() method in the plugin, which is different to most other Plugins you will ever encounter in vvvv. That is because Evaluate() is handled by IDestinationNode, which is NOT an interface, but an abstract class.

This trickery has been done to hide some of the complexities, that arise from Image’s multithreading foundation. Instead you are supposed to implement Update().
More importantly, however, you also need to implement another class, in this case it is ContourInstance, which handles the actual logic of detection.

public class ContourInstance : IDestinationInstance

There are two methods you have to do: Allocate() and Process(). In Allocate(), you reserve some chunk of memory, that will always contain the most recent image. In Process() you do the actual call to the EmguCV framework (which in the case of Contour seemed to be a pain, telling from the comments).

If you have a multiple Images, there will be an indiviual ContourInstance for each of them. This will be done automatically by the underlying abstract classes and provided to you in form of FProcessors.

You can see that the ContourInstance kind of doubles all the IDiffSpread-Pins from the actual plugin with Spread and saveguards any access to them with a lock. All the actual plugin does is writing to and reading from them to ensure smooth asyncronous working.

Telling from your problem, your code might be a lot less complicated (line 23 to 59 are not needed). Good luck!

@velcrome: Thanks a lot! I think I get it, but I might need some further assistance later though :)