Пример #1
0
	//--------------------------------------------------
	vector<KeyPoint> MatchableImage::findFeatures()
	{
		if(featureAlgUsed.empty())
		{
			log(LOG_LEVEL_DEBUG, "Warning: default findFeatures() called and no previous algorithm set.  Using SURF!");
			return findFeatures("SURF");
		}
		else
		{
			return findFeatures(featureAlgUsed);
		}
		
	}
Пример #2
0
void FeatureDetector::findFeatures(RGBDFrame& frame)
{
  boost::mutex::scoped_lock(mutex_);

  const cv::Mat& input_img = frame.rgb_img;

  cv::Mat gray_img(input_img.rows, input_img.cols, CV_8UC1);
  const cv::Mat* ptarget_img = NULL;

//  if (input_img.type() != CV_8UC1)
//  {
//    // convert from RGB to grayscale only if necessary
//    cvtColor(input_img, gray_img, CV_BGR2GRAY);
//    ptarget_img = &gray_img;
//  }
//  else
    ptarget_img = &input_img;

  // blur if needed
  if(smooth_ > 0)
  {
    int blur_size = smooth_*2 + 1;
    cv::GaussianBlur(*ptarget_img, *ptarget_img, cv::Size(blur_size, blur_size), 0);
  }

  // find the 2D coordinates of keypoints
  findFeatures(frame, *ptarget_img);

  // calculates the 3D position and covariance of features
  frame.computeDistributions(max_range_, max_stdev_);
}
Пример #3
0
void OpticalFlow::computeFeatures(const bool cached_ok) {
  CHECK(frame_added_ && !features_computed_ && !flow_computed_,
        "Optical Flow function called out of order!");

  const FramePair& prev_change = frame_pairs_[geNthIndexFromEnd(1)];
  FramePair* const curr_change = &frame_pairs_[geNthIndexFromEnd(0)];

  const int32 num_found_features = prev_change.countFoundFeatures();
  const clock_t ms_since_last_refresh =
      (curr_change->end_time - last_time_fresh_features_);

  if (cached_ok &&
      num_found_features >= MIN_FEATURES &&
      ms_since_last_refresh <= REGEN_FEATURES_MS) {
    // Reuse the found features from the last frame if we can.
    curr_change->number_of_features_ =
        copyFeatures(prev_change, curr_change->frame1_features_);
  } else {
    // Only find new features to track if we've lost too many since the last
    // time, or it's time to regenerate anyway.
    LOGV("Not enough features (%d/%d), or it's been too long (%ld), "
         "finding more.",
         num_found_features, MIN_FEATURES, ms_since_last_refresh);
    findFeatures(prev_change, curr_change);
  }

  features_computed_ = true;
}
Пример #4
0
	//--------------------------------------------------
	// As of writing this, you can use:
	// SIFT, SURF
	Mat MatchableImage::findDescriptors(string alg_name)
	{
		if(descriptorsCurrent && descriptorAlgUsed.compare(alg_name)==0) return descriptors;
		if(!featuresCurrent) findFeatures();
		
		if(empty() || features.size()==0)
		{
			log(LOG_LEVEL_ERROR, "in findDescriptors(), image is empty or there are no features in image");
		}
		
		Mat cvImageGray;
		cvtColor(cvImage, cvImageGray, CV_RGB2GRAY);
		
		Ptr<DescriptorExtractor> descriptorExtractor = createDescriptorExtractor(alg_name);
		if(descriptorExtractor==0)
		{
			log(LOG_LEVEL_ERROR, "Detector not found!");
		}
		
		descriptorExtractor->compute( cvImageGray, features, descriptors );
		log(LOG_LEVEL_DEBUG, "in findDescriptors(), %d x %d descriptors", descriptors.rows, descriptors.cols);
		
		descriptorAlgUsed = alg_name;
		descriptorsCurrent=true;
		matcherTrained=false;
		return descriptors;
	}
Пример #5
0
	//--------------------------------------------------
	vector<KeyPoint> MatchableImage::findFeatures(string alg_name, Mat &bounds)
	{
		vector<KeyPoint> tempFeatures = findFeatures(alg_name);
		features.clear();
		for(int i=0; i<tempFeatures.size(); i++)
		{
			double inside = pointPolygonTest(bounds, features[i].pt, true);
			if(inside>=0)
			{
				features.push_back( tempFeatures[i] );
			}
			else
			{
				double dist = abs(inside);
				if(dist < (tempFeatures[i].size/2.))
				{
					features.push_back( tempFeatures[i] );
				}
			}
		}
		
		log(LOG_LEVEL_DEBUG, "in findFeatures(), after filtering by bounds, there are %d features", features.size());
		
#ifdef DEBUG		
		for(int i=0; i<4; i++)
		{
			float *p1 = bounds.ptr<float>(i%4);
			float *p2 = bounds.ptr<float>((i+1)%4);
			//line(cvImage, Point(p1[0], p1[1]), Point(p2[0],p2[1]), CV_RGB(255,255,255), 3);
		}
#endif
		
		featuresCurrent=true;
		return features;
	}
Пример #6
0
	//--------------------------------------------------
	// As of writing this, you can use:
	// ONEWAY, FERN, BruteForce, BruteForce-L1, Planar
	void MatchableImage::trainMatcher(string alg_name)
	{
		if(matcherTrained && matchAlgUsed.compare(alg_name)==0) return;
		
		log(LOG_LEVEL_DEBUG, "Training matcher %s", alg_name.c_str());
		
		/*
		// These don't require descriptors.  It's all rolled up in the matcher.
		if(!alg_name.compare("FERN")||!alg_name.compare("ONEWAY")||!alg_name.compare("CALONDER"))
		{
			findFeatures();
			genericDescriptorMatch = createDescriptorMatcher(alg_name, "fern_params.xml");
			
			log(LOG_LEVEL_DEBUG, "training matcher");
			Mat img = bw();
			genericDescriptorMatch->add( img, features );
			
		}
		*/
		
		if(!alg_name.compare("BruteForce")||!alg_name.compare("BruteForce-L1"))
		{
			findDescriptors();
			descriptorMatcher = createDescriptorMatcher(alg_name.c_str());
			descriptorMatcher->clear();
			descriptorMatcher->add( descriptors ); 
		}
		
		if(!alg_name.compare("Planar"))
		{
			if(featureAlgUsed.compare("L")!=0)
			{
				log(LOG_LEVEL_DEBUG, "Planar detector works best with L detector.  Switching!");
				findFeatures("L");
			}
			
			Size patchSize(32, 32);
			planarDetector.setVerbose(true);
			planarDetector.train(pyramid(ldetector.nOctaves-1), features, patchSize.width, 100, 11, 10000, ldetector, gen);
			
		}
		matchAlgUsed = alg_name;
	}
WidgetProperties* WidgetParseManifest::widgetProperties()
{
    WidgetProperties *props = new WidgetProperties;

    //props->setId(value(W3CSettingsKey::WIDGET_ID));
    QString widgetid = m_manifest->value(W3CSettingsKey::WIDGET_ID );
    QString widgetType = m_manifest->value(ProprietarySettingsKey::WIDGET_TYPE);

    /**
     *  1) Try to: set id for widget from config.xml id field
     *  2) Set QUid
     *
     *  This avoid widgets installation failure in following case:
     *  - Install a widget which does not have id in field config.xml (id will be "", this hashed to zero)
     *  - Install a second widget that does not have id field in config.xml (install of second widget failed)
     *
     */
     // TODO: Check if this is required or need to emit error
    if (widgetid.isEmpty()) {
      widgetid = QUuid::createUuid().toString();
    }
    QString certId = getCertificateAKI();
    QString uniqueId("");
    // If widget is already installed, don't generate uniqueId
    QString rootDir = m_WidgetInfo[EPropertyInstallDirectory].toString();
    if (WebAppUniquenessHelper::getUniqueNameFromPath(rootDir, uniqueId)) {
        WebAppInfo appInfo;
        if (WebAppRegistry::instance()->isRegistered(uniqueId, appInfo)) {
            // grab it from registry
            uniqueId = appInfo.appId();
        }
        else
             uniqueId.clear();
    }
    else 
        uniqueId.clear();   //Restore uniqueId to calculate for first time

    WebAppUniquenessHelper *uniquenessHelper = new WebAppUniquenessHelper(rootDir);
    if ( ( uniqueId.isEmpty() || uniqueId.isNull() ) && uniquenessHelper ) {
        // if it is not already installed, generate uniqueId
        uniqueId = uniquenessHelper->generateUniqueWebAppId(widgetid, certId, getTrustDomain());
        delete uniquenessHelper;
    }
        
    props->setId(uniqueId);
    m_WidgetInfo[ EPropertyWidgetId ] = uniqueId;

    if (!widgetType.isEmpty() && !widgetType.compare(WIDGET_PACKAGE_FORMAT_JIL))
        props->setType(WIDGET_PACKAGE_FORMAT_JIL);
    else
        props->setType(WIDGET_PACKAGE_FORMAT_WGT);

    WidgetFeatures features;
    WidgetErrorType error= findFeatures(features);
    if(error != EErrorNone)
        return NULL;
    else {
        if(features.count()) {
            QList<QString> required_capabilities;
            QList<QString> optional_capabilities;
            if (m_mapping.getCapabilities(features,required_capabilities,optional_capabilities)) {
                if (required_capabilities.contains(CAPABILITY_OVI))
                    props->setType(WIDGET_PACKAGE_FORMAT_OVIAPP);
            }
        }
    }

    QString id = props->id();
    props->setInstallPath(rootDir+ QDir::separator() + id + QDir::separator());
    props->setHiddenWidget(m_manifest->value(ProprietarySettingsKey::WIDGET_HIDDEN).startsWith('T',Qt::CaseInsensitive));
    props->setSource(m_WidgetInfo[EPropertyFilePath].toString());
    props->setInfoPList(m_manifest->getDictionary());
    props->setSize(m_WidgetInfo[EPropertyWidgetSize].toULongLong());
    props->setResourcePath(resourcePath(props->installPath()));
    props->setAllowBackgroundTimers(m_manifest->value(
              ProprietarySettingsKey::WIDGET_BACKGROUND_TIMERS).startsWith("neversuspend",Qt::CaseInsensitive));

    props->setMinimizedSize(QSize( m_manifest->value(ProprietarySettingsKey::WIDGET_VIEWMODE_MINIMIZED_SETTINGS,"width").toInt(),
                                   m_manifest->value(ProprietarySettingsKey::WIDGET_VIEWMODE_MINIMIZED_SETTINGS,"height").toInt()) );
    WAC::WrtSettings* m_settings = WAC::WrtSettings::createWrtSettings();
    QString myLang = m_settings->valueAsString("UserAgentLanguage");
    if (myLang.isEmpty() || myLang.compare(" ") == 0) {
        QLocale language = QLocale::system();
        myLang = language.name().toLower();
        myLang.replace(QString("_"),QString("-"));
    }

    QString myTitle = m_manifest->value(W3CSettingsKey::WIDGET_NAME, QString(""), myLang);
    if (!myLang.isEmpty()) {
        if (!myTitle.isEmpty()) {
            props->setTitle(myTitle);
            m_WidgetInfo[EPropertyWidgetName] = myTitle;
        }
    }

    if (myLang.isEmpty() || myTitle.isEmpty()) {
        QString wName = m_manifest->value(W3CSettingsKey::WIDGET_NAME);
        if (wName.isEmpty()) {
            wName = "NoName";
        }
        props->setTitle(wName);
        m_WidgetInfo[EPropertyWidgetName] = wName;
    }

    QString myTitleDir = m_manifest->value(W3CSettingsKey::WIDGET_NAME, QString("its:dir"));
    if (!myTitle.isEmpty() && !myTitleDir.isEmpty() && isDirectionValid(myTitleDir)) {
        props->setTitleDir(myTitleDir);
    }

    QStringList icons;
    if (findIcons(icons)) {
        QString iconPath = props->installPath() + icons.at(0);
        if (!icons.at(0).startsWith(QDir::separator()) && !props->installPath().endsWith(QDir::separator())) {
            iconPath = props->installPath()+QDir::separator()+icons.at(0);
        }
        if (icons.at(0).startsWith(QDir::separator()) && props->installPath().endsWith(QDir::separator())) {
            iconPath = props->installPath();
            iconPath.chop(1);
            iconPath.append(icons.at(0));
        }
        props->setIconPath(iconPath);
    } else {
        props->setIconPath(":/resource/default_widget_icon.png");
    }

    QString myDesc    = m_manifest->value(W3CSettingsKey::WIDGET_DESCRIPTION, QString(""), myLang);
    QString myDescDir = m_manifest->value(W3CSettingsKey::WIDGET_DESCRIPTION, QString("its:dir"));
    if (!myDesc.isEmpty() && !myDescDir.isEmpty() && isDirectionValid(myDescDir)) {
        props->setDescriptionDir(myDescDir);
    }

    QString myAuthor;
    if (!myLang.isEmpty()) {
        myAuthor    = m_manifest->value(W3CSettingsKey::WIDGET_AUTHOR, QString(""), myLang);
    } else {
       myAuthor = m_manifest->value(W3CSettingsKey::WIDGET_AUTHOR);
    }

    QString myAuthorDir = m_manifest->value(W3CSettingsKey::WIDGET_AUTHOR, QString("its:dir"));
    if (!myAuthor.isEmpty() && !myAuthorDir.isEmpty() && isDirectionValid(myAuthorDir)) {
        props->setAuthorDir(myAuthorDir);
    }

    QString myLic;
    if (!myLang.isEmpty()) {
        myLic = m_manifest->value(W3CSettingsKey::WIDGET_LICENSE, QString(""), myLang);
    } else {
       myLic = m_manifest->value(W3CSettingsKey::WIDGET_LICENSE);
    }
    m_WidgetInfo[EPropertyLicenseInfo]=myLic;


    QString myLicDir = m_manifest->value(W3CSettingsKey::WIDGET_LICENSE, QString("its:dir"));
    if (!myLic.isEmpty() && !myLicDir.isEmpty() && isDirectionValid(myLicDir)) {
        props->setLicenseDir(myLicDir);
    }

    props->setLanguages(m_manifest->languages());  //Adding language set to widget properties

    QString version = (props->plistValue(W3CSettingsKey::WIDGET_VERSION)).toString();
    m_WidgetInfo[EPropertyWidgetVersion]=version;

    return props;
}
Пример #8
0
 // Find feature in images from internal image array.
      JNIEXPORT jint JNICALL
      Java_fr_ensicaen_panandroid_stitcher_StitcherWrapper_findFeatures
      (JNIEnv* env, jobject obj)
      {
              return findFeatures();
      }