www.pudn.com > Estereo.rar > stereoMatching_algo.cpp


/***************************************************************************  
* 
* Copyright 2004 by the Massachusetts Institute  of Technology.   All    
* rights reserved.  
*   
* Developed  by David Demirdjian 
* at the Computer Sciences and Artificial Intelligence Laboratory,  
* MIT, Cambridge, Massachusetts.  
*   
* Permission to use, copy, or modify this software and  its documentation  
* for  educational  and  research purposes only and without fee  is hereby  
* granted, provided  that this copyright notice and the original authors's  
* names appear  on all copies and supporting documentation.  If individual  
* files are  separated from  this  distribution directory  structure, this  
* copyright notice must be included.  For any other uses of this software,  
* in original or  modified form, including but not limited to distribution  
* in whole or in  part, specific  prior permission  must be  obtained from  
* MIT.  These programs shall not  be  used, rewritten, or  adapted as  the  
* basis  of  a  commercial  software  or  hardware product  without  first  
* obtaining appropriate licenses  from MIT.  MIT. makes no representations  
* about the suitability of this  software for any purpose.  It is provided  
* "as is" without express or implied warranty.  
*   
**************************************************************************/ 
#include "stereoMatching.h" 
#include "processingMMX.h" 
 
typedef unsigned char uchar; 
typedef unsigned short ushort; 
 
#define ALLOC_ALIGN_MEMORY(X, X_origin, type, size) (X_origin)=((type*)malloc((size)*sizeof(type)+63)); (X) = (type*)((((unsigned int)(X_origin))+63) & (~63)); 
//#define _DDMIN(X,Y) ((X<=Y)?(X):(Y)) 
//#define __max(X,Y) ((X>=Y)?(X):(Y)) 
 
 
 
#define _PROCESS_AND_COMPARE_ \ 
	sum_Row(ptBuff , ptBuff16+2*backStep,	subImageSize, maskSizeX); \ 
	avg_Col(ptBuff16+backStep , ptBuff-backStep,subImageSize, width, maskSizeY); \ 
	copyMMX(ptBuff16, ptBuff16+subImageSize, 2*backStep*sizeof(short));  \ 
	findMinimumCorrelation(ptBuff-backStep, i+k,	imDepth+offset-backStep, \ 
								corrScore+offset-backStep, 	corrScoreSec+offset-backStep,\ 
								subImageSize); 
 
#define _PROCESS_AND_COMPARE_SSE2_ \ 
	ImgSubandAdd_sse2(imr8_bw , imtop8_bw +(i+k)*width , iml8_bw +(i+k) ,ptBuff , subImageSize); \ 
	sum_Row(ptBuff , ptBuff16+2*backStep,	subImageSize, maskSizeX); \ 
	avg_Col(ptBuff16+backStep , ptBuff-backStep,subImageSize, width, maskSizeY); \ 
	copyMMX(ptBuff16, ptBuff16+subImageSize, 2*backStep*sizeof(short));  \ 
	findMinimumCorrelation(ptBuff-backStep, i+k,	imDepth+offset-backStep, \ 
								corrScore+offset-backStep, 	corrScoreSec+offset-backStep,\ 
								subImageSize); 
								 
void StereoMatching::estimateStereo(const uchar* iml8_bw,  
									const uchar* imr8_bw, 
									const uchar* imtop8_bw,									 
									int width, int height, int maskSizeX, int maskSizeY,  
									char minDiff, int nbDepth, 
									uchar** buff, int buffStep, // buffStep: dist. between buff[i] and buff[i+1] 
									uchar* corrScore, uchar* imDepth, 
									int nbPartitions) 
{ 
	// assure good partitioning (.....) 
	while (height/nbPartitions - 2*(maskSizeY/2) <=0) 
	{ 
		nbPartitions /= 2; 
	} 
 
	int i,j,k; 
	int subImageSize=width*height/nbPartitions; 
 
	int backStep = (maskSizeY/2)*width; 
 
	int buffStep16 = buffStep; 
	uchar* ptBuff; 
	ushort* ptBuff16; 
	int siz; 
 
	// ----------- process the first sub-images ----------- 
	for (i=0; i