public void ComputeMode1() { using (var model = BlockMeanHash.Create(BlockMeanHashMode.Mode1)) using (var img = Image("lenna.png")) using (var hash = new MatOfByte()) { model.Compute(img, hash); Assert.Equal(1, hash.Rows); Assert.Equal(121, hash.Cols); Assert.Equal(MatType.CV_8UC1, hash.Type()); var hashArray = hash.ToArray(); Assert.Equal( new byte[] { 135, 255, 243, 135, 131, 255, 249, 199, 193, 255, 252, 227, 224, 127, 254, 113, 128, 127, 127, 48, 192, 191, 25, 24, 240, 255, 4, 13, 248, 127, 135, 134, 252, 255, 99, 67, 254, 255, 184, 113, 255, 127, 220, 240, 195, 31, 111, 120, 224, 135, 55, 12, 248, 192, 27, 6, 126, 240, 13, 128, 63, 248, 6, 64, 14, 126, 3, 48, 7, 191, 3, 248, 131, 159, 1, 248, 193, 207, 0, 252, 240, 103, 0, 126, 248, 59, 0, 63, 254, 29, 0, 15, 255, 14, 0, 135, 127, 6, 128, 131, 63, 3, 224, 103, 206, 0, 240, 247, 99, 0, 248, 255, 49, 0, 252, 255, 24, 0, 254, 49, 0 }, hashArray); } }
public Stream MatToStream(Mat m) { using (var vect = new MatOfByte()) { if (Imgcodecs.Imencode(".png", m, vect)) { var stream = new MemoryStream(vect.ToArray()); return(stream); } return(null); } }
static bool RefineMatchesWithHomography( KeyPoint[] queryKeypoints, KeyPoint[] trainKeypoints, float reprojectionThreshold, DMatch[] matches, Mat homography ) { int minNumberMatchesAllowed = 8; if (matches.Length < minNumberMatchesAllowed) { return(false); } List <Point2f> srcPointsList = new List <Point2f>(matches.Length); List <Point2f> dstPointsList = new List <Point2f>(matches.Length); for (int i = 0; i < matches.Length; i++) { srcPointsList.Add(trainKeypoints[matches[i].TrainIdx].Pt); dstPointsList.Add(queryKeypoints[matches[i].QueryIdx].Pt); } using (MatOfPoint2f srcPoints = MatOfPoint2f.FromArray(srcPointsList)) using (MatOfPoint2f dstPoints = MatOfPoint2f.FromArray(dstPointsList)) using (MatOfByte inliersMask = new MatOfByte()) { Cv2.FindHomography(srcPoints, dstPoints, HomographyMethods.Ransac, reprojectionThreshold, inliersMask).CopyTo(homography); if (homography.Rows != 3 || homography.Cols != 3) { return(false); } byte[] inliersMaskList = inliersMask.ToArray(); List <DMatch> inliers = new List <DMatch>(); for (int i = 0; i < inliersMaskList.Length; i++) { if (inliersMaskList[i] == 1) { inliers.Add(matches[i]); } } matches = inliers.ToArray(); } return(matches.Length > minNumberMatchesAllowed); }
public void ComputeMode0() { using (var model = BlockMeanHash.Create(BlockMeanHashMode.Mode0)) using (var img = Image("lenna.png")) using (var hash = new MatOfByte()) { model.Compute(img, hash); Assert.Equal(1, hash.Rows); Assert.Equal(32, hash.Cols); Assert.Equal(MatType.CV_8UC1, hash.Type()); var hashArray = hash.ToArray(); Assert.Equal( new byte[] { 243, 61, 243, 61, 195, 63, 226, 151, 226, 159, 250, 223, 50, 206, 18, 231, 130, 226, 130, 227, 130, 243, 130, 243, 2, 243, 2, 87, 2, 127, 2, 47 }, hashArray); } }
public void Compute() { using (var model = RadialVarianceHash.Create()) using (var img = Image("lenna.png")) using (var hash = new MatOfByte()) { model.Compute(img, hash); Assert.Equal(1, hash.Rows); Assert.Equal(40, hash.Cols); Assert.Equal(MatType.CV_8UC1, hash.Type()); var hashArray = hash.ToArray(); Assert.Equal( new byte[] { 142, 0, 209, 255, 100, 131, 131, 190, 107, 68, 192, 159, 136, 135, 131, 159, 129, 184, 140, 134, 145, 120, 162, 157, 136, 142, 139, 134, 149, 146, 134, 151, 137, 139, 148, 144, 140, 135, 144, 144 }, hashArray); } }
public void Compute() { using (var model = MarrHildrethHash.Create()) using (var img = Image("lenna.png")) using (var hash = new MatOfByte()) { model.Compute(img, hash); Assert.Equal(1, hash.Rows); Assert.Equal(72, hash.Cols); Assert.Equal(MatType.CV_8UC1, hash.Type()); var hashArray = hash.ToArray(); Assert.Equal( new byte[] { 208, 54, 63, 31, 143, 199, 227, 241, 192, 124, 126, 39, 3, 205, 192, 124, 126, 63, 228, 150, 199, 194, 242, 254, 208, 143, 201, 105, 118, 57, 5, 191, 3, 99, 177, 224, 15, 137, 153, 58, 5, 129, 63, 193, 216, 228, 112, 100, 129, 176, 248, 255, 110, 7, 230, 16, 193, 231, 207, 135, 0, 150, 120, 5, 191, 60, 18, 114, 119, 131, 150, 31 }, hashArray); } }
public void Compute() { using (var model = PHash.Create()) using (var img = Image("lenna.png")) using (var hash = new MatOfByte()) { model.Compute(img, hash); Assert.Equal(1, hash.Rows); Assert.Equal(8, hash.Cols); Assert.Equal(MatType.CV_8UC1, hash.Type()); var hashArray = hash.ToArray(); Assert.Equal(152, hashArray[0]); Assert.Equal(99, hashArray[1]); Assert.Equal(42, hashArray[2]); Assert.Equal(180, hashArray[3]); Assert.Equal(206, hashArray[4]); Assert.Equal(197, hashArray[5]); Assert.Equal(97, hashArray[6]); Assert.Equal(25, hashArray[7]); } }
public void Compute() { using (var model = AverageHash.Create()) using (var img = Image("lenna.png")) using (var hash = new MatOfByte()) { model.Compute(img, hash); Assert.Equal(1, hash.Rows); Assert.Equal(8, hash.Cols); Assert.Equal(MatType.CV_8UC1, hash.Type()); var hashArray = hash.ToArray(); Assert.Equal(101, hashArray[0]); Assert.Equal(121, hashArray[1]); Assert.Equal(185, hashArray[2]); Assert.Equal(149, hashArray[3]); Assert.Equal(205, hashArray[4]); Assert.Equal(209, hashArray[5]); Assert.Equal(213, hashArray[6]); Assert.Equal(112, hashArray[7]); } }
private void BeamDetection(string outputfilename, bool isup) {// beam Detection int BinarizeThreshold = 60; int BrightnessThreshold = 4; int nop = 7; double dz = 0; if (isup == true) { dz = -0.003; } else { dz = 0.003; } Camera camera = Camera.GetInstance(); MotorControler mc = MotorControler.GetInstance(parameterManager); Vector3 InitPoint = mc.GetPoint(); Vector3 p = new Vector3(); TracksManager tm = parameterManager.TracksManager; int mod = parameterManager.ModuleNo; int pl = parameterManager.PlateNo; Track myTrack = tm.GetTrack(tm.TrackingIndex); string[] sp = myTrack.IdString.Split('-'); //string datfileName = string.Format("{0}.dat", System.DateTime.Now.ToString("yyyyMMdd_HHmmss")); string datfileName = string.Format(@"c:\test\bpm\{0}\{1}-{2}-{3}-{4}-{5}.dat", mod, mod, pl, sp[0], sp[1], System.DateTime.Now.ToString("ddHHmmss")); BinaryWriter writer = new BinaryWriter(File.Open(datfileName, FileMode.Create)); byte[] bb = new byte[440 * 512 * nop]; string fileName = string.Format("{0}", outputfilename); StreamWriter twriter = File.CreateText(fileName); string stlog = ""; List <ImageTaking> LiIT = TakeSequentialImage(0.0, 0.0, dz, nop); Mat sum = Mat.Zeros(440, 512, MatType.CV_8UC1); for (int i = 0; i < LiIT.Count; i++) { Mat bin = (Mat)DogContrastBinalize(LiIT[i].img, 31, BinarizeThreshold); Cv2.Add(sum, bin, sum); //byte[] b = LiIT[i].img.ToBytes();//format is .png MatOfByte mob = new MatOfByte(LiIT[i].img); byte[] b = mob.ToArray(); b.CopyTo(bb, 440 * 512 * i); } mc.MovePointZ(InitPoint.Z); mc.Join(); Cv2.Threshold(sum, sum, BrightnessThreshold, 1, ThresholdType.Binary); //Cv2.FindContoursをつかうとAccessViolationExceptionになる(Release/Debug両方)ので、C-API風に書く using (CvMemStorage storage = new CvMemStorage()) { using (CvContourScanner scanner = new CvContourScanner(sum.ToIplImage(), storage, CvContour.SizeOf, ContourRetrieval.Tree, ContourChain.ApproxSimple)) { //string fileName = string.Format(@"c:\img\{0}.txt", // System.DateTime.Now.ToString("yyyyMMdd_HHmmss_fff")); foreach (CvSeq <CvPoint> c in scanner) { CvMoments mom = new CvMoments(c, false); if (c.ElemSize < 2) { continue; } if (mom.M00 == 0.0) { continue; } double mx = mom.M10 / mom.M00; double my = mom.M01 / mom.M00; stlog += string.Format("{0:F} {1:F}\n", mx, my); } } } twriter.Write(stlog); twriter.Close(); writer.Write(bb); writer.Flush(); writer.Close(); sum *= 255; sum.ImWrite(String.Format(@"c:\img\{0}_{1}_{2}.bmp", System.DateTime.Now.ToString("yyyyMMdd_HHmmss"), (int)(p.X * 1000), (int)(p.Y * 1000))); }//BeamDetection