コード例 #1
0
        public ActionResult Canny(HttpPostedFileBase imageData)
        {
            if (imageData != null)
            {
                using (var image = IplImage.FromStream(imageData.InputStream, LoadMode.Color))
                {
                    using (var grayImage = new IplImage(image.Size, BitDepth.U8, 1))
                    using (var cannyImage = new IplImage(image.Size, BitDepth.U8, 1))
                    {
                        Cv.CvtColor(image, grayImage, ColorConversion.BgrToGray);
                        Cv.Canny(grayImage, cannyImage, 60, 180);

                        byte[] cannyBytes = cannyImage.ToBytes(".png");
                        string base64 = Convert.ToBase64String(cannyBytes);
                        ViewBag.Base64Image = base64;

                        byte[] originalBytes = image.ToBytes(".png");
                        string base64Org = Convert.ToBase64String(originalBytes);
                        ViewBag.Base64OrgImage = base64Org;

                        byte[] grayBytes = grayImage.ToBytes(".png");
                        string base64Gray = Convert.ToBase64String(grayBytes);
                        ViewBag.Base64GrayImage = base64Gray;
                    }
                }
            }

            return View();
        }