Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调整图像大小<;灰色,字节>;没有缩放。埃姆古CV_C#_Opencv_Emgucv - Fatal编程技术网

C# 调整图像大小<;灰色,字节>;没有缩放。埃姆古CV

C# 调整图像大小<;灰色,字节>;没有缩放。埃姆古CV,c#,opencv,emgucv,C#,Opencv,Emgucv,我正在使用Image.InRange从图像创建遮罩。为了将性能保持在最佳状态,我在使用InRange方法之前使用Image.ROI裁剪图像。然而,为了实际处理图像,我需要它具有与原始图像相同的尺寸,但对我来说,显而易见的是如何缩放图像,而不是改变保留图像的尺寸 以下是相关代码: public Image<Gray, byte> Process(Image<Bgr, byte> frameIn, Rectangle roi) { Image<B

我正在使用Image.InRange从图像创建遮罩。为了将性能保持在最佳状态,我在使用InRange方法之前使用Image.ROI裁剪图像。然而,为了实际处理图像,我需要它具有与原始图像相同的尺寸,但对我来说,显而易见的是如何缩放图像,而不是改变保留图像的尺寸

以下是相关代码:

public Image<Gray, byte> Process(Image<Bgr, byte> frameIn, Rectangle roi)
    {
        Image<Bgr, byte> rectFrame = null;
        Image<Gray, byte> mask = null;
        if (roi != Rectangle.Empty)
        {
            rectFrame = frameIn.Copy(roi);
        }
        else
        {
            rectFrame = frameIn;
        }

        if (Equalize)
        {
            rectFrame._EqualizeHist();
        }


        mask = rectFrame.InRange(minColor, maxColor);

        mask ._Erode(Iterations);
        mask ._Dilate(Iterations);

        if (roi != Rectangle.Empty)
        {
            //How do I give the image its original dimensions?
        }

        return mask;
    }
公共图像处理(图像成帧、矩形roi)
{
图像帧=空;
图像掩码=空;
如果(roi!=矩形。空)
{
rectFrame=frameIn.Copy(roi);
}
其他的
{
rectFrame=frameIn;
}
如果(均衡)
{
rectFrame._EqualizeHist();
}
mask=rectFrame.InRange(minColor,maxColor);
掩模腐蚀(迭代);
掩模放大(迭代);
如果(roi!=矩形。空)
{
//我如何给出图像的原始尺寸?
}
返回掩码;
}
谢谢,,
Chris

我假设您希望返回与framIn大小相同的遮罩最简单的方法是将遮罩复制到与framIn大小相同的新图像。如果你的应用程序对时间不敏感,你可以让mask与framIn的大小相同,设置它的ROI,然后再进行操作。这确实需要较长的处理时间,而且不是最佳做法

无论如何,这里是希望你的代码后,如果不让我知道,我会相应地纠正它

if (roi != Rectangle.Empty)
{
    //Create a blank image with the correct size
    Image<Gray, byte> mask_return = new Image<Gray, byte>(frameIn.Size);
    //Set its ROI to the same as Mask and in the centre of the image (you may wish to change this)
    mask_return.ROI = new Rectangle((mask_return.Width - mask.Width) / 2, (mask_return.Height - mask.Height) / 2, mask.Width, mask.Height);
    //Copy the mask to the return image
    CvInvoke.cvCopy(mask, mask_return, IntPtr.Zero);
    //Reset the return image ROI so it has the same dimensions
    mask_return.ROI = new Rectangle(0, 0, frameIn.Width, frameIn.Height);
    //Return the mask_return image instead of the mask
    return mask_return;
}

return mask;
if(roi!=矩形.空)
{
//创建具有正确大小的空白图像
图像掩码返回=新图像(帧大小);
//将其ROI设置为与遮罩相同且位于图像中心(您可能希望更改此设置)
mask\u return.ROI=新矩形((mask\u return.Width-mask.Width)/2,(mask\u return.Height-mask.Height)/2,mask.Width,mask.Height);
//将掩码复制到返回图像
CvInvoke.cvCopy(掩码,掩码返回,IntPtr.Zero);
//重置返回图像ROI,使其具有相同的尺寸
mask_return.ROI=新矩形(0,0,frameIn.宽度,frameIn.高度);
//返回掩码\返回图像,而不是掩码
返回掩码(u return);;
}
返回掩码;
希望这有帮助

干杯


Chris

我假设您希望返回与framIn大小相同的遮罩最简单的方法是将遮罩复制到与framIn大小相同的新图像。如果你的应用程序对时间不敏感,你可以让mask与framIn的大小相同,设置它的ROI,然后再进行操作。这确实需要较长的处理时间,而且不是最佳做法

无论如何,这里是希望你的代码后,如果不让我知道,我会相应地纠正它

if (roi != Rectangle.Empty)
{
    //Create a blank image with the correct size
    Image<Gray, byte> mask_return = new Image<Gray, byte>(frameIn.Size);
    //Set its ROI to the same as Mask and in the centre of the image (you may wish to change this)
    mask_return.ROI = new Rectangle((mask_return.Width - mask.Width) / 2, (mask_return.Height - mask.Height) / 2, mask.Width, mask.Height);
    //Copy the mask to the return image
    CvInvoke.cvCopy(mask, mask_return, IntPtr.Zero);
    //Reset the return image ROI so it has the same dimensions
    mask_return.ROI = new Rectangle(0, 0, frameIn.Width, frameIn.Height);
    //Return the mask_return image instead of the mask
    return mask_return;
}

return mask;
if(roi!=矩形.空)
{
//创建具有正确大小的空白图像
图像掩码返回=新图像(帧大小);
//将其ROI设置为与遮罩相同且位于图像中心(您可能希望更改此设置)
mask\u return.ROI=新矩形((mask\u return.Width-mask.Width)/2,(mask\u return.Height-mask.Height)/2,mask.Width,mask.Height);
//将掩码复制到返回图像
CvInvoke.cvCopy(掩码,掩码返回,IntPtr.Zero);
//重置返回图像ROI,使其具有相同的尺寸
mask_return.ROI=新矩形(0,0,frameIn.宽度,frameIn.高度);
//返回掩码\返回图像,而不是掩码
返回掩码(u return);;
}
返回掩码;
希望这有帮助

干杯


克里斯

你能展示一下你做了什么/用问题的形式提问吗?你能展示一下你做了什么/用问题的形式提问吗?