Thursday, April 11, 2013

OpenCV perforamce (效能測試) FPS 小的原因


+ it cost 200ms
--> (context switch + access the pixel 50x384=19200 pixel)


 
    // gray debug
    // 2013/4/12: performance low
	public void RunDebug_1(Mat image)
	{
		Log.i(TAG,"+++RunDebug_1");
		
		int rows = image.rows();
		int cols = image.cols();
		
		//Log.i(TAG,"row:"+rows+"cols:"+cols);
		
		double [] d;
		int r,c;
		double g;
		
		//Log.i(TAG,"+++sslake check 1");
		for(r=0;r<rows;r++)
		{
			for(c=0;c<cols;c++)
			{
				d= image.get(r, c);
				//gray= 0.299*R+ 0.587*G + 0.114*B
				g = 0.299* d[0]+0.587*d[1] + 0.114*d[2];
				
				image.put(r,c,g,g,g,255);
				
			}
			//if(r %50 ==0)
			//	Log.i(TAG,"+++sslake check 1 r:->"+r);
		}
		
	
	}
Result: the Performance is bad, FPS is 0.56 .
    
// Case 2: sslake : use the OpenCV Lib:
// Code:
Imgproc.cvtColor(image, image, Imgproc.COLOR_RGB2GRAY);

Result: The FPS is around 14.  (14/0.56=25倍的差異)

No comments:

Post a Comment