Beispiel #1
0
        public void ApplyConfig(IBlobTrackParamConfig blobTrackParamConfig)
        {
            if (blobTrackParamConfig != null)
            {
                blobTrackParamConfig.ImageWidth  = shapeDrawCtrl_alarmarea.ShapeManager.ImageWidth;
                blobTrackParamConfig.ImageHeight = shapeDrawCtrl_alarmarea.ShapeManager.ImageHeight;

                Hashtable     acTable = new Hashtable();
                IAreaConfig[] acs     = blobTrackParamConfig.GetAreaConfigs();
                if (acs != null)
                {
                    foreach (IAreaConfig ac in acs)
                    {
                        acTable.Add(ac.Id, ac);
                    }
                }

                blobTrackParamConfig.ClearAreaConfig();
                IShape[] shapes = shapeDrawCtrl_alarmarea.GetShapes();
                if (shapes != null)
                {
                    IAreaConfig oac, ac;
                    foreach (IGuardArea area in shapes)
                    {
                        if (area != null)
                        {
                            ac  = area.GetAreaConfig();
                            oac = acTable[ac.Id] as IAreaConfig;

                            if (oac != null)
                            {
                                oac.CopyPointsTo(ac);
                            }

                            blobTrackParamConfig.AddAreaConfig(ac);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public bool BuildConfiguration(ref Configuration config, IBlobTrackParamConfig paramConfig)
        {
            if (paramConfig == null)
            {
                paramConfig = this.BlobTrackParamConfig;
            }

            unsafe
            {
                config.AvailableMinSize   = new win32.POINT();
                config.AvailableMinSize.x = paramConfig.MinWidth;
                config.AvailableMinSize.y = paramConfig.MinHeight;

                config.AvailableMaxSize   = new win32.POINT();
                config.AvailableMaxSize.x = paramConfig.MaxWidth;
                config.AvailableMaxSize.y = paramConfig.MaxHeight;

                config.AvailableMinSpeed = paramConfig.MinSpeed;
                config.AvailableMaxSpeed = paramConfig.MaxSpeed;

                config.TimeThreshold = paramConfig.TimeThreshold;

                config.DensityMinNum = 0;
                //config.FaceDetectTwoStep = false;
                //config.FaceDetectForeground = false;

                config.WanderAlertMinTimes = 0;
                config.StayAlertMinTimes   = 0;
                config.ProcessMode         = paramConfig.ProcessMode;

                config.GuardAlert     = (ushort)paramConfig.GuardAlert;
                config.GuardAreaCount = paramConfig.AreaCount;

                if (config.GuardAreaCount > 0)
                {
                    config.GuardAreas = (GuardArea *)Marshal.AllocHGlobal(config.GuardAreaCount * Marshal.SizeOf(typeof(GuardArea)));

                    IAreaConfig   curAreaConfig;
                    win32.POINT[] points;
                    win32.RECT    rect;

                    int   width  = paramConfig.ImageWidth;
                    int   height = paramConfig.ImageHeight;
                    float xr     = 1.0F;
                    float yr     = 1.0F;
                    if (width > 352 || height > 288)
                    {
                        xr = ((float)352 / (float)width);
                        yr = ((float)288 / (float)height);
                    }

                    IAreaConfig[] arrarList = paramConfig.GetAreaConfigs();
                    for (int i = 0; i < config.GuardAreaCount; i++)
                    {
                        curAreaConfig = arrarList[i];

                        config.GuardAreas[i].index       = curAreaConfig.Index;
                        config.GuardAreas[i].type        = (int)curAreaConfig.AreaType;
                        config.GuardAreas[i].level       = (int)curAreaConfig.GuardLevel;
                        config.GuardAreas[i].opt         = curAreaConfig.AlertOpt;
                        config.GuardAreas[i].sensitivity = curAreaConfig.Sensitivity;
                        //config.GuardAreas[i].param = curAreaConfig.AlertParam;
                        config.GuardAreas[i].wanderCount   = curAreaConfig.WanderCount;
                        config.GuardAreas[i].stayTime      = curAreaConfig.StayTime;
                        config.GuardAreas[i].assembleCount = curAreaConfig.AssembleCount;
                        config.GuardAreas[i].interval      = curAreaConfig.AlertInterval;
                        config.GuardAreas[i].count         = curAreaConfig.Count;

                        if (curAreaConfig.Count > 0)
                        {
                            config.GuardAreas[i].points = (win32.POINT *)Marshal.AllocHGlobal(curAreaConfig.Count * Marshal.SizeOf(typeof(win32.POINT)));
                            points = curAreaConfig.GetPoints();
                            for (int j = 0; j < points.Length; j++)
                            {
                                if (width <= 352 && height <= 288)
                                {
                                    config.GuardAreas[i].points[j].x = points[j].x;
                                    config.GuardAreas[i].points[j].y = height - points[j].y;
                                }
                                else
                                {
                                    config.GuardAreas[i].points[j].x = (int)(xr * (float)points[j].x);
                                    config.GuardAreas[i].points[j].y = (int)(yr * (float)(height - points[j].y));
                                }
                            }
                        }

                        rect = curAreaConfig.Rect;
                        if (width <= 352 && height <= 288)
                        {
                            rect.top    = height - rect.top;
                            rect.bottom = height - rect.bottom;
                        }
                        else
                        {
                            rect.top    = (int)(yr * (float)(height - rect.top));
                            rect.bottom = (int)(yr * (float)(height - rect.bottom));
                            rect.left   = (int)(xr * (float)rect.left);
                            rect.right  = (int)(xr * (float)rect.right);
                        }
                        config.GuardAreas[i].r       = rect;
                        config.GuardAreas[i].minsize = curAreaConfig.MinSize;
                        config.GuardAreas[i].maxsize = curAreaConfig.MaxSize;
                    }
                }

                config.DepthAreaCount = paramConfig.DepthAreaCount;

                if (config.DepthAreaCount > 0)
                {
                    config.DepthAreas = (DepthArea *)Marshal.AllocHGlobal(config.DepthAreaCount * Marshal.SizeOf(typeof(DepthArea)));

                    IDepthAreaConfig curDepthAreaConfig;

                    IDepthAreaConfig[] depthAreaList = paramConfig.GetDepthAreaConfigs();
                    for (int i = 0; i < config.DepthAreaCount; i++)
                    {
                        curDepthAreaConfig           = depthAreaList[i];
                        config.DepthAreas[i].x1      = curDepthAreaConfig.X1;
                        config.DepthAreas[i].y1      = curDepthAreaConfig.Y1;
                        config.DepthAreas[i].x2      = curDepthAreaConfig.X2;
                        config.DepthAreas[i].y2      = curDepthAreaConfig.Y2;
                        config.DepthAreas[i].height  = curDepthAreaConfig.Height;
                        config.DepthAreas[i].width   = curDepthAreaConfig.Width;
                        config.DepthAreas[i].IsDepth = curDepthAreaConfig.IsDepth ? 1 : 0;
                    }
                }
            }
            return(true);
        }