示例#1
0
        public void CalculateChrominanceSize(int ratioValue, int expectedDivX, int expectedDivY)
        {
            YCbCrImage.YCbCrSubsampleRatio ratio = (YCbCrImage.YCbCrSubsampleRatio)ratioValue;

            //this.Output.WriteLine($"RATIO: {ratio}");
            Size size = YCbCrImage.CalculateChrominanceSize(400, 400, ratio);

            //this.Output.WriteLine($"Ch Size: {size}");

            Assert.Equal(new Size(400 / expectedDivX, 400 / expectedDivY), size);
        }
示例#2
0
        internal void Create(YCbCrImage.YCbCrSubsampleRatio ratioValue, int expectedCStrideDiv)
        {
            YCbCrImage.YCbCrSubsampleRatio ratio = (YCbCrImage.YCbCrSubsampleRatio)ratioValue;

            this.Output.WriteLine($"RATIO: {ratio}");

            YCbCrImage img = new YCbCrImage(400, 400, ratio);

            //this.PrintChannel("Y", img.YChannel);
            //this.PrintChannel("Cb", img.CbChannel);
            //this.PrintChannel("Cr", img.CrChannel);

            Assert.Equal(400, img.YChannel.Width);
            Assert.Equal(img.CbChannel.Width, 400 / expectedCStrideDiv);
            Assert.Equal(img.CrChannel.Width, 400 / expectedCStrideDiv);
        }
示例#3
0
        public static JpegEncoder WithImageFromFile(string filename)
        {
            FileStream   fileStream   = new FileStream(filename, FileMode.Open);
            MemoryStream memoryStream = new MemoryStream();

            fileStream.CopyTo(memoryStream);

            fileStream.Close();

            memoryStream.Seek(0, SeekOrigin.Begin);

            RGBImage   rgbImage   = RGBImage.RGBImageBuilder.From(memoryStream).Build();
            YCbCrImage yCbCrImage = ColorChannels.RgbToYCbCr(rgbImage);

            return(new JpegEncoder(yCbCrImage));
        }
示例#4
0
        /// <summary>
        /// Gets an image made up of a subset of the originals pixels.
        /// </summary>
        /// <param name="x">The x-coordinate of the image.</param>
        /// <param name="y">The y-coordinate of the image.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns>
        /// The <see cref="YCbCrImage"/>.
        /// </returns>
        public YCbCrImage Subimage(int x, int y, int width, int height)
        {
            YCbCrImage ret = new YCbCrImage
            {
                Width     = width,
                Height    = height,
                YChannel  = this.YChannel,
                CbChannel = this.CbChannel,
                CrChannel = this.CrChannel,
                Ratio     = this.Ratio,
                YStride   = this.YStride,
                CStride   = this.CStride,
                YOffset   = (y * this.YStride) + x,
                COffset   = (y * this.CStride) + x
            };

            return(ret);
        }
示例#5
0
 private void MakeImg(int mxx, int myy)
 {
     if (nComp == 1){
         var m = new GrayImage(8*mxx, 8*myy);
         grayImage = m.subimage(0, 0, width, height);
     } else{
         var h0 = comp[0].h;
         var v0 = comp[0].v;
         var hRatio = h0/comp[1].h;
         var vRatio = v0/comp[1].v;
         var ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio444;
         switch ((hRatio << 4) | vRatio){
             case 0x11:
                 ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio444;
                 break;
             case 0x12:
                 ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio440;
                 break;
             case 0x21:
                 ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio422;
                 break;
             case 0x22:
                 ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio420;
                 break;
             case 0x41:
                 ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio411;
                 break;
             case 0x42:
                 ratio = YCbCrImage.YCbCrSubsampleRatio.YCbCrSubsampleRatio410;
                 break;
         }
         var m = new YCbCrImage(8*h0*mxx, 8*v0*myy, ratio);
         ycbcrImage = m.Subimage(0, 0, width, height);
     }
 }
示例#6
0
 public YCbCrImage Subimage(int x, int y, int w, int h)
 {
     var ret = new YCbCrImage{
         w = w,
         h = h,
         pix_y = pix_y,
         pix_cb = pix_cb,
         pix_cr = pix_cr,
         ratio = ratio,
         y_stride = y_stride,
         c_stride = c_stride,
         y_offset = y*y_stride + x,
         c_offset = y*c_stride + x
     };
     return ret;
 }
示例#7
0
        //For Tracking Object From Camera
        private void objectTrackingCam(Bitmap srcImage)
        {
            //Copy detected image to the new one
            if (radioButton1.Checked)
            {
                Bitmap newImage = (Bitmap)RGBImage.Clone();

                //Blob counter on the detected image
                BlobCounter bc = new BlobCounter();
                bc.MinHeight    = 5;
                bc.MinWidth     = 5;
                bc.FilterBlobs  = true;
                bc.ObjectsOrder = ObjectsOrder.Area;
                bc.ProcessImage(newImage);
                Rectangle[] rects = bc.GetObjectsRectangles();
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0]; //= recs;
                        Graphics  graph      = Graphics.FromImage(srcImage);

                        using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 2))
                        {
                            graph.DrawRectangle(pen, objectRect);
                        }

                        graph.Dispose();
                    }
                }

                //Draw tracked object on picture box
                pictureBox3.Image = srcImage;
            }

            else if (radioButton2.Checked)
            {
                Bitmap newImage = (Bitmap)HSLImage.Clone();

                //Blob counter on the detected image
                BlobCounter bc = new BlobCounter();
                bc.MinHeight    = 5;
                bc.MinWidth     = 5;
                bc.FilterBlobs  = true;
                bc.ObjectsOrder = ObjectsOrder.Area;
                bc.ProcessImage(newImage);
                Rectangle[] rects = bc.GetObjectsRectangles();
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0]; //= recs;
                        Graphics  graph      = Graphics.FromImage(srcImage);

                        using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 2))
                        {
                            graph.DrawRectangle(pen, objectRect);
                        }

                        graph.Dispose();
                    }
                }

                //Draw tracked object on picture box
                pictureBox3.Image = srcImage;
            }

            else if (radioButton3.Checked)
            {
                Bitmap newImage = (Bitmap)YCbCrImage.Clone();

                //Blob counter on the detected image
                BlobCounter bc = new BlobCounter();
                bc.MinHeight    = 5;
                bc.MinWidth     = 5;
                bc.FilterBlobs  = true;
                bc.ObjectsOrder = ObjectsOrder.Area;
                bc.ProcessImage(newImage);
                Rectangle[] rects = bc.GetObjectsRectangles();
                foreach (Rectangle recs in rects)
                {
                    if (rects.Length > 0)
                    {
                        Rectangle objectRect = rects[0]; //= recs;
                        Graphics  graph      = Graphics.FromImage(srcImage);

                        using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 2))
                        {
                            graph.DrawRectangle(pen, objectRect);
                        }

                        graph.Dispose();
                    }
                }

                //Draw tracked object on picture box
                pictureBox3.Image = srcImage;
            }
        }