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
        private void take_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, "alarmActive")) ? "On" : "Off");
                    lst.Add(config.getProfile(bubble.profileInUse).pingInterval.ToString() + " Mins");
                }

                imageText stampArgs = new imageText();
                stampArgs.bitmap           = (Bitmap)camera.pubFrame.Clone();
                stampArgs.type             = "Ping";
                stampArgs.backingRectangle = config.getProfile(bubble.profileInUse).pingTimeStampRect;
                stampArgs.stats            = lst;

                //saveBmp = bubble.timeStampImage((Bitmap)CameraRig.rig[CameraRig.activeCam].cam.pubFrame.Clone(), "Ping");
                //saveBmp = bubble.timeStampImage((Bitmap)camera.pubFrame.Clone(), "Ping", config.getProfile(bubble.profileInUse).pingTimeStampRect);
                saveBmp = bubble.timeStampImage(stampArgs);

                //specify jpeg compression
                //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, 50L);
                //myEncoderParameters.Param[0] = myEncoderParameter;
                //// Save the bitmap as a JPG file with 50 quality level compression.
                ////0 is greatest compression, 100 is least compression
                //saveBmp.Save(bubble.tmpFolder + fName, jgpEncoder, myEncoderParameters);

                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);


                //saveBmp.Save(bubble.tmpFolder + fName, ImageFormat.Jpeg);
                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;
                //old code 20091226
                //camera.pubFrame.Save(bubble.imageFolder + fName, ImageFormat.Jpeg);
                //old code 20091226
            }
            catch (Exception)
            {
                haveTheFlag      = false;
                bubble.pingError = true;
                bubble.logAddLine("Error in saving image: " + fName);
            }
        }
Exemplo n.º 3
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.º 4
0
        public static void publishImage()
        {
            if (keepPublishing)
            {

                foreach (rigItem item in CameraRig.rig)
                {

                    bool pubToWeb = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishWeb).ToString());
                    bool pubToLocal = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishLocal).ToString());
                    bool pubThisOne = true;

                    //publish from this camera
                    if (pubThisOne && (pubToWeb || pubToLocal))
                    {

                        int timeMultiplier = 0;
                        int PubInterval = 0;
                        bool secs = (bool)CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubSecs);
                        bool mins = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubMins).ToString());
                        bool hrs = Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubHours).ToString());

                        if (secs) timeMultiplier = 1;
                        if (mins) timeMultiplier = 60;
                        if (hrs) timeMultiplier = 3600;

                        PubInterval = timeMultiplier * Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString());

                        if (
                            Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishFirst).ToString())
                            || (time.secondsSinceStart() - Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.lastPublished).ToString())) >= PubInterval
                            )
                        {

                            pulseEvent(null, new EventArgs());

                            CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.publishFirst, false);

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

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

                                statistics.movementResults stats = new statistics.movementResults();
                                stats = statistics.statsForCam(item.cam.cam, bubble.profileInUse, "Publish");

                                lst.Add(stats.avgMvStart.ToString());
                                lst.Add(stats.avgMvLast.ToString());
                                lst.Add(stats.mvNow.ToString());
                                lst.Add(item.cam.alarmActive ? "On" : "Off");

                                switch (timeMultiplier)
                                {
                                    case 1:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Secs");
                                        break;
                                    case 60:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Mins");
                                        break;
                                    case 3600:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Hours");
                                        break;
                                    default:
                                        lst.Add(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.pubTime).ToString() + " Secs");
                                        break;
                                }

                            }

                            ImagePubArgs a = new ImagePubArgs();

                            a.option = "pub";
                            a.cam = item.cam.cam;
                            a.lst = lst;

                            try { pubPicture(null, a); }
                            catch { }

                            if (!pubError)
                                try
                                {

                                    teboDebug.writeline(teboDebug.publishImageVal + 3);
                                    pulseEvent(null, new EventArgs());

                                    string pubFile = "";

                                    if (pubToLocal)
                                    {

                                        teboDebug.writeline(teboDebug.publishImageVal + 4);
                                        string locFile = "";

                                        long tmpCycleLoc = new long();
                                        tmpCycleLoc = Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubLoc).ToString());

                                        string cameraPubLoc = CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.fileDirPubLoc).ToString();
                                        if (!Directory.Exists(cameraPubLoc))
                                        {
                                            Directory.CreateDirectory(cameraPubLoc);
                                        }

                                        //locFile = bubble.imageFolder +
                                        locFile = cameraPubLoc +
                                                  fileNameSet(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.filenamePrefixPubLoc).ToString(),
                                                                                   Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.cycleStampCheckedPubLoc).ToString()),
                                                                                   Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.startCyclePubLoc).ToString()),
                                                                                   Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.endCyclePubLoc).ToString()),
                                                                                   ref tmpCycleLoc,
                                                                                   Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.stampAppendPubLoc).ToString()));

                                        CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubLoc, Convert.ToInt32(tmpCycleLoc));

                                        teboDebug.writeline(teboDebug.publishImageVal + 5);
                                        File.Copy(tmpFolder + "pubPicture.jpg", locFile, true);
                                        pubFile = locFile;

                                    }

                                    if (pubToWeb)
                                    {
                                        teboDebug.writeline(teboDebug.publishImageVal + 6);

                                        string webFile = "";

                                        long tmpCycleWeb = new long();
                                        tmpCycleWeb = Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubWeb).ToString());

                                        webFile = fileNameSet(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.filenamePrefixPubWeb).ToString(),
                                                              Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.cycleStampCheckedPubWeb).ToString()),
                                                              Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.startCyclePubWeb).ToString()),
                                                              Convert.ToInt32(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.endCyclePubWeb).ToString()),
                                                              ref tmpCycleWeb,
                                                              Convert.ToBoolean(CameraRig.rigInfoGet(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.stampAppendPubWeb).ToString()));

                                        CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.currentCyclePubWeb, Convert.ToInt32(tmpCycleWeb));

                                        File.Copy(tmpFolder + "pubPicture.jpg", tmpFolder + webFile, true);
                                        ftp.DeleteFTP(webFile, config.getProfile(bubble.profileInUse).pubFtpRoot, config.getProfile(bubble.profileInUse).pubFtpUser, config.getProfile(bubble.profileInUse).pubFtpPass);
                                        ftp.Upload(tmpFolder + webFile, config.getProfile(bubble.profileInUse).pubFtpRoot, config.getProfile(bubble.profileInUse).pubFtpUser, config.getProfile(bubble.profileInUse).pubFtpPass);
                                        pubFile = webFile;

                                    }

                                    teboDebug.writeline(teboDebug.publishImageVal + 7);
                                    File.Delete(tmpFolder + "pubPicture.jpg");
                                    CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.lastPublished, time.secondsSinceStart());
                                    logAddLine("Webcam image " + pubFile + " published.");

                                    pulseEvent(null, new EventArgs());

                                }

                                catch
                                {
                                    teboDebug.writeline(teboDebug.publishImageVal + 8);
                                    CameraRig.updateInfo(bubble.profileInUse, item.cameraName, CameraRig.infoEnum.lastPublished, time.secondsSinceStart());
                                }

                        }

                    }//if (pubToWeb || pubToLocal)

                }//foreach (rigItem item in CameraRig.rig)

            }// if (keepPublishing)
        }