Ejemplo n.º 1
0
void VideoTrack::filterImagesByFeatures( Detector detID, DescriptorExtractor desID, DescriptorMatcher dmID,
		float ratio, float threshold )
{
	FeatureHandler* featureHandler = new FeatureHandler( detID, desID, dmID );
	proccessImagesFeatures( featureHandler );

	for( std::set< Image* >::iterator it = _images.begin(); it != _images.end(); it++ )
	{
		bool detectedChange = false;
		std::set< Image* >::iterator aux = it; aux++;
		while( !detectedChange && aux != _images.end() )
		{
			featureHandler->findGoodMatches( *it, *aux, ratio );
			float matchThreshold = (*it)->getImageMatchThreshold( *aux );

			if( matchThreshold > threshold )
			{
				Log::notice( "filterImagesByFeatures rejected image " + (*aux)->getPath() );
				_rejectedimages.insert( std::pair< std::string, float >( (*aux)->getPath(), matchThreshold ) );
				aux++;
			}
			else
			{
//				it = aux; --it;
				detectedChange = true;
			}
		}
	}
}
Ejemplo n.º 2
0
void VideoTrack::trackFeatures( Detector detID, DescriptorExtractor desID, DescriptorMatcher dmID,
		float ratio )
{
	FeatureHandler* featureHandler = new FeatureHandler( detID, desID, dmID );

	Image* currentPic = NULL;
	for( std::set< std::string >::iterator it = _files.begin(); it != _files.end(); it++ )
	{
		std::string path( _path + "/" + (*it) );
		Image* img = new Image( path, 0.0f, 0.0f, 0.0f, 0.40f );
		_images.insert( img );

		featureHandler->detect( img );
		featureHandler->computeDescriptors( img );

		if( currentPic )
		{
			featureHandler->findGoodMatches( currentPic, img, ratio );
			std::vector< cv::DMatch > matches = currentPic->getGoodMatches( img );

			for( std::vector< cv::DMatch >::iterator itm = matches.begin(); itm != matches.end(); itm++ )
			{
				int currImgIndex = itm->queryIdx;
				cv::Mat cImgDesc = currentPic->getDescriptors().row( currImgIndex );
				cImgDesc.push_back(cImgDesc);
				cv::KeyPoint cImgkp = currentPic->getKeypoint( currImgIndex );

				TrackFeature* tf = new TrackFeature( currentPic, cImgkp, cImgDesc );
				Image* asImage = tf->asImage();

				bool foundInStorage = false;
				for( std::vector< TrackFeature* >::iterator itt = _featuresInTrack.begin();
								!foundInStorage && itt != _featuresInTrack.end(); itt++ )
				{
					Image* stFeatasImage = (*itt)->asImage();
					featureHandler->findGoodMatches( stFeatasImage , asImage, 1.0 );

					std::vector< cv::DMatch> gm = stFeatasImage->getGoodMatches( asImage );
					if( gm.size() > 0 && gm.at( 0 ).distance == 0 )
					{
						(*itt)->addFeatureImage( img->getPath(), cImgkp );
						foundInStorage = true;
					}
				}
				if( !foundInStorage ) _featuresInTrack.push_back( tf );
			}
		}
		currentPic = img;
	}
}
Ejemplo n.º 3
0
int main( int argc, char** argv )
{
	/**-------------------------- Image entity and image roi --------------------------------------*/
	Image* img1 = new Image( "data/videothumbs/img0001.jpeg", 0.20f, 0.10f, 0.0f, 0.35f );
	img1->show("image");
	img1->showROI("roi");
	cv::waitKey(0);
	cv::destroyAllWindows();

	/**-------------------------- Calculate and compare histograms --------------------------------------*/
	Image* img2 = new Image( "data/videothumbs/img0002.jpeg", 0.10f, 0.0f, 0.60f, 0.0f );

	int imageSections = 3;

	img1->calcHistogram(imageSections);
	img2->calcHistogram(imageSections);
	img1->compareHistograms( img2, CV_COMP_CHISQR );
	img1->printCompareHistograms( img2 );

	img1->showHistogramAsImage();

	cv::waitKey(0);
	cv::destroyAllWindows();

	/**-------------------------- Compute features and match images --------------------------------------*/
	FeatureHandler* fd = new FeatureHandler( DET_FAST, DES_SURF, DESM_FB );

	fd->detect( img1 );
	fd->computeDescriptors( img1 );
	fd->detect( img2 );
	fd->computeDescriptors( img2 );

	float ratio = 0.85f;

	fd->matchDescriptors( img1, img2 );
	fd->findGoodMatches( img1, img2, ratio );

	int numberOfMatches = 60;
	cv::Scalar color = cv::Scalar( 0, 255, 0 );

	cv::Mat resultin;
	cv::Mat resultgd;
	img1->drawMatches( img2, numberOfMatches, MA_IN, resultin, color );
	img1->drawMatches( img2, numberOfMatches, MA_GD, resultgd, color );

	cv::namedWindow("Image initial matches", CV_WINDOW_NORMAL);
	cv::namedWindow("Image good matches", CV_WINDOW_NORMAL);

	cv::imshow("Image initial matches", resultin);
	cv::imshow("Image good matches", resultgd);

	cv::waitKey(0);
}