【问题标题】:Shift Emgu.CV.Image to the right using WarpAffine()使用 WarpAffine() 将 Emgu.CV.Image 向右移动
【发布时间】:2020-09-29 23:58:11
【问题描述】:

我的目标是,将图像向右移动 x 个像素。我想这可以通过使用 WarpAffine 来实现。这至少是我的研究告诉我的。我使用了多种不同的方法,例如:

CvInvoke.WarpAffine(realImage, transformedImage, transformationMatrix, new Size(realImage.Size);

//or while m is the Mat used to create realImage
transImage.WarpAffine(m,Emgu.CV.CvEnum.Inter.Area,Emgu.CV.CvEnum.Warp.Default,Emgu.CV.CvEnum.BorderType.Default,new Gray());

我得到了例外:

Exception thrown: 'Emgu.CV.Util.CvException' in Emgu.CV.Platform.NetStandard.dll
[ WARN:0] global E:\bb\cv_x86\build\opencv\modules\videoio\src\cap_msmf.cpp (436) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

我想我用错了,但网上没有合适的例子可供我学习。 有没有人有干净的方式向我解释?

提前谢谢你!

【问题讨论】:

    标签: c# image opencv emgucv affinetransform


    【解决方案1】:

    如果您将像素 x 量向右移动,我假设左侧会有黑色空像素?如果是这样,您可以创建一个 ROI 并切断右侧的一些像素,因为您将所有像素都向右移动,然后将图像复制到另一个图像上。

    //The image that you want to shift pixels with
    Image<Bgr, byte> inputImage = new Image<Bgr, byte>(1000, 1000);
    
    //The output image
    Image<Bgr, byte> image = new Image<Bgr, byte>(990, 1000);
    
    //Create the roi, with 10 pixels cut off from the right side because of the shift
    inputImage.ROI = new Rectangle(0, 0, inputImage.Width - 10, inputImage.Height);
    
    inputImage.CopyTo(image);
    
    CvInvoke.ImShow("The Output", image);
    CvInvoke.WaitKey(0);
    
    

    编辑

    现在假设您也想在图像的左侧保留黑色条纹。这样做与上面的代码非常相似,只是做了一些修改。

    //The image that you want to shift pixels with
    Image<Bgr, byte> inputImage = new Image<Bgr, byte>(1000, 1000);
    
    //The output image
    Image<Bgr, byte> image = new Image<Bgr, byte>(1000, 1000);
    
    //Create the roi, with 10 pixels cut off from the right side because of the shift
    inputImage.ROI = new Rectangle(0, 0, inputImage.Width - 10, inputImage.Height);
    
    //The image we want to shift, the same one we created a ROI with, 
    //has the dimensions 990 X 1000 and the output image has 
    //dimensions of 1000 x 1000. Unfortunately, in order to paste 
    //an image onto another image, they need to be the same dimensions. 
    //How do we do this? We must create an ROI with the output image 
    //that has the same dimensions as the input image. 
    
    image.ROI = new Rectangle(10, 0, image.Width, image.Height);
    
    //Now we can past the image onto the output because the dimensions match
    inputImage.CopyTo(image);
    
    //Inorder to make our output seem normal, we must empty the ROI of the output image
    image.ROI = Rectangle.Empty;
    
    CvInvoke.ImShow("The Output", image);
    CvInvoke.WaitKey(0);
    
    

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多