Example #1
0
    bool ArrayMatchingMatchExpression::matches( const BSONObj& doc, MatchDetails* details ) const {

        FieldRef path;
        path.parse(_path);

        bool traversedArray = false;
        int32_t idxPath = 0;
        BSONElement e = getFieldDottedOrArray( doc, path, &idxPath, &traversedArray );

        string rest = pathToString( path, idxPath+1 );

        if ( rest.size() == 0 ) {
            if ( e.type() == Array )
                return matchesArray( e.Obj(), details );
            return false;
        }

        if ( e.type() != Array )
            return false;

        BSONObjIterator i( e.Obj() );
        while ( i.more() ) {
            BSONElement x = i.next();
            if ( ! x.isABSONObj() )
                continue;

            BSONElement sub = x.Obj().getFieldDotted( rest );
            if ( sub.type() != Array )
                continue;

            if ( matchesArray( sub.Obj(), NULL ) ) {
                if ( details && details->needRecord() ) {
                    // trying to match crazy semantics??
                    details->setElemMatchKey( x.fieldName() );
                }
                return true;
            }
        }

        return false;
    }
Example #2
0
// Attempts to recognize the plate.  Returns a confidence level.  Updates teh "stateCode" variable 
// with the value of the country/state
int StateIdentifier::recognize(Mat img, char* stateCode)
{

  timespec startTime;
  getTime(&startTime);
  
  cvtColor(img, img, CV_BGR2GRAY);
  
  resize(img, img, getSizeMaintainingAspect(img, config->stateIdImageWidthPx, config->stateIdimageHeightPx));
  
  Mat plateImg(img.size(), img.type());
  //plateImg = equalizeBrightness(img);
  img.copyTo(plateImg);
  
  Mat debugImg(plateImg.size(), plateImg.type());
  plateImg.copyTo(debugImg);
  vector<int> matchesArray(featureMatcher->numTrainingElements());
  
  
  RecognitionResult result = featureMatcher->recognize(plateImg, true, &debugImg, true, matchesArray );
  
  if (this->config->debugStateId)
  {
    
    
    displayImage(config, "State Identifier1", plateImg);
    displayImage(config, "State Identifier", debugImg);
    cout << result.haswinner << " : " << result.confidence << " : " << result.winner << endl;
  }
  
  
  if (config->debugTiming)
  {
    timespec endTime;
    getTime(&endTime);
    cout << "State Identification Time: " << diffclock(startTime, endTime) << "ms." << endl;
  }
  
  
  if (result.haswinner == false)
    return 0;
  
  strcpy(stateCode, result.winner.c_str());
  
  
  return result.confidence;
}
Example #3
0
    bool ArrayMatchingMatchExpression::matches( const MatchableDocument* doc, MatchDetails* details ) const {
        MatchableDocument::IteratorHolder cursor( doc, &_elementPath );

        while ( cursor->more() ) {
            ElementIterator::Context e = cursor->next();
            if ( e.element().type() != Array )
                continue;

            bool amIRoot = e.arrayOffset().eoo();

            if ( !matchesArray( e.element().Obj(), amIRoot ? details : NULL ) )
                continue;

            if ( !amIRoot && details && details->needRecord() && !e.arrayOffset().eoo() ) {
                details->setElemMatchKey( e.arrayOffset().fieldName() );
            }
            return true;
        }
        return false;
    }
Example #4
0
  // Attempts to recognize the plate.  Returns a confidence level.  Updates the region code and confidence
  // If region is found, returns true.
  bool StateIdentifier::recognize(PipelineData* pipeline_data)
  {
    timespec startTime;
    getTime(&startTime);

    Mat plateImg = Mat(pipeline_data->grayImg, pipeline_data->regionOfInterest);

    resize(plateImg, plateImg, getSizeMaintainingAspect(plateImg, config->stateIdImageWidthPx, config->stateIdimageHeightPx));


    Mat debugImg(plateImg.size(), plateImg.type());
    plateImg.copyTo(debugImg);
    vector<int> matchesArray(featureMatcher->numTrainingElements());

    RecognitionResult result = featureMatcher->recognize(plateImg, true, &debugImg, true, matchesArray );

    if (this->config->debugStateId)
    {
      displayImage(config, "State Identifier1", plateImg);
      displayImage(config, "State Identifier", debugImg);
      cout << result.haswinner << " : " << result.confidence << " : " << result.winner << endl;
    }

    if (config->debugTiming)
    {
      timespec endTime;
      getTime(&endTime);
      cout << "State Identification Time: " << diffclock(startTime, endTime) << "ms." << endl;
    }

    if (result.haswinner == false)
      return 0;

    pipeline_data->region_code = result.winner;
    pipeline_data->region_confidence = result.confidence;

    if (result.confidence >= 10)
      return true;

    return false;
  }
Example #5
0
 bool ArrayMatchingMatchExpression::matchesSingleElement( const BSONElement& e ) const {
     if ( e.type() != Array )
         return false;
     return matchesArray( e.Obj(), NULL );
 }