private void update() { // load calibration data stereointerface.loadCalibration(calibration_filename); // get image data from bitmaps int bytes_per_pixel = 3; // load images into the correspondence object stereointerface.loadImage(fullres_left, image_width, image_height, true, bytes_per_pixel); stereointerface.loadImage(fullres_right, image_width, image_height, false, bytes_per_pixel); // set the quality of the disparity map stereointerface.setDisparityMapCompression(horizontal_compression, vertical_compression); clock.Start(); // perform stereo matching stereointerface.stereoMatchRun(0, 8, correspondence_algorithm_type); long correspondence_time_mS = clock.Stop(); txtStereoCorrespondenceTime.Buffer.Text = correspondence_time_mS.ToString(); // make a bitmap byte[] depthmap = new byte[image_width * image_height * 3]; stereointerface.getDisparityMap(depthmap, image_width, image_height, 0); picDepthMap.Pixbuf = GtkBitmap.createPixbuf(image_width, image_height); GtkBitmap.setBitmap(depthmap, picDepthMap); }
private void update() { // load calibration data stereointerface.loadCalibration(calibration_filename); // get image data from bitmaps int bytes_per_pixel = 3; int image_width = picLeftImage.Image.Width; int image_height = picLeftImage.Image.Height; byte[] fullres_left = new byte[image_width * image_height * bytes_per_pixel]; byte[] fullres_right = new byte[fullres_left.Length]; BitmapArrayConversions.updatebitmap((Bitmap)picLeftImage.Image, fullres_left); BitmapArrayConversions.updatebitmap((Bitmap)picRightImage.Image, fullres_right); // load images into the correspondence object stereointerface.loadImage(fullres_left, image_width, image_height, true, bytes_per_pixel); stereointerface.loadImage(fullres_right, image_width, image_height, false, bytes_per_pixel); // set the quality of the disparity map stereointerface.setDisparityMapCompression(horizontal_compression, vertical_compression); clock.Start(); // perform stereo matching stereointerface.stereoMatchRun(0, 8, correspondence_algorithm_type); long correspondence_time_mS = clock.Stop(); txtStereoCorrespondenceTime.Text = correspondence_time_mS.ToString(); // make a bitmap Bitmap depthmap_bmp = new Bitmap(image_width, image_height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); picDepthMap.Image = depthmap_bmp; byte[] depthmap = new byte[image_width * image_height * 3]; stereointerface.getDisparityMap(depthmap, image_width, image_height, 0); BitmapArrayConversions.updatebitmap_unsafe(depthmap, depthmap_bmp); picDepthMap.Refresh(); }
/// <summary> /// return a disparity map /// </summary> /// <param name="img"></param> /// <param name="width"></param> /// <param name="height"></param> public void getDisparityMap(Byte[] img, int width, int height, int threshold) { stereointerface.getDisparityMap(img, width, height, threshold); }
/// <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); } } }