Exemple #1
0
        public byte[] AddImageToByteList(ViewDir view, Bitmap image)
        {
            if (new Image <Bgra, byte>(image).Cols != frame.Cols || new Image <Bgra, byte>(image).Rows != frame.Rows)
            {
                CvInvoke.Resize(new Image <Bgra, byte>(image), new Image <Bgra, byte>(image), new Size(frame.Cols, frame.Rows));
            }

            if (viewMat.ContainsKey(view))
            {
                viewMat.Remove(view);
            }
            viewMat.Add(view, new Image <Bgra, byte>(image));

            Image <Bgra, byte> combineImg = new Image <Bgra, byte>(frame.Size);

            frame.CopyTo(combineImg);
            CvInvoke.CvtColor(new Image <Bgra, byte>(image), modelMask, ColorConversion.Rgb2Gray);
            CvInvoke.Threshold(modelMask, modelMask, 250, 255, ThresholdType.BinaryInv);
            new Image <Bgra, byte>(image).Mat.CopyTo(combineImg, modelMask);

            Bitmap       bitmap = combineImg.ToBitmap();
            MemoryStream ms     = new MemoryStream();

            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return(combineImg.ToJpegData(100));
            //return new Image<Bgra, byte>(image).ToJpegData(100);
        }
Exemple #2
0
 public void ChangeViewDir(ViewDir view)
 {
     viewMat[view].Mat.CopyTo(model);
     CvInvoke.CvtColor(model, modelMask, ColorConversion.Rgb2Gray);
     CvInvoke.Threshold(modelMask, modelMask, 250, 255, ThresholdType.BinaryInv);
     DrawPlaneAndDisplay(currentHeight);
 }
Exemple #3
0
        public byte[] CropAndAddImage(ViewDir view, Bitmap image)
        {
            //Get range
            int  dim  = (int)(image.Height / 1.7);
            Size size = new Size(dim, dim);
            //Point location = new Point((int)(image.Width / 2 - dim / 2), (int)((image.Height / 2) - dim / 2) + (int)(frame.Rows*1.05) /2);
            Point     location = new Point((int)(image.Width / 2 - dim / 2), (int)((image.Height / 2) - dim / 2) + (int)(image.Height * 0.189));
            Rectangle roi      = new Rectangle(location, size);

            //Crop and resize
            Image <Bgra, byte> modelsImg = new Image <Bgra, byte>(image);

            modelsImg.ROI = roi;
            if (modelsImg.Cols != frame.Cols || modelsImg.Rows != frame.Rows)
            {
                CvInvoke.Resize(modelsImg, modelsImg, new Size(frame.Cols, frame.Rows));
            }

            //Add into array
            if (viewMat.ContainsKey(view))
            {
                viewMat.Remove(view);
            }
            viewMat.Add(view, modelsImg);

            //Combine models and frame
            Image <Bgra, byte> combineImg = new Image <Bgra, byte>(frame.Size);

            frame.CopyTo(combineImg);
            CvInvoke.CvtColor(modelsImg, modelMask, ColorConversion.Rgb2Gray);
            CvInvoke.Threshold(modelMask, modelMask, 250, 255, ThresholdType.BinaryInv);
            modelsImg.Mat.CopyTo(combineImg, modelMask);

            //output byte[]
            Bitmap       bitmap = combineImg.ToBitmap();
            MemoryStream ms     = new MemoryStream();

            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            return(combineImg.ToJpegData(100));
        }