コード例 #1
0
        KeyValuePair <BlobChunkHeader, byte[]> WriteChunksProcessObject(BlobObject obj)
        {
            byte[] data;

            var byte_order = UnderlyingStream.ByteOrder;

            if (obj.SystemGroupVersionInfo.ForceLittleEndian)
            {
                byte_order = Shell.EndianFormat.Little;
            }

            var sys_group = obj.SystemGroup;

            // #TODO_IMPLEMENT: support non-fixed length blobs like film streams
            using (var ms = new System.IO.MemoryStream(obj.CalculateFixedBinarySize(this.GameTarget)))
                using (var es = new IO.EndianStream(ms, byte_order, this, sys_group.GroupTag.Name, FileAccess.Write))
                {
                    es.StreamMode = FileAccess.Write;

                    obj.Serialize(es);

                    data = ms.ToArray();
                }

            var header = new BlobChunkHeader(sys_group.GroupTag, obj.Version, data.Length, obj.BlobFlags);

            return(new KeyValuePair <BlobChunkHeader, byte[]>(header, data));
        }
コード例 #2
0
    private void CheckSpheresColor()
    {
        BlobObject LeftBlob = null, RightBlob = null;

        if (leftArmObj != -1)
        {
            LeftBlob = Inventory[leftArmObj].Object;
        }
        if (RightArmObj != -1)
        {
            RightBlob = Inventory[RightArmObj].Object;
        }
        // LeftBlob = Inventory[leftArmObj].Object;
        // RightBlob = Inventory[RightArmObj].Object;



        if (LMBcurrent >= LMBMax && RMBcurrent >= RMBMax)
        {
            myActivatedColor = MyColorMath.MixUpColors(LeftBlob.MyColorName, RightBlob.MyColorName);
        }
        else if (LMBcurrent >= LMBMax && !(RMBcurrent >= RMBMax))
        {
            myActivatedColor = MyColorMath.MixUpColors(LeftBlob.MyColorName);
        }
        else if (!(LMBcurrent >= LMBMax) && RMBcurrent >= RMBMax)
        {
            myActivatedColor = MyColorMath.MixUpColors(RightBlob.MyColorName);
        }
        else
        {
            myActivatedColor = "null";
        }
    }
コード例 #3
0
    private void UseCurrentBubble(string Side)
    {
        switch (Side)
        {
        case "Left":

            ActivatedBlob = Inventory[leftArmObj].Object;
            Inventory[leftArmObj].Count--;
            if (Inventory[RightArmObj].Count < 1)
            {
                SwitchBubble2("Left");
            }



            break;

        case "Right":

            ActivatedBlob = Inventory[RightArmObj].Object;
            Inventory[RightArmObj].Count--;
            if (Inventory[RightArmObj].Count < 1)
            {
                SwitchBubble2("Right");
            }

            break;
        }
    }
コード例 #4
0
ファイル: BlobResult.cs プロジェクト: odins1970/Ogama
        public void FilterByEccentricity(double maxEccentricity)
        {
            BlobObject[] finalBlobs;

            int numFilteredBlobs = 0;

            for (int i = 0; i < numBlobs; i++)
            {
                if (detectedBlobs[i].Eccentricity < maxEccentricity)
                {
                    numFilteredBlobs++;
                }
            }

            finalBlobs = new BlobObject[numFilteredBlobs];

            int counter = 0;

            for (int i = 0; i < numBlobs; i++)
            {
                if (detectedBlobs[i].Eccentricity < maxEccentricity)
                {
                    finalBlobs[counter] = detectedBlobs[i];
                    counter++;
                }
                else
                {
                    detectedBlobs[i].Clear();
                }
            }

            detectedBlobs = finalBlobs;
            numBlobs      = numFilteredBlobs;
        }
コード例 #5
0
ファイル: BlobResult.cs プロジェクト: odins1970/Ogama
        /// <summary>
        /// This methods eliminates the blobs that are exterior, i.e. those blobs
        /// that have pixels on the edge of the image
        /// </summary>
        public void EliminateExteriorBlobs()
        {
            BlobObject[] finalBlobs;

            int numFilteredBlobs = 0;

            for (int i = 0; i < numBlobs; i++)
            {
                if (detectedBlobs[i].Exterior == 0)
                {
                    numFilteredBlobs++;
                }
            }

            finalBlobs = new BlobObject[numFilteredBlobs];

            int counter = 0;

            for (int i = 0; i < numBlobs; i++)
            {
                if (detectedBlobs[i].Exterior == 0)
                {
                    finalBlobs[counter] = detectedBlobs[i];
                    counter++;
                }
                else
                {
                    detectedBlobs[i].Clear();
                }
            }

            detectedBlobs = finalBlobs;
            numBlobs      = numFilteredBlobs;
        }
コード例 #6
0
ファイル: BlobResult.cs プロジェクト: odins1970/Ogama
        public void FilterByArea(int minArea, int maxArea)
        {
            BlobObject[] finalBlobs;

            int numFilteredBlobs = 0;

            for (int i = 0; i < numBlobs; i++)
            {
                if (detectedBlobs[i].Area > minArea && detectedBlobs[i].Area < maxArea)
                {
                    numFilteredBlobs++;
                }
            }

            finalBlobs = new BlobObject[numFilteredBlobs];

            int counter = 0;

            for (int i = 0; i < numBlobs; i++)
            {
                if (detectedBlobs[i].Area > minArea && detectedBlobs[i].Area < maxArea)
                {
                    finalBlobs[counter] = detectedBlobs[i];
                    counter++;
                }
                else
                {
                    detectedBlobs[i].Clear();
                }
            }

            detectedBlobs = finalBlobs;
            numBlobs      = numFilteredBlobs;
        }
コード例 #7
0
ファイル: BlobResult.cs プロジェクト: odins1970/Ogama
        private BlobObject[] GetBlobs(Image <Gray, byte> image,
                                      int threshold,
                                      IntPtr maskImage,
                                      bool borderColor,
                                      bool findMoments)
        {
            int count;

            IntPtr vector = BlobsInvoke.CvGetBlobs(image.Ptr, threshold, maskImage, borderColor, findMoments, out count);

            IntPtr[] blobsPtrs = new IntPtr[count];

            GCHandle handle = GCHandle.Alloc(blobsPtrs, GCHandleType.Pinned);

            Emgu.Util.Toolbox.memcpy(handle.AddrOfPinnedObject(), vector, count * Marshal.SizeOf(typeof(IntPtr)));
            handle.Free();

            BlobObject[] Blobs = new BlobObject[count];
            for (int i = 0; i < blobsPtrs.Length; i++)
            {
                Blobs[i] = new BlobObject(blobsPtrs[i]);
            }

            System.GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            return(Blobs);
        }
コード例 #8
0
        /// <summary>
        /// Calculate the rotation of an object from image
        /// </summary>
        /// <param name="colorBS"></param>
        /// <param name="currentBlob"></param>
        /// <param name="viBlobs"></param>
        /// <returns>angle degree</returns>
        public static float GetRotation(Image <Bgra, byte> colorBS, BlobObject currentBlob, List <BlobObject> viBlobs)
        {
            Image <Bgra, byte> observedImage = UtilitiesImage.CropImage(colorBS, currentBlob.Rect);
            //observedImage.Save("current.jpg");
            float degree = 360;

            if (viBlobs.Count == 0)
            {
                return(degree);
            }
            else
            {
                VectorOfKeyPoint keypoints1;
                VectorOfKeyPoint keypoints2;
                Matrix <float>   symMatches;
                foreach (BlobObject viblob in viBlobs)
                {
                    //viblob.Image.Save(viblob.Id + ".jpg");
                    bool isDetect = UtilitiesImage.MatchIsSame(viblob.Image, observedImage.Convert <Gray, byte>(), out keypoints1, out keypoints2, out symMatches);

                    if (isDetect)
                    {
                        degree = UtilitiesImage.GetRotationDiff(symMatches, keypoints1, keypoints2);
                    }
                }
                return(degree);
            }
        }
コード例 #9
0
		public void FilterByArea(int minArea, int maxArea)
		{
			BlobObject[] finalBlobs;

			int numFilteredBlobs = 0;

			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Area > minArea && detectedBlobs[i].Area < maxArea)
					numFilteredBlobs++;
			}

			finalBlobs = new BlobObject[numFilteredBlobs];

			int counter = 0;
			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Area > minArea && detectedBlobs[i].Area < maxArea)
				{
					finalBlobs[counter] = detectedBlobs[i];
					counter++;
				}
				else
				{
					detectedBlobs[i].Clear();
				}
				
				
			}

			detectedBlobs = finalBlobs;
			numBlobs = numFilteredBlobs;
		}
コード例 #10
0
        private static BlobObject CreateTestBlobObject()
        {
            var blogObject = new BlobObject();

            blogObject.SetHash();

            return(blogObject);
        }
コード例 #11
0
        public async Task <IActionResult> Post()
        {
            var blob = new BlobObject();

            blob.ReadFileStream(Request);

            var result = await _storage.Create(blob);

            return(Ok(result.SasUri));
        }
コード例 #12
0
        public async Task <Uri> Update(BlobObject obj)
        {
            var container = await GetContainerReference();

            var blob = container.GetBlockBlobReference(obj.Name);

            await blob.UploadFromStreamAsync(obj.Stream);

            var uri = blob.GenerateSas(container, SasPermissions.ReadList);

            return(uri);
        }
コード例 #13
0
        public async Task <IActionResult> Put(string id)
        {
            var blob = new BlobObject {
                Name = id
            };

            blob.ReadFileStream(Request, true);

            var result = await _storage.Update(blob);

            return(Ok(result));
        }
コード例 #14
0
        public async Task <BlobObject> Create(BlobObject obj)
        {
            var container = await GetContainerReference();

            var blob = container.GetBlockBlobReference(obj.Name);

            await blob.UploadFromStreamAsync(obj.Stream);

            obj.Uri    = blob.Uri;
            obj.SasUri = blob.GenerateSas(container, SasPermissions.All);

            return(obj);
        }
コード例 #15
0
ファイル: MazeSpawner.cs プロジェクト: Nabr1n/SomeUnityGame
    public BlobObject FindBlobByString(string Name)
    {
        BlobObject blob = null;

        for (int i = 0; i < Blobs.Length; i++)
        {
            if (Blobs[i].Name == Name)
            {
                blob = Blobs[i].Blob;
            }
        }
        return(blob);
    }
コード例 #16
0
        public BlobObject CreateBlogObject(string content)
        {
            var blogObject = new BlobObject
            {
                Content = content
            };

            blogObject.SetHash();

            BlobObjects.Add(blogObject);

            return(blogObject);
        }
コード例 #17
0
ファイル: BlobPickUp.cs プロジェクト: Nabr1n/SomeUnityGame
    public void OnInstantiate(string ColorCode)
    {
        ColorType = ColorCode;
        for (int i = 0; i < AllBlobList.Count; i++)
        {
            if (ColorType == AllBlobList[i].Code)
            {
                PickUpOBj = AllBlobList[i].BlobObject;
                break;
            }
        }

        myBooma.GetComponent <ColoredSphere>().UpdateMyColor(PickUpOBj.MyColor);
    }
コード例 #18
0
        public void Verify_EmptyBlobObject_HasCorrectedFileFormat()
        {
            const string expectedHash        = "BC9F3DE89F680D2185A9E0CD316C29B2406DB8EF";
            const string expectedFileContent = "blob 14\0initial Commit";

            var blogObject = new BlobObject()
            {
                Content = "initial Commit"
            };

            blogObject.SetHash();

            Assert.AreEqual(expectedFileContent, blogObject.GetFileContent());
            Assert.AreEqual(expectedHash, blogObject.Hash);
        }
コード例 #19
0
        public TreeObject CreateTreeObject(BlobObject blobObject)
        {
            var treeObject = new TreeObject
            {
                Permissions    = "100644",
                ObjectType     = "blob",
                ObjectFileName = ExampleFileName,
                BlobObject     = blobObject
            };

            treeObject.SetHash();

            TreeObjects.Add(treeObject);

            return(treeObject);
        }
コード例 #20
0
        public static void ReadFileStream(this BlobObject blob, HttpRequest request, bool isUpdate = false)
        {
            if (request.Form.Files.Count <= 0)
            {
                return;
            }
            if (blob.Stream != null)
            {
                return;
            }

            var file = request.Form.Files.FirstOrDefault();

            blob.Stream = file?.OpenReadStream();
            if (!isUpdate)
            {
                blob.Name = file?.FileName;
            }
        }
コード例 #21
0
    public void PickUP(BlobObject blobObject, int count)
    {
        bool Exist = false;

        for (int i = 0; i < Inventory.Count; i++)
        {
            if (Inventory[i].Object.MyColorName == blobObject.MyColorName)
            {
                Inventory[i].Count += count;
                Exist = true;
            }
        }
        if (!Exist)
        {
            Inventory.Add(new InventoryBubble(blobObject, count));
        }
        else if (leftArmObj == -1 && RightArmObj == -1)
        {
            for (int i = 0; i < Inventory.Count; i++)
            {
                if (Inventory[i].Object.MyColorName == blobObject.MyColorName)
                {
                    leftArmObj = i;
                    break;
                }
            }
        }
        else if (leftArmObj != -1 & RightArmObj == -1)
        {
            for (int i = 0; i < Inventory.Count; i++)
            {
                if (Inventory[i].Object.MyColorName == blobObject.MyColorName)
                {
                    RightArmObj = i;
                    break;
                }
            }
        }
        // else if(leftArmObj==-1&&RightArmObj!=-1){
        //     SwitchBubble2("Left");
        // }
        //Debug.Log("ITEMADDED!");
    }
コード例 #22
0
ファイル: BlobResult.cs プロジェクト: odins1970/Ogama
        public void FilterByDistance(GTPoint initialLocation, int N)
        {
            if (N > numBlobs)
            {
                return;
            }

            BlobObject[] finalBlobs = new BlobObject[N];

            double[] distances = new double[numBlobs];
            int[]    keys      = new int[numBlobs];
            //Matrix<double> distances = new Matrix<double>(numBlobs, 1);
            GTPoint center;

            for (int i = 0; i < numBlobs; i++)
            {
                center       = new GTPoint(detectedBlobs[i].CentroidX, detectedBlobs[i].CentroidY);
                distances[i] = Operations.Distance(center, new GTPoint(initialLocation));
                keys[i]      = i;
            }

            Array.Sort(distances, keys);

            for (int i = 0; i < numBlobs; i++)
            {
                if (i < N)
                {
                    finalBlobs[i] = detectedBlobs[keys[i]];
                }
                else
                {
                    detectedBlobs[keys[i]].Clear();
                }
            }

            detectedBlobs = finalBlobs;
            numBlobs      = N;
        }
コード例 #23
0
		public void DrawBlobs(Image<Bgr, byte> image,
				BlobObject[] blobs,
				bool fill,
				bool drawBoundingBox, Color BoundingBoxColor,
				bool drawConvexHull, Color ConvexHullColor,
				bool drawEllipse, Color EllipseColor,
				bool drawCentroid, Color CentroidColor,
				bool drawAngle, Color AngleColor)
		{
			Random r = new Random(0);
			foreach (var b in blobs)
			{
				if (fill)
					b.FillBlob(image.Ptr, new MCvScalar(r.Next(255), r.Next(255), r.Next(255), r.Next(255)));
				if (drawBoundingBox)
					image.Draw(b.BoundingBox, new Bgr(BoundingBoxColor), 1);
				if (drawConvexHull)
					image.DrawPolyline(b.ConvexHull, true, new Bgr(ConvexHullColor), 1);
				if (drawEllipse)
					image.Draw(b.BestFitEllipse, new Bgr(EllipseColor), 1);

				if (drawCentroid)
				{
					image.Draw(new LineSegment2D(new Point((int)b.CentroidX - 4, (int)b.CentroidY),
										   new Point((int)b.CentroidX + 4, (int)b.CentroidY)),
						 new Bgr(CentroidColor), 1);
					image.Draw(new LineSegment2D(new Point((int)b.CentroidX, (int)b.CentroidY - 4),
										   new Point((int)b.CentroidX, (int)b.CentroidY + 4)),
						 new Bgr(CentroidColor), 1);
				}
				if (drawAngle)
				{
					double x1, x2, y1, y2;
					x1 = b.CentroidX - 0.005 * b.Area * Math.Cos(b.Angle);
					y1 = b.CentroidY - 0.005 * b.Area * Math.Sin(b.Angle);
					x2 = b.CentroidX + 0.005 * b.Area * Math.Cos(b.Angle);
					y2 = b.CentroidY + 0.005 * b.Area * Math.Sin(b.Angle);
					image.Draw(new LineSegment2D(new Point((int)x1, (int)y1),
									new Point((int)x2, (int)y2)),
						 new Bgr(AngleColor), 1);
				}
			}
		}
コード例 #24
0
		private BlobObject[] GetBlobs(Image<Gray, byte> image,
						int threshold,
					   IntPtr maskImage,
					   bool borderColor,
					   bool findMoments)
		{
			int count;

			IntPtr vector = BlobsInvoke.CvGetBlobs(image.Ptr, threshold, maskImage, borderColor, findMoments, out count);
			IntPtr[] blobsPtrs = new IntPtr[count];

			GCHandle handle = GCHandle.Alloc(blobsPtrs, GCHandleType.Pinned);
			Emgu.Util.Toolbox.memcpy(handle.AddrOfPinnedObject(), vector, count * Marshal.SizeOf(typeof(IntPtr)));
			handle.Free();

			BlobObject[] Blobs = new BlobObject[count];
			for (int i = 0; i < blobsPtrs.Length; i++)
				Blobs[i] = new BlobObject(blobsPtrs[i]);

            System.GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

			return Blobs;
		}
コード例 #25
0
		public void FilterByEccentricity(double maxEccentricity)
		{
			BlobObject[] finalBlobs;

			int numFilteredBlobs = 0;

			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Eccentricity < maxEccentricity)
					numFilteredBlobs++;
			}

			finalBlobs = new BlobObject[numFilteredBlobs];

			int counter = 0;
			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Eccentricity < maxEccentricity)
				{
					finalBlobs[counter] = detectedBlobs[i];
					counter++;
				}
				else
					detectedBlobs[i].Clear();
			}

			detectedBlobs = finalBlobs;
			numBlobs = numFilteredBlobs;
		}
コード例 #26
0
		public void FilterByDistance(GTPoint initialLocation, int N)
		{
			if(N > numBlobs)
				return;

			BlobObject[] finalBlobs = new BlobObject[N];

			double[] distances = new double[numBlobs];
			int[] keys = new int[numBlobs];
			//Matrix<double> distances = new Matrix<double>(numBlobs, 1);
			GTPoint center;

			for (int i = 0; i < numBlobs; i++)
			{
				center = new GTPoint(detectedBlobs[i].CentroidX, detectedBlobs[i].CentroidY);
				distances[i] = Operations.Distance(center, new GTPoint(initialLocation));
				keys[i] = i;
			}

			Array.Sort(distances, keys);

			for (int i = 0; i < numBlobs; i++)
			{
				if (i < N)
					finalBlobs[i] = detectedBlobs[keys[i]];
				else
					detectedBlobs[keys[i]].Clear();
			}

			detectedBlobs = finalBlobs;
			numBlobs = N;

	
		}
コード例 #27
0
		/// <summary>
		/// This methods eliminates the blobs that are exterior, i.e. those blobs
		/// that have pixels on the edge of the image
		/// </summary>
		public void EliminateExteriorBlobs()
		{
			BlobObject[] finalBlobs;

			int numFilteredBlobs = 0;

			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Exterior == 0)
					numFilteredBlobs++;
			}

			finalBlobs = new BlobObject[numFilteredBlobs];

			int counter = 0;
			for (int i = 0; i < numBlobs; i++)
			{
				if (detectedBlobs[i].Exterior == 0) 
				{
					finalBlobs[counter] = detectedBlobs[i];
					counter++;
				}
				else
				{
					detectedBlobs[i].Clear();
				}


			}

			detectedBlobs = finalBlobs;
			numBlobs = numFilteredBlobs;
		}
コード例 #28
0
        private async void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                if (!System.String.IsNullOrEmpty(lblFileName.Text))
                {
                    string CS = ConfigurationManager.ConnectionStrings["AzureConnection"].ConnectionString;
                    // container name should be lower case
                    string box = "order" + OrderId.ToString();



                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CS);
                    CloudBlobClient     client         = storageAccount.CreateCloudBlobClient();

                    //CloudBlobContainer container = client.GetContainerReference("blinds"); //table+primarykey
                    CloudBlobContainer container = client.GetContainerReference(box); //table+primarykey

                    //container.CreateIfNotExists();
                    bool x = await container.CreateIfNotExistsAsync();

                    //await container.CreateIfNotExistsAsync();

                    CloudBlockBlob blob = container.GetBlockBlobReference(FileName);
                    using (System.IO.FileStream stream = new System.IO.FileStream(ImageLocation, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        // blob.UploadFromStream(stream);
                        await blob.UploadFromStreamAsync(stream);
                    };

                    List <BlobObject> BlobList = new List <BlobObject>();

                    foreach (CloudBlob blobItem in container.ListBlobs())
                    // foreach (CloudBlob blobItem in container.ListBlobs())
                    {
                        BlobObject _object = new BlobObject();
                        //_object.BlobContainerName = blobItem.Container.Name;
                        // _object.StorageUri = blobItem.StorageUri.PrimaryUri.ToString();
                        //_object.PrimaryUri = blobItem.StorageUri.PrimaryUri.ToString();
                        string _name = blobItem.Uri.AbsoluteUri.Substring(blobItem.Uri.AbsoluteUri.LastIndexOf("/") + 1);
                        _object.ActualFileName = _name.Replace("%20", " ");
                        //_object.FileExtension = System.IO.Path.GetExtension(blobItem.Uri.AbsoluteUri.Substring(blobItem.Uri.AbsoluteUri.LastIndexOf("/") + 1));
                        BlobList.Add(_object);
                    }

                    grdViewBlobList.DataSource = BlobList;
                    lblFileName.Text           = string.Empty;

                    //DataGridViewLinkColumn linkColumnDelete = new DataGridViewLinkColumn();
                    //linkColumnDelete.Name = "Delete";
                    //linkColumnDelete.HeaderText = "Delete";
                    //linkColumnDelete.Text = "Delete";
                    //linkColumnDelete.UseColumnTextForLinkValue = true;
                    //grdViewBlobList.Columns.Insert(1, linkColumnDelete);

                    //DataGridViewLinkColumn linkColumnDownload = new DataGridViewLinkColumn();
                    //linkColumnDownload.Name = "Download";
                    //linkColumnDownload.HeaderText = "Download";
                    //linkColumnDownload.Text = "Download";
                    //linkColumnDownload.UseColumnTextForLinkValue = true;
                    //grdViewBlobList.Columns.Insert(2, linkColumnDownload);



                    //List<string> blobs = new List<string>();
                    //foreach (CloudBlockBlob blobItem in container.ListBlobs())
                    //{
                    //    blobs.Add(blobItem.Container.Name);
                    //}

                    //grdViewBlobList.DataSource = blobs.ToList();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #29
0
        private void FIleUploadBlobForm_Load(object sender, EventArgs e)
        {
            try
            {
                string CS  = ConfigurationManager.ConnectionStrings["AzureConnection"].ConnectionString;
                string box = "order" + OrderId.ToString();


                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CS);
                CloudBlobClient     client         = storageAccount.CreateCloudBlobClient();

                //CloudBlobContainer container = client.GetContainerReference("blinds"); //table+primarykey
                CloudBlobContainer container = client.GetContainerReference(box); //table+primarykey

                //if (container.Exists())
                //{
                List <BlobObject> BlobList = new List <BlobObject>();
                if (container.Exists())
                {
                    foreach (CloudBlob blobItem in container.ListBlobs())
                    // foreach (CloudBlob blobItem in container.ListBlobs())
                    {
                        BlobObject _object = new BlobObject();
                        //_object.BlobContainerName = blobItem.Container.Name;
                        // _object.StorageUri = blobItem.StorageUri.PrimaryUri.ToString();
                        //_object.PrimaryUri = blobItem.StorageUri.PrimaryUri.ToString();
                        string _name = blobItem.Uri.AbsoluteUri.Substring(blobItem.Uri.AbsoluteUri.LastIndexOf("/") + 1);
                        _object.ActualFileName = _name.Replace("%20", " ");
                        //_object.FileExtension = System.IO.Path.GetExtension(blobItem.Uri.AbsoluteUri.Substring(blobItem.Uri.AbsoluteUri.LastIndexOf("/") + 1));
                        BlobList.Add(_object);
                    }
                }
                //if (BlobList.Count > 0)
                //{
                //    Marker += 1;
                //}

                grdViewBlobList.DataSource = BlobList;



                DataGridViewLinkColumn linkColumnDelete = new DataGridViewLinkColumn();
                linkColumnDelete.Name       = "Delete";
                linkColumnDelete.HeaderText = "Delete";
                linkColumnDelete.Text       = "Delete";
                linkColumnDelete.UseColumnTextForLinkValue = true;
                grdViewBlobList.Columns.Insert(1, linkColumnDelete);

                DataGridViewLinkColumn linkColumnDownload = new DataGridViewLinkColumn();
                linkColumnDownload.Name       = "Download";
                linkColumnDownload.HeaderText = "Download";
                linkColumnDownload.Text       = "Download";
                linkColumnDownload.UseColumnTextForLinkValue = true;
                grdViewBlobList.Columns.Insert(2, linkColumnDownload);

                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #30
0
        /// <summary>
        /// Find an object in a object list
        /// </summary>
        /// <param name="currentBlob"></param>
        /// <param name="viBlobs"></param>
        /// <returns>BlobID</returns>
        public static string RecognizeObject(BlobObject currentBlob, List <TrackableObject> dbObjects)
        {
            bool   isDetect = false;
            string blobId   = "not identified";

            bool careAboutWorkflow = false;

            if (WorkflowManager.Instance.LoadedWorkflow != null)
            {
                careAboutWorkflow = true;
            }

            if (dbObjects.Count != 0)
            {
                foreach (TrackableObject obj in dbObjects)
                {
                    if (careAboutWorkflow)
                    {
                        // first check if object belongs to current workingstep
                        if (obj.Category == "" + WorkflowManager.Instance.CurrentWorkingStep.StepNumber)
                        {
                            // MFunk: Run this a couple of times to get more robust
                            int numRuns = 3;

                            for (int i = 0; i < numRuns; i++)
                            {
                                isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage, currentBlob.Image);

                                if (isDetect)
                                {
                                    break;
                                }
                            }

                            if (isDetect)
                            {
                                WorkflowManager.Instance.OnObjectRecognized(obj);
                                blobId = obj.Name;
                                break;
                            }
                            else
                            {
                                isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage.Canny(10, 50).Convert <Gray, Int32>(), currentBlob.Image.Canny(10, 50).Convert <Gray, Int32>());
                                if (isDetect)
                                {
                                    isDetect = true;
                                    blobId   = obj.Name;
                                    WorkflowManager.Instance.OnObjectRecognized(obj);
                                    break;
                                }
                                else
                                {
                                    blobId = "not identified";
                                }
                            }

                            if (isDetect)
                            {
                                m_LastWasCorrupted = false;
                            }
                        }
                    }
                    else
                    {
                        // do not care about workflow

                        // MFunk: Run this a couple of times to get more robust
                        int numRuns = 3;

                        for (int i = 0; i < numRuns; i++)
                        {
                            isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage, currentBlob.Image);

                            if (isDetect)
                            {
                                break;
                            }
                        }

                        if (isDetect)
                        {
                            WorkflowManager.Instance.OnObjectRecognized(obj);
                            blobId = obj.Name;
                            break;
                        }
                        else
                        {
                            isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage.Canny(10, 50).Convert <Gray, Int32>(), currentBlob.Image.Canny(10, 50).Convert <Gray, Int32>());
                            if (isDetect)
                            {
                                isDetect = true;
                                blobId   = obj.Name;
                                WorkflowManager.Instance.OnObjectRecognized(obj);
                                break;
                            }
                            else
                            {
                                blobId = "not identified";
                            }
                        }
                    }
                }
            }

            if (isDetect)
            {
                m_LastWasCorrupted = false;
            }
            return(blobId);
        }
コード例 #31
0
		public Image<Bgr, byte> DrawBlobs(Image<Bgr, byte> image, BlobObject[] blobs)
		{
			Image<Bgr, byte> imageFinal;
			imageFinal = image.Copy();

			foreach (var b in blobs)
			{
				imageFinal.Draw(new LineSegment2D(new Point((int)b.CentroidX - 4, (int)b.CentroidY),
									   new Point((int)b.CentroidX + 4, (int)b.CentroidY)),
					 new Bgr(Color.Red), 1);
				imageFinal.Draw(new LineSegment2D(new Point((int)b.CentroidX, (int)b.CentroidY - 4),
									   new Point((int)b.CentroidX, (int)b.CentroidY + 4)),
					 new Bgr(Color.Red), 1);

			}

			return imageFinal;

		}
コード例 #32
0
 public InventoryBubble(BlobObject obj, int count)
 {
     Object = obj;
     Count  = count;
 }
コード例 #33
0
 private void Start()
 {
     leftArmObj    = -1;
     RightArmObj   = -1;
     ActivatedBlob = null;
 }
コード例 #34
0
 public void OneTimeSetUp()
 {
     EmptyBlobObject = CreateTestBlobObject();
 }
コード例 #35
0
ファイル: VideoPanel.xaml.cs プロジェクト: koppor/motionEAP
        public void ProcessBoxProjection(Image <Bgra, byte> pColorBitSource)
        {
            if (SettingsManager.Instance.Settings.CheckBoxStartProjection == false)
            {
                return;
            }

            Image <Gray, Int32> depthImg = KinectManager.Instance.GetCurrentDepthImageCropped();

            int[,] map = new int[SettingsManager.Instance.Settings.IntegerUpDownXBox, SettingsManager.Instance.Settings.IntegerUpDownYBox];
            BlobManager.Instance.MasterBlob = BlobManager.FindAllBlob(
                depthImg,
                BlobManager.Instance.MasterBlob,
                pColorBitSource,
                SettingsManager.Instance.Settings.BlobRadio);
            Image <Bgra, byte> outputImage = depthImg.Convert <Bgra, byte>();
            Tuple <RectangleF, System.Windows.Media.Color>             outputFree     = new Tuple <RectangleF, System.Windows.Media.Color>(new RectangleF(), new System.Windows.Media.Color());
            List <Tuple <PointF[], System.Windows.Media.Color> >       outputBoxPoint = new List <Tuple <PointF[], System.Windows.Media.Color> >();
            List <Tuple <PointF, String, System.Windows.Media.Color> > outputString   = new List <Tuple <PointF, String, System.Windows.Media.Color> >();

            Bgra color = new Bgra(0, 255, 0, 0);

            if (BlobManager.Instance.MasterBlob != null)
            {
                for (int i = 0; i < BlobManager.Instance.MasterBlob.Count; i++)
                {
                    BlobObject currentBlob = BlobManager.Instance.MasterBlob[i];
                    //currentBlob.Id == 0;

                    if (m_Free_Checked)
                    {
                        map = FreeSpaceManager.RenderObject(currentBlob.CornerPoints, map, depthImg.Width, depthImg.Height);
                    }

                    // map_check fliegt raus
                    if (m_Map_Checked)
                    {
                        if (BlobManager.Instance.MasterBlob[i].Hits == 0)
                        {
                            int count;
                            count = UtilitiesImage.FeaturePerObject(pColorBitSource, BlobManager.Instance.MasterBlob[i].Rect);

                            BlobManager.Instance.MasterBlob[i].Hits = count;
                        }
                        color = UtilitiesImage.MappingColor(BlobManager.Instance.MasterBlob[i].Hits);
                    }

                    if (m_Tracking_Checked)
                    {
                        System.Drawing.Point center = new System.Drawing.Point((int)(currentBlob.Center.X * depthImg.Width), (int)(currentBlob.Center.Y * depthImg.Height));
                        //outputImage.Draw(currentBlob.Name.ToString(), ref m_Font, center, new Bgr(System.Drawing.Color.Red));
                        outputString.Add(new Tuple <PointF, String, System.Windows.Media.Color>(currentBlob.Center, currentBlob.Name.ToString(), System.Windows.Media.Color.FromRgb(0, 255, 0)));
                    }

                    List <LineSegment2DF> depthboxLines = UtilitiesImage.PointsToImageLine(currentBlob.CornerPoints, depthImg.Width, depthImg.Height);
                    foreach (LineSegment2DF line in depthboxLines)
                    {
                        outputImage.Draw(line, color, 2);
                    }

                    PointF[] corner = new PointF[4];
                    for (int cur = 0; cur < 4; cur++)
                    {
                        corner[cur] = new PointF(BlobManager.Instance.MasterBlob[i].CornerPoints[cur].X, 1 - BlobManager.Instance.MasterBlob[i].CornerPoints[cur].Y);
                    }

                    outputBoxPoint.Add(new Tuple <PointF[], System.Windows.Media.Color>(corner, System.Windows.Media.Color.FromRgb((byte)color.Red, (byte)color.Green, (byte)color.Blue)));
                }
            }

            // update the reference
            ObjectDetectionManager.Instance.MasterBlob = BlobManager.Instance.MasterBlob;

            RectangleF freeSpace = new RectangleF();

            if (m_Free_Checked)
            {
                depthImg  = FreeSpaceManager.DrawMaxSubmatrix(depthImg.Convert <Bgra, byte>(), map).Convert <Gray, Int32>();
                freeSpace = FreeSpaceManager.DrawMaxSubmatrix(map, (float)(depthImg.Width / (float)SettingsManager.Instance.Settings.IntegerUpDownXBox / depthImg.Width),
                                                              (float)(depthImg.Height / (float)SettingsManager.Instance.Settings.IntegerUpDownYBox / depthImg.Height));
            }

            //draw on table
            # region projection
            if (SettingsManager.Instance.Settings.CheckBoxStartProjection)
コード例 #36
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="openCVImg"></param>
        /// <param name="masterBlobs"></param>
        /// <param name="colorBS"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static List <BlobObject> FindAllBlob(Image <Gray, Int32> openCVImg,
                                                    List <BlobObject> masterBlobs,
                                                    Image <Bgra, byte> colorBS,
                                                    bool mode)
        {
            List <BlobObject> retList = new List <BlobObject>();

            try
            {
                Image <Gray, byte> gray_image = openCVImg.Convert <Gray, byte>();
                List <BlobObject>  newBlobs   = new List <BlobObject>();
                if (mode == false)
                {
                    #region using cvBlob
                    Emgu.CV.Cvb.CvBlobs        resultingBlobs = new Emgu.CV.Cvb.CvBlobs();
                    Emgu.CV.Cvb.CvBlobDetector bDetect        = new Emgu.CV.Cvb.CvBlobDetector();
                    uint numWebcamBlobsFound = bDetect.Detect(gray_image, resultingBlobs);

                    using (MemStorage stor = new MemStorage())
                    {
                        foreach (Emgu.CV.Cvb.CvBlob targetBlob in resultingBlobs.Values)
                        {
                            if (targetBlob.Area > 200)
                            {
                                var contour = targetBlob.GetContour(stor);

                                MCvBox2D box = contour.GetMinAreaRect();

                                PointF[] boxCorner = UtilitiesImage.ToPercent(contour.GetMinAreaRect().GetVertices(), gray_image.Width, gray_image.Height);

                                PointF center = UtilitiesImage.ToPercent(contour.GetMinAreaRect().center, gray_image.Width, gray_image.Height);

                                RectangleF rect = UtilitiesImage.ToPercent(targetBlob.BoundingBox, gray_image.Width, gray_image.Height);

                                Image <Gray, byte> newCropImg = UtilitiesImage.CropImage(colorBS.Convert <Gray, byte>(), rect);
                                newBlobs.Add(new BlobObject(newCropImg, null, boxCorner, rect, center, 0, 0, 0 + ""));
                                //stor.Clear();
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region using contour
                    using (MemStorage storage = new MemStorage())
                    {
                        //Find contours with no holes try CV_RETR_EXTERNAL to find holes
                        Contour <System.Drawing.Point> contours = gray_image.FindContours(
                            Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
                            Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
                            storage);

                        for (int i = 0; contours != null; contours = contours.HNext)
                        {
                            i++;

                            //double area = contours.Area;
                            if (contours.Area > 200)
                            {
                                PointF[]           boxCorner  = UtilitiesImage.ToPercent(contours.GetMinAreaRect().GetVertices(), gray_image.Width, gray_image.Height);
                                PointF             center     = UtilitiesImage.ToPercent(contours.GetMinAreaRect().center, gray_image.Width, gray_image.Height);
                                RectangleF         rect       = UtilitiesImage.ToPercent(contours.BoundingRectangle, gray_image.Width, gray_image.Height);
                                Image <Bgra, byte> newCropImg = UtilitiesImage.CropImage(colorBS, rect);
                                newBlobs.Add(new BlobObject(newCropImg.Convert <Gray, byte>(), null, boxCorner, rect, center, 0, 0, 0 + ""));
                            }
                        }
                    }
                    #endregion
                }

                // read objects from database now
                List <TrackableObject> objects = DatabaseManager.Instance.Objects.ToList();

                if (objects.Count == 0)
                {
                    foreach (BlobObject b in newBlobs)
                    {
                        retList.Add(new BlobObject(b.Image, null, b.CornerPoints, b.Rect, b.Center, 0, 0, 0 + ""));
                    }
                }
                else
                {
                    #region

                    // size and position werden abgeglichen
                    List <Tuple <double, double, int, int> > trackInfo = new List <Tuple <double, double, int, int> >();
                    for (int newblob = 0; newblob < newBlobs.Count; newblob++)
                    {
                        for (int master = 0; master < masterBlobs.Count; master++)
                        {
                            double d = UtilitiesImage.Distance(newBlobs[newblob].Center, masterBlobs[master].Center);
                            double s = UtilitiesImage.DiffSize(newBlobs[newblob].Rect.Size, masterBlobs[master].Rect.Size);
                            trackInfo.Add(new Tuple <double, double, int, int>(d, s, master, newblob));
                        }
                    }


                    trackInfo.Sort((x, y) => x.Item1.CompareTo(y.Item1));
                    List <int> newItem = new List <int>();

                    if (!m_LastWasCorrupted)
                    {
                        while (trackInfo.Count != 0)
                        {
                            if (trackInfo[0].Item2 < 0.2)
                            {
                                int        masterId  = trackInfo[0].Item3;
                                int        newId     = trackInfo[0].Item4;
                                BlobObject newObject = new BlobObject(newBlobs[newId].Image, newBlobs[newId].DepthStructur, newBlobs[newId].CornerPoints, newBlobs[newId].Rect, newBlobs[newId].Center, masterBlobs[masterId].Hits, masterBlobs[masterId].Id, masterBlobs[masterId].Name);
                                retList.Add(newObject);
                                trackInfo.RemoveAll(item => item.Item3 == masterId);
                                trackInfo.RemoveAll(item => item.Item4 == newId);
                                newItem.Add(newId);
                            }
                            else
                            {
                                trackInfo.RemoveAt(0);
                            }
                        }
                        newItem.Sort();
                        //}


                        // check the images based on their features
                        for (int i = newBlobs.Count - 1; i >= 0; i--)
                        {
                            if (newItem.Count != 0 && i == newItem.Last())
                            {
                                newItem.RemoveAt(newItem.Count - 1);
                            }
                            else
                            {
                                // set the name according to the recognized object
                                string currentBlobId = RecognizeObject(newBlobs[i], objects);
                                newBlobs[i].Name = currentBlobId;
                                retList.Add(newBlobs[i]);
                            }
                        }
                    }
                }
            }
            catch (CvException e)
            {
                Logger.Instance.Log(e.Message, Logger.LoggerState.ERROR);
                return(retList);
            }
            catch (Exception e)
            {
                Logger.Instance.Log(e.Message, Logger.LoggerState.ERROR);
                //mark a flag that the last frame was corrupt
                m_LastWasCorrupted = true;
            }
            #endregion

            return(retList);
        }
コード例 #37
0
        private void grdViewBlobList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    string CS = ConfigurationManager.ConnectionStrings["AzureConnection"].ConnectionString;

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CS);
                    CloudBlobClient     client         = storageAccount.CreateCloudBlobClient();
                    string             box             = "order" + OrderId.ToString();
                    CloudBlobContainer container       = client.GetContainerReference(box);


                    DataGridViewRow row = grdViewBlobList.Rows[e.RowIndex];

                    if (grdViewBlobList.Columns[e.ColumnIndex].Name == "Download")
                    {
                        //FileId = System.Convert.ToInt32(row.Cells["FileId"].Value.ToString());
                        // Download(FileId);
                        using (SaveFileDialog saveFile = new SaveFileDialog())
                        {
                            saveFile.FileName = row.Cells["ActualFileName"].Value.ToString();
                            CloudBlockBlob blob = container.GetBlockBlobReference(row.Cells["ActualFileName"].Value.ToString());


                            string extension = System.IO.Path.GetExtension(row.Cells["ActualFileName"].Value.ToString());
                            string subString = extension.Substring(1);

                            string filter  = "var files(*.var)|*.var";
                            string replace = filter.Replace("var", subString);


                            saveFile.Filter = replace;

                            if (DialogResult.OK != saveFile.ShowDialog())
                            {
                                return;
                            }
                            using (FileStream fs = (FileStream)saveFile.OpenFile())
                            {
                                blob.DownloadToStream(fs);
                            }
                            //System.IO.FileStream stream = new System.IO.FileStream(row.Cells["StorageUri"].Value.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read);


                            //blob.DownloadToFileAsync(System.IO.Path.GetDirectoryName(saveFile.FileName), FileMode.Create);
                        }
                    }
                    else if (grdViewBlobList.Columns[e.ColumnIndex].Name == "Delete")
                    {
                        if (MessageBox.Show("Are you sure do you want to delete this file?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            string         name      = row.Cells["ActualFileName"].Value.ToString();
                            string         fileName  = name.Replace("%20", " ");
                            CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
                            blockBlob.DeleteIfExists();

                            List <BlobObject> BlobList = new List <BlobObject>();


                            foreach (CloudBlob blobItem in container.ListBlobs())
                            {
                                BlobObject _object = new BlobObject();

                                string _name = blobItem.Uri.AbsoluteUri.Substring(blobItem.Uri.AbsoluteUri.LastIndexOf("/") + 1);

                                _object.ActualFileName = _name.Replace("%20", " ");

                                //_object.ActualFileName = blobItem.Uri.AbsoluteUri.Substring(blobItem.Uri.AbsoluteUri.LastIndexOf("/") + 1); //%20

                                BlobList.Add(_object);
                            }

                            grdViewBlobList.DataSource = BlobList;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }