gpt4 book ai didi

c# - 使用WarpAffine()将Emgu.CV.Image向右移动

转载 作者:行者123 更新时间:2023-12-02 16:24:31 27 4
gpt4 key购买 nike

我的目标是将图像向右移动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());


我得到了Exeption:
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

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

先感谢您!

最佳答案

如果您将像素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);

关于c# - 使用WarpAffine()将Emgu.CV.Image向右移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62305781/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com