OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3317|回复: 0

求高手解决问题啊,变色代码 运行时说无法加载什么问题

[复制链接]
发表于 2012-3-9 19:53:33 | 显示全部楼层 |阅读模式
private void buttonGrayImg_Click(object sender, EventArgs e)
        {
            string path = textBoxPath.Text;
            if (path == "")
            {
                MessageBox.Show(&quotlease select an image at first.", "Information");
                return;
            }

            string ext = path.Substring(path.Length - 3, 3);
            ext = ext.ToLower();
            ext = ext.Trim();
            if (ext.CompareTo("bmp") != 0 && ext.CompareTo("jpg") != 0)
            {
                MessageBox.Show("You must select an .bmp or .jpg file at first.", "Information");
                return;
            }

            IntPtr oldImg = CvInvoke.cvLoadImage(path, Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_ANYCOLOR);
            if (oldImg == eof)
            {
                MessageBox.Show("can not load the image:" + path, "Information");
                return;
            }

            Rectangle cr = CvInvoke.cvGetImageROI(oldImg);
            int width = cr.Width;
            int height = cr.Height;
            IntPtr grayImg = CvInvoke.cvCreateImage(cr.Size, Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 1);
            if (grayImg == eof)
            {
                MessageBox.Show("can not create an image in memory.", "Information");
                return;
            }
            CvInvoke.cvCvtColor(oldImg, grayImg, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_BGR2GRAY);            
           CvInvoke.cvNamedWindow("灰度图");
            CvInvoke.cvShowImage("灰度图", grayImg);
            CvInvoke.cvWaitKey(0);
            CvInvoke.cvReleaseImage(ref oldImg);
            CvInvoke.cvReleaseImage(ref grayImg);
            CvInvoke.cvDestroyWindow("灰度图");
        }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-5-19 01:08 , Processed in 0.009438 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表