Esempio n. 1
0
    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);
    }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        public unsafe void stereoMatch(Byte[] left_bmp, Byte[] right_bmp,
                                       int width, int height, bool colourImages)
        {
            if (!initialised)
            {
                initialised = true;
            }

            int BytesPerPixel = 3;

            if (!colourImages)
            {
                BytesPerPixel = 1;
            }

            stereointerface.loadImage(left_bmp, width, height, true, BytesPerPixel);

            stereointerface.loadImage(right_bmp, width, height, false, BytesPerPixel);

            setMaxDisparity(max_disparity_percent);
            setRequiredFeatures(required_features);

            // do the stereo correspondence
            stereointerface.stereoMatchRun(0, peaks_per_row, correspondence_algorithm_type);

            // retrieve features
            no_of_disparities = stereointerface.getSelectedPointFeatures(disparities);

            // track the features
            features = new stereoFeatures(no_of_disparities);

            if (correspondence_algorithm_type == 0)
            {
                for (int i = 0; i < no_of_disparities * 3; i++)
                {
                    features.features[i] = disparities[i];
                }
                tracking.update(features, width, height);
                for (int i = 2; i < no_of_disparities; i += 3)
                {
                    disparities[i] = features.features[i];
                }
            }
            //robot_head.features[0] = features;

            // update radar
            radar.update(width, height, features);

            // dynamically adjust the difference threshold to try to
            // maintain a constant number of stereo features
            if (no_of_disparities < required_features * 9 / 10)
            {
                difference_threshold -= 1;
                if (difference_threshold < 10)
                {
                    difference_threshold = 10;
                }
                setDifferenceThreshold(difference_threshold);
                if (no_of_disparities < required_features * 8 / 10)
                {
                    if (peaks_per_row < 10)
                    {
                        peaks_per_row++;
                    }
                }
            }
            else
            {
                if (no_of_disparities >= required_features * 9 / 10)
                {
                    if (peaks_per_row > 5)
                    {
                        peaks_per_row--;
                    }
                    else
                    {
                        difference_threshold += 2;
                        if (difference_threshold > 10000)
                        {
                            difference_threshold = 10000;
                        }
                        setDifferenceThreshold(difference_threshold);
                    }
                }
            }

            prev_features = features;
        }
Esempio n. 4
0
        /// <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);
                }
            }
        }