int segmentRGBAndDepthFrame ( unsigned char * RGB , unsigned short * Depth , unsigned int width , unsigned int height , struct SegmentationFeaturesRGB * segConfRGB , struct SegmentationFeaturesDepth * segConfDepth, struct calibration * calib , int combinationMode ) { //We have some criteria for segmentation at segConfRGB , and segConfDepth //First of all we want to use them and the original frames (RGB,Depth) , and select ( on an abstract array ) //the areas we want and the areas we don't want .. //We select the area for segmentation from RGB frame unsigned char * selectedRGB = selectSegmentationForRGBFrame(RGB , width , height , segConfRGB , calib); //We select the area for segmentation from Depth frame unsigned char * selectedDepth = selectSegmentationForDepthFrame(Depth , width , height , segConfDepth , calib); //We may chose to combine , or make a different selection for the RGB and Depth Frame if ( combinationMode == DONT_COMBINE ) { //If we dont want to combine them we just execute the selection and RGB will //now have the segmented output frame executeSegmentationRGB(RGB,selectedRGB,width,height,segConfRGB); //The same goes for Depth executeSegmentationDepth(Depth,selectedDepth,width,height,segConfDepth); } else { //If we do want to combine the selections "Together" , and there are many ways to do that using //the combinationMode switch ( see enum combinationModesEnumerator ) , we first make a new selection //and then execute the segmentation using it unsigned char * combinedSelection = combineRGBAndDepthToOutput(selectedRGB,selectedDepth,combinationMode,width,height); if (combinedSelection==0) { fprintf(stderr,"Failed to combine outputs using method %u\Cannot execute segmentation\n",combinationMode); } else {
int segmentRGBAndDepthFrame ( unsigned char * RGB , unsigned short * Depth , unsigned int width , unsigned int height , struct SegmentationFeaturesRGB * segConfRGB , struct SegmentationFeaturesDepth * segConfDepth, struct calibration * calib , int combinationMode ) { struct calibration lastMomentEmptyCalibration={0}; if (RGB==0) { fprintf(stderr,"segmentRGBAndDepthFrame called with a null RGB frame \n"); return 0; } if (Depth==0) { fprintf(stderr,"segmentRGBAndDepthFrame called with a null Depth frame \n"); return 0; } if (calib==0) { fprintf(stderr,"segmentRGBAndDepthFrame called with a null Calibration , generating an ephimeral one now \n"); NullCalibration( width, height, &lastMomentEmptyCalibration ); calib=&lastMomentEmptyCalibration; } if (segConfRGB==0) { fprintf(stderr,"segmentRGBAndDepthFrame called with a null RGB Segmentation configuration \n"); } else if (!segConfRGB->isInitialized) { fprintf(stderr,"segmentRGBAndDepthFrame called with a non initialized RGB Segmentation configuration\n"); } if (segConfDepth==0) { fprintf(stderr,"segmentRGBAndDepthFrame called with a null Depth Segmentation configuration \n"); } else if (!segConfDepth->isInitialized) { fprintf(stderr,"segmentRGBAndDepthFrame called with a non initialized Depth Segmentation configuration\n"); } if (segConfDepth->autoPlaneSegmentation) { automaticPlaneSegmentation(Depth,width,height, segConfDepth->autoPlaneSegmentationMinimumDistancePoint , segConfDepth->autoPlaneSegmentationMaximumDistancePoint , segConfDepth->planeNormalOffset, segConfDepth->planeNormalSize, segConfDepth, calib); } //We have some criteria for segmentation at segConfRGB , and segConfDepth //First of all we want to use them and the original frames (RGB,Depth) , and select ( on an abstract array ) //the areas we want and the areas we don't want .. //We select the area for segmentation from RGB frame unsigned int selectedRGBCount=0; unsigned char * selectedRGB = selectSegmentationForRGBFrame(RGB , width , height , segConfRGB , calib , &selectedRGBCount); //We select the area for segmentation from Depth frame unsigned int selectedDepthCount=0; unsigned char * selectedDepth = selectSegmentationForDepthFrame(Depth , width , height , segConfDepth , calib , &selectedDepthCount); if ( (selectedDepthCount==width*height) && (selectedRGBCount==width*height) ) { fprintf(stderr,"Both RGB and Depth are fully selected , fastpath doing nothing\n"); } else { //We may chose to combine , or make a different selection for the RGB and Depth Frame if ( combinationMode == DONT_COMBINE ) { //If we dont want to combine them we just execute the selection and RGB will //now have the segmented output frame executeSegmentationRGB(RGB,selectedRGB,width,height,segConfRGB,selectedRGBCount,combinationMode); //The same goes for Depth executeSegmentationDepth(Depth,selectedDepth,width,height,selectedDepthCount,combinationMode); } else if (combinationMode == COMBINE_RGBFULL_DEPTH_USE_RGB ) { //RGB frame is unaffected , Depth Frame uses RGB Segmentation executeSegmentationDepth(Depth,selectedRGB,width,height,selectedDepthCount,combinationMode); } else if (combinationMode == COMBINE_DEPTHFULL_RGB_USE_DEPTH ) { //Depth frame is unaffected , RGB Frame uses DepthSegmentation executeSegmentationRGB(RGB,selectedDepth,width,height,segConfRGB,selectedRGBCount,combinationMode); } else if (combinationMode == COMBINE_SWAP ) { //If we want to swap RGB and Depth we just swap it executeSegmentationRGB(RGB,selectedDepth,width,height,segConfRGB,selectedRGBCount,combinationMode); //The same goes for Depth executeSegmentationDepth(Depth,selectedRGB,width,height,selectedDepthCount,combinationMode); } else { //If we do want to combine the selections "Together" , and there are many ways to do that using //the combinationMode switch ( see enum combinationModesEnumerator ) , we first make a new selection //and then execute the segmentation using it unsigned char * combinedSelection = combineRGBAndDepthToOutput(selectedRGB,selectedDepth,combinationMode,width,height); if (combinedSelection==0) { fprintf(stderr,"Failed to combine outputs using method %u\nCannot execute segmentation\n",combinationMode); } else { //We use the combinedSelection for both RGB and Depth executeSegmentationRGB(RGB,combinedSelection,width,height,segConfRGB,selectedRGBCount,combinationMode); executeSegmentationDepth(Depth,combinedSelection,width,height,selectedDepthCount,combinationMode); //And we dont forget to free our memory if (combinedSelection!=0) { free(combinedSelection); combinedSelection=0; } } } } // We do COMBINE LOGIC //Free memory from selections.. if (selectedRGB!=0) { free(selectedRGB); selectedRGB=0; } if (selectedDepth!=0) { free(selectedDepth); selectedDepth=0; } return 1; }