Exemplo n.º 1
0
        private void take_ping_picture(object sender, System.EventArgs e)
        {
            haveTheFlag = true;

            string fName = "pingPicture.jpg";
            Bitmap saveBmp = null;
            try
            {

                List<string> lst = new List<string>();

                if (config.getProfile(bubble.profileInUse).pingStatsStamp)
                {

                    statistics.movementResults stats = new statistics.movementResults();
                    stats = statistics.statsForCam(CameraRig.activeCam, bubble.profileInUse, "Ping");

                    lst.Add(stats.avgMvStart.ToString());
                    lst.Add(stats.avgMvLast.ToString());
                    lst.Add(stats.mvNow.ToString());
                    lst.Add(Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[CameraRig.activeCam].cameraName, CameraRig.infoEnum.alarmActive)) ? "On" : "Off");
                    lst.Add(config.getProfile(bubble.profileInUse).pingInterval.ToString() + " Mins");

                }

                imageText stampArgs = new imageText();

                if (config.getProfile(bubble.profileInUse).pingAll)
                {

                    mosaic mos = new mosaic();
                    int imgHeight = 0;
                    int imgWidth = 0;

                    //set the height and width to the largest image
                    foreach (rigItem item in CameraRig.rig)
                    {

                        if (item.cam.pubFrame.Height > imgHeight || item.cam.pubFrame.Width > imgWidth)
                        {

                            imgHeight = item.cam.pubFrame.Height;
                            imgWidth = item.cam.pubFrame.Width;

                        }

                    }

                    foreach (rigItem item in CameraRig.rig)
                    {

                        mos.addToList(bubble.resizeImage(item.cam.pubFrame, imgWidth, imgHeight));

                    }

                    stampArgs.bitmap = (Bitmap)mos.getMosaicBitmap(4).Clone();

                }
                else//if (config.getProfile(bubble.profileInUse).pingStatsStamp)
                {

                    stampArgs.bitmap = (Bitmap)camera.pubFrame.Clone();

                }

                stampArgs.type = "Ping";
                stampArgs.backingRectangle = config.getProfile(bubble.profileInUse).pingTimeStampRect;
                stampArgs.stats = lst;

                saveBmp = bubble.timeStampImage(stampArgs);

                ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
                System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                EncoderParameters myEncoderParameters = new EncoderParameters(1);
                EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, config.getProfile(bubble.profileInUse).pingCompression);
                myEncoderParameters.Param[0] = myEncoderParameter;
                saveBmp.Save(bubble.tmpFolder + fName, jgpEncoder, myEncoderParameters);

                Bitmap thumb = bubble.GetThumb(saveBmp);
                thumb.Save(bubble.tmpFolder + bubble.tmbPrefix + fName, ImageFormat.Jpeg);

                saveBmp.Dispose();
                thumb.Dispose();
                bubble.logAddLine("Image saved: " + fName);
                //bubble.pingError = false;
                haveTheFlag = false;

            }
            catch (Exception)
            {
                haveTheFlag = false;
                //bubble.pingError = true;
                bubble.logAddLine("Error in saving image: " + fName);
            }
        }
Exemplo n.º 2
0
        public static Bitmap timeStampImage(imageText imageTxt)
        {
            Bitmap imageIn = imageTxt.bitmap;
            string type = imageTxt.type;
            bool backingRectangle = imageTxt.backingRectangle;

            string position = "";
            string format = "";
            string colour = "";
            string formatStr = "";
            Brush textBrush = Brushes.Black;
            Brush opaqueBrush = Brushes.Black;
            int time = 70;
            int date = 80;
            int full = 150;
            int textWidth = 0;

            try
            {

                if (type == "Alert")
                {
                    if (!config.getProfile(bubble.profileInUse).alertTimeStamp) return imageIn;
                    position = config.getProfile(bubble.profileInUse).alertTimeStampPosition;
                    format = config.getProfile(bubble.profileInUse).alertTimeStampFormat;
                    colour = config.getProfile(bubble.profileInUse).alertTimeStampColour;
                }

                if (type == "Ping")
                {
                    if (!config.getProfile(bubble.profileInUse).pingTimeStamp) return imageIn;
                    position = config.getProfile(bubble.profileInUse).pingTimeStampPosition;
                    format = config.getProfile(bubble.profileInUse).pingTimeStampFormat;
                    colour = config.getProfile(bubble.profileInUse).pingTimeStampColour;
                }

                if (type == "Publish")
                {
                    if (!config.getProfile(bubble.profileInUse).publishTimeStamp) return imageIn;
                    position = config.getProfile(bubble.profileInUse).publishTimeStampPosition;
                    format = config.getProfile(bubble.profileInUse).publishTimeStampFormat;
                    colour = config.getProfile(bubble.profileInUse).publishTimeStampColour;
                }

                if (type == "Online")
                {
                    if (!config.getProfile(bubble.profileInUse).onlineTimeStamp) return imageIn;
                    position = config.getProfile(bubble.profileInUse).onlineTimeStampPosition;
                    format = config.getProfile(bubble.profileInUse).onlineTimeStampFormat;
                    colour = config.getProfile(bubble.profileInUse).onlineTimeStampColour;
                }

                switch (format)
                {
                    case "hhmm":
                        formatStr = DateTime.Now.ToString("HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                        textWidth = time;
                        break;
                    case "ddmmyy":
                        formatStr = DateTime.Now.ToString("dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture);
                        textWidth = date;
                        break;
                    case "ddmmyyhhmm":
                        formatStr = DateTime.Now.ToString("dd-MMM-yy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                        textWidth = full;
                        break;
                    case "analogue":
                        formatStr = "";
                        textWidth = 0;
                        break;
                    case "analoguedate":
                        formatStr = DateTime.Now.ToString("dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture); ;
                        textWidth = date;
                        break;
                    default:
                        formatStr = DateTime.Now.ToString("dd-MMM-yy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                        textWidth = full;
                        break;
                }

                switch (colour)
                {
                    case "red":
                        textBrush = Brushes.Red;
                        opaqueBrush = Brushes.White;
                        break;
                    case "black":
                        textBrush = Brushes.Black;
                        opaqueBrush = Brushes.White;
                        break;
                    case "white":
                        textBrush = Brushes.White;
                        opaqueBrush = Brushes.Black;
                        break;
                    default:
                        textBrush = Brushes.Black;
                        opaqueBrush = Brushes.White;
                        break;
                }

                int width = imageIn.Width;
                int height = imageIn.Height;
                int x = 0;
                int y = 0;

                switch (position)
                {
                    case "tl":
                        x = 5;
                        y = 5;
                        break;
                    case "tr":
                        x = width - textWidth;
                        y = 5;
                        break;
                    case "bl":
                        x = 5;
                        y = height - 20;
                        break;
                    case "br":
                        x = width - textWidth;
                        y = height - 20;
                        break;
                    default:
                        x = 5;
                        y = 5;
                        break;
                }

                if (format == "analogue" || format == "analoguedate")
                {

                    int Xpos = 0;
                    int Ypos = 0;
                    int dtYpos = 0;
                    int dtXpos = 0;
                    int stYpos = 0;
                    int stXpos = 0;
                    int radius = 0;
                    int borderCorrection = 0;
                    int dateCorrection = 0;
                    int dateOfffset = 20;
                    int statsCorrection = 0;
                    int statsOffset = 20;

                    if (format == "analoguedate")
                    {

                        dateCorrection = -dateOfffset;
                    }

                    string stformatStr = "";

                    if (imageTxt.stats.Count > 0)
                    {

                        stformatStr = "";
                        foreach (string str in imageTxt.stats)
                        {

                            stformatStr += str + ", ";

                        }

                        //remove that last comma and space
                        stformatStr = stformatStr.Remove(stformatStr.Length - 2);

                        statsCorrection = -statsOffset;

                    }

                    Size stsize = TextRenderer.MeasureText(stformatStr, new Font("Arial", 12, FontStyle.Regular));
                    Size dtsize = TextRenderer.MeasureText(formatStr, new Font("Arial", 12, FontStyle.Regular));
                    radius = (int)(Math.Min(imageIn.Height, imageIn.Width) / 12);
                    borderCorrection = radius;

                    switch (position)
                    {

                        case "tl":
                            Xpos = borderCorrection;
                            Ypos = imageIn.Height - borderCorrection;
                            dtXpos = 2;
                            dtYpos = radius * 2 - statsCorrection;
                            stXpos = 2;
                            stYpos = radius * 2;
                            break;
                        case "tr":
                            Xpos = imageIn.Width - borderCorrection;
                            Ypos = imageIn.Height - borderCorrection;
                            dtXpos = imageIn.Width - dtsize.Width - 2;
                            dtYpos = radius * 2 - statsCorrection;
                            stXpos = imageIn.Width - stsize.Width - 2;
                            stYpos = radius * 2;
                            break;
                        case "bl":
                            Xpos = borderCorrection;
                            Ypos = borderCorrection - dateCorrection - statsCorrection;
                            dtXpos = 2;
                            dtYpos = imageIn.Height - dateOfffset - 5;
                            stXpos = 2;
                            stYpos = imageIn.Height - dateOfffset - statsOffset - 5;
                            break;
                        case "br":
                            Xpos = imageIn.Width - borderCorrection;
                            Ypos = borderCorrection - dateCorrection - statsCorrection;
                            dtXpos = imageIn.Width - dtsize.Width - 2;
                            dtYpos = imageIn.Height - dateOfffset - 5;
                            stXpos = imageIn.Width - stsize.Width - 2;
                            stYpos = imageIn.Height - dateOfffset - statsOffset - 5;
                            break;
                        default://tr
                            Xpos = imageIn.Width - borderCorrection;
                            Ypos = imageIn.Height - borderCorrection;
                            dtXpos = imageIn.Width - dtsize.Width - 2;
                            dtYpos = radius * 2 - statsCorrection;
                            stXpos = imageIn.Width - stsize.Width - 2;
                            stYpos = radius * 2;
                            break;
                    }

                    if (format == "analoguedate")
                    {

                        Graphics graphicsObj;
                        graphicsObj = Graphics.FromImage(imageIn);

                        if (backingRectangle)
                        {

                            graphicsObj.FillRectangle(opaqueBrush, dtXpos, dtYpos, dtsize.Width, dtsize.Height);

                        }

                        graphicsObj.DrawString(formatStr, new Font("Arial", 12, FontStyle.Regular), textBrush, new PointF(dtXpos, dtYpos));

                        graphicsObj.Dispose();

                    }

                    if (imageTxt.stats.Count > 0)
                    {

                        Graphics graphicsObjStats;
                        graphicsObjStats = Graphics.FromImage(imageIn);
                        graphicsObjStats.FillRectangle(opaqueBrush, stXpos, stYpos, stsize.Width, stsize.Height);
                        graphicsObjStats.DrawString(stformatStr, new Font("Arial", 12, FontStyle.Regular), textBrush, stXpos, stYpos);
                        graphicsObjStats.Dispose();

                    }

                    imageIn = drawClock(imageIn,
                                        Color.FromName(colour),
                                        Color.FromName(colour),
                                        Color.FromName(colour),
                                        Color.FromName(colour),
                                        Color.Black, true, false,
                                        Xpos,
                                        Ypos,
                                        radius,
                                        imageIn.Width,
                                        imageIn.Height,
                                        backingRectangle,
                                        false,
                                        opaqueBrush);

                }
                else
                {
                    Graphics graphicsObj;
                    graphicsObj = Graphics.FromImage(imageIn);

                    if (backingRectangle)
                    {

                        graphicsObj.FillRectangle(opaqueBrush, x, y, textWidth, 20);

                    }

                    graphicsObj.DrawString(formatStr, new Font("Arial", 12, FontStyle.Regular), textBrush, new PointF(x, y));
                    graphicsObj.Dispose();

                    if ((type == "Publish" || type == "Ping") && imageTxt.stats.Count > 0)
                    {

                        formatStr = "";
                        foreach (string str in imageTxt.stats)
                        {

                            formatStr += str + ", ";

                        }

                        //remove that last comma and space
                        formatStr = formatStr.Remove(formatStr.Length - 2);

                        Graphics graphicsObjStats;
                        graphicsObjStats = Graphics.FromImage(imageIn);
                        graphicsObjStats.FillRectangle(opaqueBrush, x, y + 21, graphicsObjStats.MeasureString(formatStr, new Font("Arial", 12, FontStyle.Regular)).Width, graphicsObjStats.MeasureString(formatStr, new Font("Arial", 12, FontStyle.Regular)).Height);
                        graphicsObjStats.DrawString(formatStr, new Font("Arial", 12, FontStyle.Regular), textBrush, new PointF(x, y + 21));
                        graphicsObjStats.Dispose();

                    }
                }

                return imageIn;
            }
            catch
            { return imageIn; }
        }
Exemplo n.º 3
0
        public static void camera_Alarm(object sender, CamIdArgs e, LevelArgs l)
        {
            List<object> lightSpikeResults;

            bool spike = new bool();
            spike = false;
            int spikePerc = new int();

            //are we filtering light spikes?
            if (!CameraRig.rig[e.cam].cam.triggeredBySpike
                && (bool)(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[e.cam].cameraName, CameraRig.infoEnum.lightSpike)))
            {

                lightSpikeResults = statistics.lightSpikeDetected(e.cam, l.lvl,
                                                       config.getProfile(bubble.profileInUse).timeSpike,
                                                       config.getProfile(bubble.profileInUse).toleranceSpike,
                                                       bubble.profileInUse,
                                                       time.millisecondsSinceStart());

                spike = (bool)lightSpikeResults[0];
                spikePerc = (int)lightSpikeResults[1];

            }

            //movement alarm was not previously triggered by a light spike
            //and a light spike has not been detected with the current alarm inducing movement
            //or we are not concerned about light spikes
            if ((!CameraRig.rig[e.cam].cam.triggeredBySpike && !spike)
                || CameraRig.rig[e.cam].cam.certifiedTriggeredByNonSpike
                || !(bool)(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[e.cam].cameraName, CameraRig.infoEnum.lightSpike)))
            {

                CameraRig.rig[e.cam].cam.certifiedTriggeredByNonSpike = true;

                if (config.getProfile(bubble.profileInUse).areaOffAtMotion && !CameraRig.AreaOffAtMotionIsTriggeredCam(e.cam))
                {

                    CameraRig.AreaOffAtMotionTrigger(e.cam);
                    bubble.areaOffAtMotionTriggered = true;

                }

                if (bubble.Alert.on && bubble.imageSaveTime(true))
                {

                    try
                    {

                        string fName = fileNameSet(config.getProfile(bubble.profileInUse).filenamePrefix,
                                                   config.getProfile(bubble.profileInUse).cycleStampChecked,
                                                   config.getProfile(bubble.profileInUse).startCycle,
                                                   config.getProfile(bubble.profileInUse).endCycle,
                                                   ref config.getProfile(bubble.profileInUse).currentCycle,
                                                   true);

                        Bitmap saveBmp = null;

                        imageText stampArgs = new imageText();
                        stampArgs.bitmap = (Bitmap)CameraRig.rig[e.cam].cam.pubFrame.Clone();
                        stampArgs.type = "Alert";
                        stampArgs.backingRectangle = config.getProfile(profileInUse).alertTimeStampRect;

                        saveBmp = timeStampImage(stampArgs);

                        ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
                        System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                        EncoderParameters myEncoderParameters = new EncoderParameters(1);
                        EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, config.getProfile(profileInUse).alertCompression);
                        myEncoderParameters.Param[0] = myEncoderParameter;
                        saveBmp.Save(bubble.imageFolder + fName, jgpEncoder, myEncoderParameters);

                        Bitmap thumb = GetThumb(saveBmp);
                        thumb.Save(thumbFolder + tmbPrefix + fName, ImageFormat.Jpeg);
                        ImageThumbs.addThumbToPictureBox(thumbFolder + tmbPrefix + fName);
                        saveBmp.Dispose();
                        thumb.Dispose();
                        ImageSavedArgs a = new ImageSavedArgs();
                        a.image = fName;
                        ImageSaved(null, a);

                        updateSeq++;

                        if (updateSeq > 9999)
                        {
                            updateSeq = 1;
                        }

                        moveStatsAdd(time.currentTime());
                        logAddLine("Movement detected");
                        logAddLine("Movement level: " + l.lvl.ToString() + " spike perc.: " + Convert.ToString(spikePerc));
                        logAddLine("Image saved: " + fName);

                    }
                    catch (Exception)
                    {

                        logAddLine("Error in saving movement image.");
                        updateSeq++;

                    }
                }

            }
            else
            {

                //a light spike caused this alarm and we are catching light spikes
                if ((bool)(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[e.cam].cameraName, CameraRig.infoEnum.lightSpike)))
                {

                    CameraRig.rig[e.cam].cam.triggeredBySpike = true;

                }

            }
        }
Exemplo n.º 4
0
        public static void take_picture_publish(object sender, ImagePubArgs e)
        {
            haveTheFlag = true;

            string fName = "";
            string stamp = "";
            stamp = e.option;

            bool online = false;
            bool publish = false;
            bool test = false;

            if (stamp.Length >= 3)
            {
                publish = stamp == "pub";
                online = stamp == "onl";
                test = LeftRightMid.Left(stamp, 3) == "tst";
            }

            try
            {

                Bitmap imgBmp = null;
                int compression = 100;

                if (online)
                {
                    fName = config.getProfile(bubble.profileInUse).webImageFileName + ".jpg";

                    imageText stampArgs = new imageText();
                    stampArgs.bitmap = (Bitmap)CameraRig.getCam(e.cam).pubFrame.Clone();
                    stampArgs.type = "Online";
                    stampArgs.backingRectangle = config.getProfile(profileInUse).onlineTimeStampRect;

                    imgBmp = bubble.timeStampImage(stampArgs);
                    compression = config.getProfile(bubble.profileInUse).onlineCompression;
                }

                if (publish)
                {
                    fName = "pubPicture.jpg";

                    imageText stampArgs = new imageText();
                    stampArgs.bitmap = (Bitmap)CameraRig.getCam(e.cam).pubFrame.Clone();
                    stampArgs.type = "Publish";
                    stampArgs.backingRectangle = config.getProfile(profileInUse).publishTimeStampRect;
                    stampArgs.stats = e.lst;

                    imgBmp = bubble.timeStampImage(stampArgs);
                    compression = config.getProfile(bubble.profileInUse).publishCompression;
                }

                if (test)
                {
                    fName = LeftRightMid.Mid(stamp, 3, stamp.Length - 3) + ".jpg";

                    imgBmp = (Bitmap)CameraRig.getCam(e.cam).pubFrame.Clone();
                    compression = config.getProfile(bubble.profileInUse).alertCompression;
                }

                ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
                System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                EncoderParameters myEncoderParameters = new EncoderParameters(1);
                EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, compression);

                myEncoderParameters.Param[0] = myEncoderParameter;
                imgBmp.Save(bubble.tmpFolder + fName, jgpEncoder, myEncoderParameters);

                if (!test)
                {
                    Bitmap thumb = bubble.GetThumb(imgBmp);
                    thumb.Save(bubble.tmpFolder + bubble.tmbPrefix + fName, ImageFormat.Jpeg);
                    thumb.Dispose();
                }

                imgBmp.Dispose();
                bubble.logAddLine("Image saved: " + fName);
                bubble.pubError = false;
                haveTheFlag = false;

            }
            catch (Exception)
            {
                haveTheFlag = false;
                bubble.pubError = true;
                bubble.logAddLine("Error in saving image: " + fName);
            }
        }