yasaswini1995 / cvblob

Automatically exported from code.google.com/p/cvblob
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Wrong background in use cvFilterLabels #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. use function cvFilterLabels
2.
3.

What is the expected output? What do you see instead?
We want a black background. We see some pixel with wrong value (because this 
pixel are not check).

What version of the product are you using? On what operating system?
version 0.10.1. Windows 7, 64 bits

Please provide any additional information below.
My correction:

  void cvFilterLabels(IplImage *imgIn, IplImage *imgOut, const CvBlobs &blobs)
  {
    CV_FUNCNAME("cvFilterLabels");
    __CV_BEGIN__;
    {
      CV_ASSERT(imgIn&&(imgIn->depth==IPL_DEPTH_LABEL)&&(imgIn->nChannels==1));
      CV_ASSERT(imgOut&&(imgOut->depth==IPL_DEPTH_8U)&&(imgOut->nChannels==1));

      int stepIn  =  imgIn->widthStep / ( imgIn->depth / 8);
      int stepOut = imgOut->widthStep / (imgOut->depth / 8);
      int imgIn_width  = imgIn->width;
      int imgIn_height = imgIn->height;
      int imgIn_offset = 0;
      int imgOut_width  = imgOut->width;
      int imgOut_height = imgOut->height;
      int imgOut_offset = 0;
      if(imgIn->roi)
      {
    imgIn_width  = imgIn->roi->width;
    imgIn_height = imgIn->roi->height;
    imgIn_offset = imgIn->roi->xOffset + (imgIn->roi->yOffset * stepIn);
      }
      if(imgOut->roi)
      {
    imgOut_width = imgOut->roi->width;
    imgOut_height = imgOut->roi->height;
    imgOut_offset = imgOut->roi->xOffset + (imgOut->roi->yOffset * stepOut);
      }

      char *imgDataOut=imgOut->imageData + imgOut_offset;
      CvLabel *imgDataIn=(CvLabel *)imgIn->imageData + imgIn_offset;

      for (unsigned int r=0;r<(unsigned int)imgIn_height;r++,
      imgDataIn+=stepIn,imgDataOut+=stepOut)
      {
        for (unsigned int c=0;c<(unsigned int)imgIn_width;c++)
        {
          if (imgDataIn[c])
          {
            if (blobs.find(imgDataIn[c])==blobs.end()) imgDataOut[c]=0x00;
            else imgDataOut[c]=(char)0xff;
          }
          else
              imgDataOut[c]=(char)0x00; //add by me to correct bug
        }
      }
    }
    __CV_END__;
  }

Original issue reported on code.google.com by mathias....@gmail.com on 30 Jun 2010 at 1:04

GoogleCodeExporter commented 8 years ago
I've just submit the fix to the repository.

Anyway, perhaps I include a function that does not write 0x00 in any case, in 
order to print blobs in another binary image.

Thank you very much!

Original comment by grendel....@gmail.com on 1 Jul 2010 at 9:12