public void setMaxDisparity(int max_disparity) { stereointerface.setMaxDisparity(max_disparity); }
/// <summary> /// perform stereo matching of the given images and save the /// results with the given filename /// </summary> /// <param name="calibration_filename">stereo camera calibration filename</param> /// <param name="data_filename">file into which disparity data will be saved</param> /// <param name="image_data">list containing two mono images</param> /// <param name="image_width">width of the image in pixels</param> /// <param name="image_height">height of the image in pixels</param> /// <param name="maximum_disparity_percent">maximum disparity as a percentage of the image width</param> /// <param name="output_filename">filename to save the depth map as</param> private static void StereoMatch(string calibration_filename, string data_filename, List <byte[]> image_data, int image_width, int image_height, int maximum_disparity_percent, string output_filename) { int horizontal_compression = 1; int vertical_compression = 3; // an interface to different stereo correspondence algorithms sentience_stereo_interface stereointerface = new sentience_stereo_interface(); // load calibration data if (calibration_filename != "") { stereointerface.loadCalibration(calibration_filename); } //the type of stereo correspondance algorithm to be used int correspondence_algorithm_type = sentience_stereo_interface.CORRESPONDENCE_CONTOURS; // load images into the correspondence object stereointerface.loadImage(image_data[0], image_width, image_height, true, 1); stereointerface.loadImage(image_data[1], image_width, image_height, false, 1); // set the quality of the disparity map stereointerface.setDisparityMapCompression(horizontal_compression, vertical_compression); // set the maximum disparity as a percentage of the image width stereointerface.setMaxDisparity(maximum_disparity_percent); // perform stereo correspondence stereointerface.stereoMatchRun(0, 8, correspondence_algorithm_type); // make a bitmap to store the depth map byte[] depthmap = new byte[image_width * image_height * 3]; stereointerface.getDisparityMap(depthmap, image_width, image_height, 0); // save disparity data to file if (data_filename != "") { SaveData(data_filename, depthmap, image_width, image_height); } if (output_filename != "") { // save output as a jpeg if ((output_filename.ToLower().EndsWith(".jpg")) || (output_filename.ToLower().EndsWith(".jpeg"))) { Bitmap depthmap_bmp = new Bitmap(image_width, image_height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); BitmapArrayConversions.updatebitmap_unsafe(depthmap, depthmap_bmp); depthmap_bmp.Save(output_filename, System.Drawing.Imaging.ImageFormat.Jpeg); } // save output as a bitmap if (output_filename.ToLower().EndsWith(".bmp")) { Bitmap depthmap_bmp = new Bitmap(image_width, image_height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); BitmapArrayConversions.updatebitmap_unsafe(depthmap, depthmap_bmp); depthmap_bmp.Save(output_filename, System.Drawing.Imaging.ImageFormat.Bmp); } // save output as a pgm if (output_filename.ToLower().EndsWith(".pgm")) { image.saveToPGM(depthmap, image_width, image_height, output_filename); } } }