Error in OpenCV blob centroid

Hi,

I’m not sure if this is where I’m supposed to add this question, but I’m working on a project where I have 2 webcams connected to my computer and I want to use the centroid of a blob I’m tracking to get distance to the blob. ( Doing this for a course project that is due soon)

Everything goes great ( thanks openframeworks) until I hit the line in bold and I get a windows error

  
  
  
float tempx1 = finderRed1.blobs[0].centroid.x;  
    float tempx2 = finderRed2.blobs[0].centroid.x;  
    float temp3 = 10;  
[b]   
//    dist = temp3 /(tempx1-tempx2);what I really want   
    dist = tempx1 ; // also give me an error  
[/b]  
  
  

dist is also a float.

I began with the tutorial on color tracking and modified it until I got it working for 2 cameras. The error I get is : process returned 0xC0000005 which google says is some kind of memory access violation.

Using Code:Blocks 8.02 and Windows XP and OpenFrameworks v0.061

Any help is appreciated
Minerva

are you sure that blobs[0] exists all the time?

I put a delay in the code, to make sure that the there was always a blob in the screen before I did the assignment, but still get the error. Something I noticed is that I can assign the blob number to a local variable, but cant apply it to the global variable.

I want it to be global, so that I can print out the result in my GUI.

Any ideas on how to fix this or a work around?

hi,

I’m doing something like this right now, too.

I’m calculating the distance with the ofxVectorMath addon. Maybe you could try this, but it does much like the same as your code.

ben