Open GoogleCodeExporter opened 9 years ago
I've implemented cvRelabel and it works well for me:
void cvRelabel(CvBlobs blobs, IplImage* imgLabel) {
int i=1;
int stepLbl = imgLabel->widthStep/(imgLabel->depth/8);
for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it, i++) {
CvBlob* blob = it->second;
if(blob->label != i) {
for(int y=0; y<imgLabel->height; y++ ) {
CvLabel *label = (CvLabel *) imgLabel->imageData + y * stepLbl;
for(int x=0; x<imgLabel->width; x++) {
if(*label == blob->label) {
*label = i;
}
label++;
}
}
blob->label = i;
}
}
}
Original comment by pablo.platt@gmail.com
on 12 Jan 2011 at 11:11
Hi Pablo,
CvBlobs is not a `vector` but a `map`. This way the "indexes" don't change when
you filter blobs. I used maps for that reason. For example, you have:
blobs[0], blobs[1], blobs[2], blobs[3]
After filter you could have:
blobs[1], blobs[3]
Of course, if you use iterators you'll see that the "first" blobs has
`label=1`, and next blob has `label=3`, but their indexes are the same. If you
need to know the "index" of a iterator you can use `it->first`, but it should
be the equal to `it->second->label`.
So, do a relabel or something like that seems unnecessary to me :-S Can you
overcome the problem in any other way?
I could refactor all the library and use only vector instead of maps (vector
must be more efficient), but I find maps easier when you program.
Regards,
Cristóbal
Original comment by grendel....@gmail.com
on 13 Jan 2011 at 9:57
Original issue reported on code.google.com by
pablo.platt@gmail.com
on 12 Jan 2011 at 10:43