Esempio n. 1
0
// Create a new Labelable that is consistant with the target type.  If we have a video source type and
// and a image target type then convert the Labelable from a video type to image type. We need
// to new it since the contents will be changed.  For now we assume the target type will always be
// an image target type.
LabelablePtr RunSetIterator::cloneLabelablePtr(const LabelablePtr _pla, int frameNum)
{
  LabelablePtr result;
  LabeledLocationPtr locptr = LabeledLocationPtr::dynamicCast(_pla);
  LabeledVideoSegmentPtr vsptr = LabeledVideoSegmentPtr::dynamicCast(_pla);
  LabeledTrackPtr tptr = LabeledTrackPtr::dynamicCast(_pla);
  if (locptr)
  {
    locptr = new LabeledLocation(*locptr);
    result = (LabelablePtr)locptr;
  }else if (vsptr)
  {
    locptr = new LabeledLocation();
    locptr->loc = vsptr->loc;
    result = (LabelablePtr)locptr;
  }else if (tptr && frameNum != -1)
  {
    FrameLocationList frames = tptr->keyframesLocations;
    FrameLocationList::iterator it;
    for (it = frames.begin(); it != frames.end(); it++)
    {
        FrameLocation floc = *it;
        if (floc.frame.framecnt == frameNum)
        {
            locptr = new LabeledLocation();
            locptr->loc = floc.loc;
            break;
        }
    }
    if (locptr.get() != NULL)
        //result = LabelablePtr::dynamicCast(locptr);
        result = (LabelablePtr)locptr;
    else
    {
        // The object is not in this frame.  If we return a default labelable
        // The the whole image size will be selected so instead we return
        // NULL which should cause frame not to be used.
        result = NULL;
    }
  }else
  {
    result = new Labelable(*_pla);
  }
  return result;
}
Esempio n. 2
0
void BowICETrainI::processPurposedList( PurposedListPtr purList,
                                        bowCV* pBowCV,
                                        TrainerCallbackHandlerPrx& _callback,
                                        const string& CVAC_DataDir,
                                        LabelMap& labelmap, bool* pLabelsMatch
                                        )
{
  if (purList->pur.ptype==cvac::NEGATIVE
      && 0==rejectClassStrategy.compare(bowCV::BOW_REJECT_CLASS_IGNORE_SAMPLES))
  {
    // ignore Negative artifacts according to reject class strategy
    return;
  }
  int _classID = getPurposeId( purList->pur, _callback );
  PurposedLabelableSeq* lab = static_cast<PurposedLabelableSeq*>(purList.get());
  assert(NULL!=lab);
  
  if(lab->labeledArtifacts.size() == 0)
  {
    localAndClientMsg(VLogger::WARN, _callback,
                      "no actual labeledArtifacts in purposed list (%d)\n",
                      purList->pur.classID );
    // ignore and continue
  }
  
  for (size_t artfct=0; artfct< lab->labeledArtifacts.size(); artfct++)
  {						
    string fullName = getFSPath(lab->labeledArtifacts[artfct]->sub.path,
                                CVAC_DataDir);
    string _filename = getFileName(fullName);
    string _filepath = getFileDirectory(fullName);
    string labelname = lab->labeledArtifacts[artfct]->lab.name;
    
    LocationPtr pLoc = NULL;
    if(lab->labeledArtifacts[artfct]->ice_isA("::cvac::LabeledLocation"))
    {
      LabeledLocationPtr plabeledLocation =
        LabeledLocationPtr::dynamicCast(lab->labeledArtifacts[artfct]);
      if (plabeledLocation)
      {
        assert( NULL!=plabeledLocation.get() );
        pLoc = plabeledLocation->loc;				
      }
      else
      {
        printf("TODO: *** RunSetWrapper needs to fix this, it ignores the loc:\n");
        printf("WEIRD: *** why is ice_isA true but the cast returns null?\n");
      }
    }
    processSingleImg(_filepath,_filename, _classID, pLoc, pBowCV, _callback);

    // try to insert labelname into labelmap; abort if conflict
    Purpose pur = purList->pur;
    string prevname = labelmap[ purList->pur ];
    if (prevname.empty())
    {
      labelmap[ purList->pur ] = labelname;
    }
    else if ( prevname!=labelname )
    {
      *pLabelsMatch = false;
    }
  }
}
Esempio n. 3
0
static std::string processLabelable(string CVAC_DataDir,
                                    LabelablePtr lptr, RectangleLabels *rlabels, bool square, 
                                    GetImageSizeFunction sfunc)
{    
  
        Substrate sub = lptr->sub;
        FilePath  filePath = sub.path;
        std::string fname = CVAC_DataDir + "/" + filePath.directory.relativePath;
        fname += std::string("/");
        fname += filePath.filename;
       
        LabeledLocationPtr locptr =
                 LabeledLocationPtr::dynamicCast(lptr);
        if (locptr.get() != NULL)
        {
            SilhouettePtr sptr = SilhouettePtr::dynamicCast(locptr->loc);
            BBoxPtr bptr = BBoxPtr::dynamicCast(locptr->loc);
            if (sptr.get() != NULL)
            {
                BBoxPtr lrect = new BBox();
                int minx = -1;
                int miny = -1;
                int maxx = -1;
                int maxy = -1;
                std::vector<Point2DPtr>::iterator itpt;
                for (itpt = sptr->points.begin(); itpt < sptr->points.end(); itpt++)
                {
                    Point2DPtr pptr = (*itpt);
                    if (minx == -1)
                        minx = pptr->x;
                    else if (pptr->x < minx)
                        minx = pptr->x;
                    if (maxx == -1)
                        maxx = pptr->x;
                    else if (pptr->x > maxx)
                        maxx = pptr->x;
                    if (miny == -1)
                        miny = pptr->y;
                    else if (pptr->y < miny)
                        miny = pptr->y;
                    if (maxy == -1)
                        maxy = pptr->y;
                    else if (pptr->y > maxy)
                        maxy = pptr->y;
                }
                lrect->x = minx;
                lrect->y = miny;
                lrect->width = maxx - minx + 1;
                lrect->height = maxy - miny + 1; 
                // If the detector only wants square rectangles then adjust the smallest 
                // side to equal the largest and center the original rectangle.
                if (square)
                {
                    if (lrect->width != lrect->height)
                    {
                        int diff;
                        if (lrect->height > lrect->width)
                        {
                            diff = lrect->height - lrect->width;
                            lrect->x = lrect->x - diff/2;
                            lrect->width = lrect->width + diff;
                        }else
                        {
                            diff = lrect->width - lrect->height;
                            lrect->y = lrect->y - diff/2;
                            lrect->height = lrect->height + diff;
                        }
                    }

                }
                rlabels->rects.push_back(lrect);  
            } else if (bptr.get() != NULL)
            {
                rlabels->rects.push_back(bptr);
            }
            
        }else if (sfunc != NULL) {
            // Assume no location so return with and height of the image
            int w;
            int h;
            // We need to keep the rectangle in sync with the files so if not found return 0 width/height
            BBoxPtr lrect = new BBox();
            lrect->x = 0;
            lrect->y = 0;
            if ((*sfunc)(fname, w, h))
            {
                lrect->width = w;
                lrect->height = h;
   
            } else {
                lrect->width = 0;
                lrect->height = 0;
            }
            rlabels->rects.push_back(lrect);
        }
   
   
        return fname;
}