2
votes

i'm new to opencv and i'm trying to run some codes..i need to get a v-disparity map from a disparity map.i 'm using a two rectified image to get stereo matching and after that the dense disparity map.i got the disparity map and when i tryed to tronsform it on v-disparity i got nothing an empty window appeared.i'm refering to the algorithm proposed by : Raphael Labayrade, Didier Aubert, Jean-Philippe Tarel in their article Real Time Obstacle Detection in Stereovision on Non Flat Road Geometry Through ”V-disparity” Representation.
hear is my code :

int main(int argc, char *argv[]){       
  int nbrepetion ; 
  Mat img = imread(argv[1],0); 
  Mat image(img.rows,img.cols, CV_8UC1); 
  if(img.empty()){
    printf("Could not load image file\n");
    exit(0);
  }
  int height = img.rows;
  int width = img.cols;
  int a = width ; 
  int k = 0 ; 
  uchar pos =0 ; 
  for(int i = 0; i < height; i++){
    for(int j = 0; j < width; j++)
    for (int k = 0; k < a; k++){
      if(img.at<uchar>(i,j) == img.at<uchar>(i,k)) {
        nbrepetion ++ ; 
      } 
    }  
    if(nbrepetion == 1){
      image.at<uchar>(i,k) = img.at<uchar>(i,k);
    } else {
      pos = img.at<uchar>(i,k); 
      image.at<uchar>(pos,k) = nbrepetion;
    }
    nbrepetion = 0 ;     
  }
  namedWindow("disparityimage", CV_WINDOW_AUTOSIZE);
  imshow("disparityimage", image ); 
  waitKey(0);
  return 0;
}
2

2 Answers

2
votes

For a v-disparity image: Use a matrix of size (rows, maxVal) and increment the corresponding element by 1 for each line of the disparity image where the disparity value corresponds to a column in the v-disparity image.

Repeat this along rows for the u-disparity image.

1
votes

Let us denote disparity image as disp of size (height, width). The output is v-disparity image of size (height, maxDisp), where maxDisp is maximum value in disparity image. Lets denote it vdisp. Algorithm (pseudo code) is as follows:

For each i in disp.Rows DO    
    For each j in disp.Columns      
        if disp(i, j) > 0 Then   
            vdisp(i, disp(i,j)++
        end
    end
end

If you look at your v-disparity image, straight vertical lines represent surfaces of obstacles, and straight diagonal line represent ground surface plane. You can use Hough Transform to identify straight lines in the v-disparity image. In the paper "FPGA implementation of the V-disparity based obstacles detection approach" it is very good explained.