All pastes #800332 Raw Edit

Unbenannt

public text v1 · immutable
#800332 ·published 2007-11-28 10:31 UTC
rendered paste body
        public ArrayList findPointMatches(ImageMap leftMap, ImageMap rightMap)
        {
            try
            {
                if (leftImage != null && rightImage != null)
                {
                    ArrayList arrayControl = new ArrayList();

                    // unlimited Number of Keypoints
                    int iMaxPairKeypoints = 0;
                    iImageDoneCount = 0;

                    ArrayList memoryKeypointsList = new ArrayList();

                    //keypointsTarget = KeypointsTarget.Memory;

                    if (leftBlurredImage != null && rightBlurredImage != null)
                    {
                        leftMap = GenerateKeypointForImage((Bitmap)leftBlurredImage, memoryKeypointsList);

                        rightMap = GenerateKeypointForImage((Bitmap)rightBlurredImage, memoryKeypointsList);
                    }
                    else
                    {
                        leftMap = GenerateKeypointForImage((Bitmap)leftImage, memoryKeypointsList);

                        rightMap = GenerateKeypointForImage((Bitmap)rightImage, memoryKeypointsList);
                    }


                    MultiMatch mm = new MultiMatch();

                    mm.LoadKeysetsFromMemory(memoryKeypointsList);
                    //mm.MatchKeypoint += new MultiMatch.MatchKeypointEventHandler(UpdateMatchProgress);

                    ArrayList mtchs = mm.LocateMatchSets(3, iMaxPairKeypoints,
                        true, true);
                    // useRANSAC = true, useAreaFilter = true

                    // Component check.
                    ArrayList components = mm.ComponentCheck(mtchs);

                    if (components.Count > 1)
                    {
                        string componentDesc = "";
                        int compN = 1;
                        foreach (MultiMatch.Component comp in components)
                            componentDesc += String.Format("component {0}: {1}\n\n", compN++, comp);

                        MessageBox.Show(String.Format
                            ("A connected-component check has identified {0} components among the image matches. This means, there are images that have no connection with other images. The following components have been identified:\n\n{1}", components.Count, componentDesc),
                            "Warning",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                    }

                    MultiMatch.MatchSet ms = (MultiMatch.MatchSet)(mtchs[0]);

                    matches = ms.Matches;

                    return matches;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return null;
            }

            return null;
        }

        private ImageMap GenerateKeypointForImage(Bitmap b, ArrayList memoryKeypointsList)
        {
            try
            {
                DisplayImage disp = new DisplayImage(b);
                int pW = disp.Width;
                int pH = disp.Height;

                double startScale = 1.0;


                // TODO:        tweak here!!!!!!!
                ImageMap picMap = disp.ConvertToImageMap(null);
                disp = null;

                LoweFeatureDetector lf = new LoweFeatureDetector();
                lf.DetectFeaturesDownscaled(picMap, 0, 1.0 / startScale);
                iImageDoneCount++;

                memoryKeypointsList.Add(new KeypointXMLList(null,
                        pW, pH, lf.GlobalNaturalKeypoints));

                return picMap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }