예제 #1
0
파일: menu.c 프로젝트: stqism/DEMOS
getmenu ()
{
	if (! menu[0].len)
		initmenu ();

	getboxes ();
	VMPutString (LINES-1, 0, "\0011\16      \17 2\16      \17 3\16      \17 4\16      \17 5\16      \17 6\16      \17 7\16      \17 8\16      \17 9\16      \01710\16Quit \17\2");
	for (;;) {
		drawhead (nmenu);
		for (;;) {
			drawmenu (&menu[nmenu]);
			hidecursor ();
			VSync ();
			switch (KeyGet ()) {
			default:
				VBeep ();
				continue;
			case cntrl (']'):          /* redraw screen */
				VRedraw ();
				continue;
			case cntrl ('M'):
				clrmenu (&menu[nmenu]);
				return (1);
			case cntrl ('J'):
				clrmenu (&menu[nmenu]);
				return (2);
			case cntrl ('C'):
			case cntrl ('['):
			case meta ('J'):        /* f0 */
				clrmenu (&menu[nmenu]);
				return (0);
			case meta ('r'):        /* right */
				clrmenu (&menu[nmenu]);
				if (! menu[++nmenu].mname)
					nmenu = 0;
				break;
			case meta ('l'):        /* left */
				clrmenu (&menu[nmenu]);
				if (--nmenu < 0) {
					for (nmenu=0; menu[nmenu].mname; ++nmenu);
					--nmenu;
				}
				break;
			case meta ('u'):        /* up */
				upmenu (&menu[nmenu]);
				continue;
			case meta ('d'):        /* down */
				downmenu (&menu[nmenu]);
				continue;
			}
			break;
		}
	}
}
예제 #2
0
파일: PM_dem.cpp 프로젝트: NoListen/adpm
void	PM_dem::detect( Mat &img, float score_thresh, bool show_hints, bool show_img, string save_img )
{
	if( score_thresh==DEFAULT_THRESH )
		model.threshing = model.thresh;
	else
		model.threshing = score_thresh;

	hints = show_hints;

	// 1. Feature pyramid <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	prag_start = yuGetCurrentTime('M');
	if( hints ){
		printf("Calculating feature pyramid ...\n");
		start_clock = prag_start;
	}

	featpyramid2( img, model, pyra );	

	if( hints ){
		end_clock = yuGetCurrentTime('M');
		printf("Time for _featpyramid is %gs\n",(end_clock-start_clock)/1000.f);		
	}

	// 2. Compute PCA projection of the feature pyramid <<<<<<<<<<<<<<
	if( hints ){
		printf("Compute PCA projection of the feature pyramid ...\n");
		start_clock = end_clock;
	}
	
	/*Mat Ctest = model.C2(Rect(0,155,32,1));
	cout<<Ctest;*/

	//project_pyramid( model, pyra );

	
	if( hints ){
		end_clock = yuGetCurrentTime('M');
		printf("Time for _project_pyramid() is %gs\n",(end_clock-start_clock)/1000.f);
	}

	if (hints)
	{
		end_clock = start_clock;
		printf("QT\n");
	}

	qtpyra(model,pyra);
	
	if (hints)
	{
		end_clock = yuGetCurrentTime('M');
		printf("%gs\n",(end_clock-start_clock)/1000.f);
	}
	
	if( pyra.num_levels!=pyra.feat.size() ){
		printf("pyra.num_levels!=pyra.feat.size()\n");
		throw	runtime_error("");	
	}


	// 3. Precompute location/scale scores <<<<<<<<<<<<<<<<<<<<<<<
	Mat	loc_f = loc_feat( model, pyra.num_levels );
	pyra.loc_scores.resize( model.numcomponents );
	for( int c=0; c<model.numcomponents; c++ ){
		Mat	loc_w( 1, model.loc[c].w.size(), CV_32FC1, &(model.loc[c].w[0]) ); // loc_w = model.loc[c].w 
		pyra.loc_scores[c] = loc_w * loc_f; 
	}

	// 4. Gather PCA root filters for convolution <<<<<<<<<<<<<<<<<<<
	if( hints ){
		printf("Gathering PCA root filters for convolution ...\n");
		start_clock = end_clock;
	}

	if( rootscores[0].size()!=pyra.num_levels ){
		vector<Mat>	tmp_rootscores(pyra.num_levels);
		rootscores.assign(model.numcomponents,tmp_rootscores);
	}	

//	ofstream f1("pj.txt");

	int	numrootlocs = 0;
	int	s = 0; // will hold the amount of temp storage needed by cascade()
	for( int i=0; i<pyra.num_levels; i++ ){
		s += pyra.feat[i].rows * pyra.feat[i].cols;
		if( i<model.interval )
			continue;
		static vector<Mat>	scores;
		//fconv( pyra.projfeat[i], rootfilters, 0, numrootfilters, scores );
		fconv_root_qt(model, pyra.qtfeat[i], scores);
		for( int c=0; c<model.numcomponents; c++ ){
			int u = model.components[c].rootindex;
			int v = model.components[c].offsetindex;
			float	tmp = model.offsets[v].w + pyra.loc_scores[c].at<float>(i);
			rootscores[c][i] = scores[u] + Scalar(tmp);
			numrootlocs += scores[u].total();
		}
	}
	cout<<numrootlocs<<endl;
	s = s * model.partfilters.size();

	if( hints ){
		end_clock = yuGetCurrentTime('M');
		printf("Time for gathering PCA root filters is %gs\n",(end_clock-start_clock)/1000.f);
	}

	// 5. Cascade detection in action <<<<<<<<<<<<<<<<<<<<<<<
	if( hints ){
		printf("Cascade detection in action ...\n");
		start_clock = end_clock;
	}

	//Mat coords = cascade(model, pyra, rootscores, numrootlocs, s);
	Mat coords = cascade_qt(model, pyra, rootscores, numrootlocs, s);
	//cout<<coords;
	//cout<<"??"<<endl;

	if( hints ){
		end_clock = yuGetCurrentTime('M');
		printf("Time for _cascade() is %gs\n",(end_clock-start_clock)/1000.f);
		if( coords.empty() ){
			printf("No Detection!\n");
			return;
		}
	}

	// 6. Detection results <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	Mat boxes = getboxes( model, img_color, coords );
	Mat x1 = boxes.col(0);
	Mat y1 = boxes.col(1);
	Mat x2 = boxes.col(2);
	Mat y2 = boxes.col(3);
	Mat Score = boxes.col( boxes.cols-1 );	
	detections.resize( x1.rows );
	for( int i=0; i<x1.rows; i++ ){
		detections[i][0] = x1.at<float>(i);
		detections[i][1] = y1.at<float>(i);
		detections[i][2] = x2.at<float>(i);
		detections[i][3] = y2.at<float>(i);
		detections[i][4] = Score.at<float>(i);
	}

	if( hints ){
		prag_end = yuGetCurrentTime('M');
		printf("Total detection time is : %gs\n",(prag_end-prag_start)/1000.f);
	}

	// 6. Draw and show <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<	
	if( show_img || !save_img.empty() ){
		//showboxes( img_color, boxes );

		//
		const int fontFace = CV_FONT_HERSHEY_PLAIN;
		const double fontScale = 1;		
		const Scalar drawColor = CV_RGB(255,0,0);
		const Scalar fontColor = CV_RGB(30,250,150);
		//
		for( int i=0; i!=detections.size(); i++ ){
			float		x1 = detections[i][0], y1 = detections[i][1], x2 = detections[i][2], y2 = detections[i][3];
			float		_score = detections[i][4];			
			//
			Point2f		UL( x1, y1 );
			Point2f		BR( x2, y2 );
			rectangle( img_color, UL, BR, drawColor, 2 );
			printf("----------------------------\n");
			printf("%g  %g  %g  %g  %g\n", x1, y1, x2, y2, _score );
			//
			x1 = int(x1*10+0.5) / 10.f; // ½ö±£Áô1λСÊý
			y1 = int(y1*10+0.5) / 10.f;
			x2 = int(x2*10+0.5) / 10.f;
			y2 = int(y2*10+0.5) / 10.f;
			_score = int(_score*100+0.5) / 100.f;			
			//
			char	buf[50] = { 0 };
			sprintf_s( buf, 50, "%d", i );
			string   text = buf;
			int		  baseline = 0;
			Size	  textSize = getTextSize( text, fontFace, fontScale, 1, &baseline );
			Point2f   textOrg2( x1, y1+textSize.height+2 );
			putText( img_color, text, textOrg2, fontFace, fontScale, fontColor );
			//				
			sprintf_s( buf, 50, "%d %g %g %g %g %g", i, x1, y1, x2, y2, _score );
			text = buf;			
			textSize = getTextSize( text, fontFace, fontScale, 1, &baseline );
			Point2f	  textOrg(5,(i+1)*(textSize.height+3));
			putText( img_color, text, textOrg, fontFace, fontScale,	fontColor );
		}
		{
			char	buf[30] = { 0 };
			sprintf_s( buf, 30, "time : %gs", (prag_end-prag_start)/1000.f );
			string		time_text = buf;
			int			baseline = 0;
			Size		textSize = getTextSize( time_text, fontFace, fontScale, 1, &baseline );
			Point2f	time_orig(5,(detections.size()+1)*(textSize.height+3));
			putText( img_color, time_text, time_orig, fontFace, fontScale, fontColor );
		}
		if( show_img )
			imshow( "OK", img_color );		
		if( !save_img.empty() )
			imwrite( save_img, img_color );

	}
	
}