*leftDepth->widthStep + n; ?
? ? ? ? ? ? ? ? ? ? ? ? pixel2 = *pPixel2; ?
? ? ? ? ? ? ? ? ? ? ? ? if (pixel2 != 0) ?
? ? ? ? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? medianArray[count] = pixel2; ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? count++; ?
? ? ? ? ? ? ? ? ? ? ? ? } ?
??
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? //排序 ?
? ? ? ? ? ? ? ? ? ? for (int k = 0; k< count;k++) ?
? ? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? ? for (int l = k + 1; l< count;l++) ?
? ? ? ? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (medianArray[l] < medianArray[l-1] ) ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? temp = medianArray[l]; ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? medianArray[l] = medianArray[l-1]; ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? medianArray[l-1] = temp; ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? medianVal = medianArray[count/2]; ?
? ? ? ? ? ? ? ? ? ? pPixel = (unsigned char *)leftFilter->imageData + i*leftFilter->widthStep + j; ?
? ? ? ? ? ? ? ? ? ? *pPixel = medianVal; ?
? ? ? ? ? ? ? ? } ?
??
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? } ?
? ? //假如已知左右图片的深度,进行refinement ?
? ? unsigned char dLeft = 0, dRight = 0; ?
? ? count = 0; ?
? ? for (int i = 0; i< imageHeight;i++) ?
? ? { ?
? ? ? ? for (int j = 0; j< imageWidth;j++) ?
? ? ? ? { ?
? ? ? ? ? ? pRightPixel= (unsigned char*)rightDepth->imageData + i*rightDepth->widthStep + j; ?
? ? ? ? ? ? dRight = (*pRightPixel)/10; ?
? ? ? ? ? ? if (j + dRight < imageWidth) ?
? ? ? ? ? ? { ? ? ?
? ? ? ? ? ? ? ? pPixel= (unsigned char*)depth->imageData + i*depth->widthStep + j; ?
? ? ? ? ? ? ? ? pLeftPixel= (unsigned char*)leftDepth->imageData + i*leftDepth->widthStep + j + dRight; ?
? ? ? ? ? ? ? ? dLeft = (*pLeftPixel)/10; ?
? ? ? ? ? ? ? ? if (abs(int(dRight) -(int)dLeft) <= 1) ?
? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? //深度一致 ? ?
? ? ? ? ? ? ? ? ? ? *pPixel = dRight*10; ?
? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }else{ ?
? ? ? ? ? ? ? ? ? ? //深度不一致,认为是误匹配、错误匹配 ?
? ? ? ? ? ? ? ? ? ? *pPixel = 0; ?
? ? ? ? ? ? ? ? ? ? count++; ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? } ?
? ? cout<<"depth Count: ?"<
??
??
? ? cvNamedWindow("leftImage",1); ?
? ? cvNamedWindow("rightImage",1); ?
? ? cvNamedWindow("leftDepth",1); ?
? ? cvNamedWindow("leftValid",1); ?
? ? cvNamedWindow("rightDepth",1); ?
? ? cvNamedWindow("rightValid",1); ?
? ? cvNamedWindow("leftFilter",1); ?
? ? cvNamedWindow("rightFilter",1); ?
? ? cvNamedWindow("depth",1); ?
??
? ? ??
? ? cvShowImage("leftImage",leftImage); ?
? ? cvShowImage("rightImage",rightImage); ?
??
? ? cvShowImage("leftDepth",leftDepth); ?
? ? cvShowImage("rightDepth",rightDepth); ?
??
? ? cvShowImage("leftValid",leftValid); ??
? ? cvShowImage("rightValid",rightValid); ?
??
? ? cvShowImage("leftFilter",leftFilter); ?
? ? cvShowImage("rightFilter",rightFilter); ?
? ? cvShowImage("depth",depth); ?
??
? ? cvSaveImage("leftDepth.jpg",leftDepth); ?
? ? cvSaveImage("rightDepth.jpg",rightDepth); ?
? ? cvSaveImage("leftValid.jpg",leftValid); ?
? ? cvSaveImage("rightValid.jpg",rightValid); ?
? ? cvSaveImage("leftFilter.jpg",leftFilter); ?
? ? cvSaveImage("rightFilter.jpg",rightFilter); ?
? ? cvSaveImage("depth.jpg",depth); ?
??
??
??
? ? fclose(pFile); ?
? ? cvWaitKey(0); ?
? ? return 0; ?
} ?
?
?
?
?
?
?
?
?
?
?