private void loadObjects() { RegistryKey keyObjects = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Blik\\Objects"); if (keyObjects != null) { int counter = 1; RegistryKey keyObject = keyObjects.OpenSubKey("Object1"); while (keyObject != null) { int x = Convert.ToInt32(keyObject.GetValue("x")); int y = Convert.ToInt32(keyObject.GetValue("y")); int width = Convert.ToInt32(keyObject.GetValue("width")); int height = Convert.ToInt32(keyObject.GetValue("height")); DetectionObject newObject = new DetectionObject(x, y, width, height); detectionSystem.DetectionObjects.Add(newObject); keyObject = keyObjects.OpenSubKey("Object" + (++counter).ToString()); } } labelNumObjects.Text = detectionSystem.DetectionObjects.Count.ToString(); if (detectionSystem.DetectionObjects.Count > 0) { currentObject = detectionSystem.DetectionObjects.ElementAtOrDefault(currentObjectNumber - 1); DisplayObjectDetails(); } }
private DetectionObject AddObject(int x1, int y1, int x2, int y2) { DetectionObject newObject = new DetectionObject(x1, y1, x2 - x1, y2 - y1); detectionSystem.DetectionObjects.Add(newObject); return(newObject); }
private void buttonNext_Click(object sender, EventArgs e) { if (currentObjectNumber < detectionSystem.DetectionObjects.Count) { currentObjectNumber++; currentObject = detectionSystem.DetectionObjects.ElementAtOrDefault(currentObjectNumber - 1); DisplayObjectDetails(); } }
private void buttonPrevious_Click(object sender, EventArgs e) { if (currentObjectNumber > 1) { currentObjectNumber--; currentObject = detectionSystem.DetectionObjects.ElementAtOrDefault(currentObjectNumber - 1); DisplayObjectDetails(); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (detectionSystem.DetectionObjects.Count > 0) { detectionSystem.DetectionObjects.RemoveAt(currentObjectNumber - 1); if (currentObjectNumber > detectionSystem.DetectionObjects.Count) { currentObjectNumber--; currentObject = detectionSystem.DetectionObjects.ElementAtOrDefault(currentObjectNumber - 1); } labelNumObjects.Text = detectionSystem.DetectionObjects.Count.ToString(); DisplayObjectDetails(); } }
private void mouseUp() { mouseDown = false; if (isPicking) { currentObject = AddObject(Math.Min(mouseDownPoint.X, mousePoint.X), Math.Min(mouseDownPoint.Y, mousePoint.Y), Math.Max(mouseDownPoint.X, mousePoint.X), Math.Max(mouseDownPoint.Y, mousePoint.Y)); currentObjectNumber = detectionSystem.DetectionObjects.Count; labelNumObjects.Text = detectionSystem.DetectionObjects.Count.ToString(); isPicking = false; Cursor = Cursors.Default; DisplayObjectDetails(); } }
// value < 3000 means the same object. unsafe int secondLevelAnalysis(BitmapData bitmapData1, BitmapData bitmapData2, DetectionObject obj, int step, int bytesPerPixel) { int totalDifference = 0; try { byte *PtrFirstPixel1 = (byte *)bitmapData1.Scan0; byte *PtrFirstPixel2 = (byte *)bitmapData2.Scan0; if (step == 0) { step = 1; } int diff = 0; int y = obj.Rectangle.Top; while (y < obj.Rectangle.Bottom) { for (int x = obj.Rectangle.Left; x < obj.Rectangle.Right; x += step) { byte *currentLine = PtrFirstPixel1 + (y * bitmapData1.Stride); for (int color = 0; color < 3; color++) // for red, green and blue { int difference = 99999999; for (int adjustY = -1; adjustY < 2; adjustY++) { /* * if ((y + adjustY) < 0) * { * continue; // skip looking above on first line * } * if ((y + adjustY) > bitmap1.Height) * { * continue; // skip looking below on last line * }*/ byte *currentLineTrigger = PtrFirstPixel2 + ((y + adjustY) * bitmapData1.Stride); for (int adjustX = -1; adjustX < 2; adjustX++) { /* * if ((x + adjustX) < 0) * { * continue; // skip looking left on first pixel * } * if ((x + adjustX) > bitmap1.Width) * { * continue; // skip looking right on last pixel * }*/ diff = Math.Abs(adjustX) + Math.Abs(adjustY) + Math.Abs(currentLine[x * bytesPerPixel + color] - currentLineTrigger[(x + adjustX) * bytesPerPixel + color]); if (diff < difference) { difference = diff; } } } totalDifference += (difference * difference); } } y++; } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(totalDifference); }