void Run(Mat src1, Mat src2) { IList <DMatch> matches; MatOfKeyPoint keypoints1 = new MatOfKeyPoint(), keypoints2 = new MatOfKeyPoint(); if (OutLookAR.Utils.ORBMatcher(src1, src2, keypoints1, keypoints2, out matches) == 0) { IList <DMatch> lowPassFilterMatches = matches.LowPassFilter(); List <Point> matchPoint1L = new List <Point>(); List <Point> matchPoint2L = new List <Point>(); foreach (DMatch match in lowPassFilterMatches) { matchPoint1L.Add(keypoints1.toArray()[match.queryIdx].pt); matchPoint2L.Add(keypoints2.toArray()[match.trainIdx].pt); } if (matchPoint1L.Count > 0) { ARTransform ARtorans = _lMedS.findARTransform(matchPoint2L.ToArray(), matchPoint1L.ToArray()); Debug.Log(string.Format("matchPoint1L.Count = {0} ,ARtorans.Error = {1}", matchPoint1L.Count, ARtorans.Error)); if (ARtorans.Error < filter) { Vector2 TTheta = new Vector2(HorizontalAngle * ARtorans.Tx / Width, VerticalAngle * ARtorans.Ty / Height); Matrix2x2 R = new Matrix2x2((float)Math.Cos(-(double)ARtorans.Radian), -(float)Math.Sin(-(double)ARtorans.Radian), (float)Math.Sin(-(double)ARtorans.Radian), (float)Math.Cos(-(double)ARtorans.Radian)); Vector2 TRTheta = R * TTheta; Debug.Log(R + " * " + TTheta + " = " + TRTheta); float LthetaX = TRTheta.x, LthetaY = TRTheta.y; CameraObject.transform.localRotation = Quaternion.Euler(-LthetaY, -LthetaX, ARtorans.Radian.Degree()); Debug.Log(ARtorans); } } } }
void Run() { if (MapDescriptors == null) { CaptureMat.ORBPointFeature(MapKeyPoints, MapDescriptors); } IList <DMatch> matches; MatOfKeyPoint keypoints = new MatOfKeyPoint(); MatOfFloat descriptors = new MatOfFloat(); CaptureMat.ORBPointFeature(keypoints, descriptors); if (descriptors.type() == CvType.CV_8U && MapDescriptors.type() == CvType.CV_8U) { matches = Utils.CrossMatcher(descriptors, MapDescriptors); if (matches.Count <= 0) { return; } } else { return; } IList <DMatch> lowPassFilterMatches = matches.LowPassFilter(); List <Point> matchPoint1L = new List <Point>(); List <Point> matchPoint2L = new List <Point>(); foreach (DMatch match in lowPassFilterMatches) { matchPoint1L.Add(keypoints.toArray()[match.queryIdx].pt); matchPoint2L.Add(MapKeyPoints.toArray()[match.trainIdx].pt); } if (matchPoint1L.Count > 0) { ARTransform ARtorans = _lMedS.findARTransform(matchPoint2L.ToArray(), matchPoint1L.ToArray()); Debug.Log(string.Format("matchPoint1L.Count = {0} ,ARtorans.Error = {1}", matchPoint1L.Count, ARtorans.Error)); if (ARtorans.Error < filter) { Vector2 TTheta = new Vector2(HorizontalAngle * ARtorans.Tx / Width, VerticalAngle * ARtorans.Ty / Height); Matrix2x2 R = new Matrix2x2((float)Math.Cos(-(double)ARtorans.Radian), -(float)Math.Sin(-(double)ARtorans.Radian), (float)Math.Sin(-(double)ARtorans.Radian), (float)Math.Cos(-(double)ARtorans.Radian)); Vector2 TRTheta = R * TTheta; Debug.Log(R + " * " + TTheta + " = " + TRTheta); float LthetaX = TRTheta.x, LthetaY = TRTheta.y; CameraObject.transform.localRotation = Quaternion.Euler(-LthetaY, -LthetaX, ARtorans.Radian.Degree()); Debug.Log(ARtorans); } } }