private async void TestButton_Click(object sender, EventArgs e) { // Create source. object O = Resources.ResourceManager.GetObject("OnGuard"); //Return an object from the image chan1.png in the project using (Bitmap bm = (Bitmap)O) { using (MemoryStream mem = new MemoryStream()) { bm.Save(mem, ImageFormat.Jpeg); mem.Position = 0; try { AIAnalyzer ai = new AIAnalyzer(ipAddresText.Text, (int)portNumeric.Value); List <ImageObject> imageObjects = await ai.ProcessVideoImageViaAI(mem, "Test Image").ConfigureAwait(false); if (imageObjects != null && imageObjects.Count > 0) { MessageBox.Show(this, "Successfully processed a picture via DeepStack", "Success!"); } else { MessageBox.Show(this, "The AI Test FAILED!. DeepStack was found, but the image was not processed successfully. Check your DeepStack startup to make sure --VISION-DETECTION True is set!", "Test Failure!"); } } catch (AiNotFoundException ex) { MessageBox.Show(this, "The AI Test FAILED!. Check the IP Address and port. Make sure DeepStack is running.", "Test Failed!"); } } } }
void RemoveUnmovedVehicles(CameraData camera, List <ImageObject> objectList) { Dbg.Trace("Object count before removing parked: " + objectList.Count.ToString()); List <ImageObject> vehicles = new List <ImageObject>(); int nonVehicleObjects = 0; if (objectList != null && objectList.Count > 0) { foreach (ImageObject obj in objectList) { if (IsVehicle(obj)) { if (obj.Confidence > minVehicleConfidence) { vehicles.Add(new ImageObject(obj)); } } else { ++nonVehicleObjects; } } Dbg.Trace("non-vehicle objects before parking check: " + nonVehicleObjects.ToString()); List <ImageObject> allFoundVehicles = new List <ImageObject>(vehicles); int i = 0; /*List<Frame> recentFrames = null; * if (vehicles.Count > 0) * { * recentFrames = camera.FrameHistory.GetFramesInTimespan(TimeSpan.FromSeconds(5), DateTime.Now, TimeDirection.Before); * }*/ while (i < vehicles.Count) { bool removedOne = false; lock (_previousVehicles) { for (int j = 0; j < _previousVehicles.Count; j++) { if (vehicles[i].Label == _previousVehicles[j].Label) // In this case we only remove objects that are the same - A = car, B = car (not 100%, but what can we do?) { int targetOverlap = ParkedOverlap; bool foundParked = false; int overlap = AIAnalyzer.GetOverlap(vehicles[i], _previousVehicles[j]); if (overlap >= targetOverlap) // Shadows, etc. do cause event parked vehicles to shift in outline { Dbg.Trace("Vehicle found parked using area overlap"); foundParked = true; } else { // Now we consider 2 points on both the parked and the subject vehicle. If they are close we consider it parked. // This is because people walking in front of a car may change the outlines. // This is far from perfect, but it is worth trying. // Note that this assumes only one edge of the vehicle is covered at a time, but for now is better than nothing. // If the vehicle is still moving the next frame should tell via the overlap test so that is not a concern // TODO: keep the parked vehicle locations in a db table? // TODO: Parked vehicles that are covered by people/animals at both corners (we know where people are) will not be // removed from the parked list? We probably don't care about vehicles covered by vehicles because the moving vehicles are // movement in themselves, unless we care specifically what kind of vehicles we are concerned with. Point pPreviousUL = new Point(_previousVehicles[j].ObjectRectangle.Left, _previousVehicles[j].ObjectRectangle.Top); Point pPreviousLR = new Point(_previousVehicles[j].ObjectRectangle.Right, _previousVehicles[j].ObjectRectangle.Bottom); Point pVehicleUL = new Point(vehicles[i].ObjectRectangle.Left, vehicles[i].ObjectRectangle.Top); Point pVehicleLR = new Point(vehicles[i].ObjectRectangle.Right, vehicles[i].ObjectRectangle.Bottom); double ulDistance = GetPointDistance(pPreviousUL, pVehicleUL); double lrDistance = GetPointDistance(pPreviousLR, pVehicleLR); double parkedSize = pVehicleLR.X - pVehicleUL.X; // the width in pixels of the parked vehicle, to get a rough idea of its size double targetSize = parkedTargetDistance * parkedSize; /*if (targetSize > parkedTargetMax) * { * targetSize = parkedTargetMax; // just a WAG pending test data * }*/ if (ulDistance < targetSize || lrDistance < targetSize) { Dbg.Trace("Parked Target Size: " + targetSize.ToString()); Dbg.Trace("Parked ULDistance: " + ulDistance.ToString()); Dbg.Trace("Parked LRDistance: " + lrDistance.ToString()); Dbg.Trace("Vehicle found parked using corners"); foundParked = true; } if (!foundParked) { Dbg.Trace("Vehicle found not parked using corners"); } } if (foundParked) { // OK, here we assume that they are the same object. // TODO: In high frame rate situations this could be a problem. // We add which ever has the highest confidence level to the result; objectList.RemoveAll(obj => obj.ID == vehicles[i].ID); // and remove it from the passed list Dbg.Trace("Removing parked vehicle: " + vehicles[i].Label); vehicles.RemoveAt(i); // we are done with this vehicle removedOne = true; break; } } } if (removedOne) { i = 0; // Since we removed on we need to start over } else { i++; // and on to the next } } // if we have any remaining vehicles add them to the list of previously seen ones _previousVehicles.Clear(); _previousVehicles = new List <ImageObject>(allFoundVehicles); // because ALL vehicles we found are now "previous" } } Dbg.Trace(" Vehicles remaining after parking check: " + vehicles.Count.ToString()); }