Search code examples
trackingjavacv

Tracking objects using javaCV


I am trying to track faces using Camshift in JavaCV. I have found Open CV equivalent at:

https://gist.github.com/231696

I have been successfully able to convert much part of the code, but struggling to figure out the equivalent of the following in JavaCV. Any help will be really appreciated.

TrackedObj* obj;

if((obj = malloc(sizeof *obj)) != NULL) {

obj->hsv  = cvCreateImage(cvGetSize(image), 8, 3);
obj->mask = cvCreateImage(cvGetSize(image), 8, 1);
obj->hue  = cvCreateImage(cvGetSize(image), 8, 1);
obj->prob = cvCreateImage(cvGetSize(image), 8, 1);
}

Solution

  • Well, we can define a class similar to the struct TrackedObj like this:

    class TrackedObj {
        IplImage hsv;
        IplImage hue;
        IplImage mask;
        IplImage prob;
        CvHistogram hist;
        CvRect prev_rect;
        CvBox2D curr_box;
    } 
    

    And we can translate the bit of code you point out in a very similar fashion like this:

    TrackedObj obj = new TrackedObj();
    obj.hsv  = cvCreateImage(cvGetSize(image), 8, 3);
    obj.mask = cvCreateImage(cvGetSize(image), 8, 1);
    obj.hue  = cvCreateImage(cvGetSize(image), 8, 1);
    obj.prob = cvCreateImage(cvGetSize(image), 8, 1);