使用WarpAffine()向右移动Emgu.CV.Image

詹德·弗里贝(Jander Friebe)

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将类型'Emgu.CV.Mat'转换为'Emgu.CV.Image <Emgu.CV.Structure.Bgr,byte>'

来自分类Dev

SystemAccessViolation将Drawing.Bitmap转换为Emgu.CV.Image

来自分类Dev

如何使Emgu CV透明?

来自分类Dev

如何使Emgu CV透明?

来自分类Dev

EMGU CV异常

来自分类Dev

将OGRE :: Image转换为cv :: Mat

来自分类Dev

何时在Emgu CV中使用“图像”以及何时使用“矩阵”?

来自分类Dev

使用emgu.cv的Alpha合成图像

来自分类Dev

如何使用Emgu CV检测图像中的箭头?

来自分类Dev

如何使用Emgu CV消除不必要的行

来自分类Dev

使用Emgu CV 3.1进行内存管理的正确方法

来自分类Dev

使用 Visual Studio 在 emgu cv 中出现 foreach 循环错误

来自分类Dev

使用 emgu CV 将大图像保存到文件系统

来自分类Dev

向右移动数组

来自分类Dev

向右移动按钮

来自分类Dev

猪描述符emgu cv

来自分类Dev

基于图像的EMGU CV人脸识别

来自分类Dev

Emgu CV图像加载不起作用

来自分类Dev

Emgu CV无法从给定路径创建图像

来自分类Dev

PIL.Image到cv2:参数'src'的预期Ptr <cv :: UMat>

来自分类Dev

未定义“ CV_LOAD_IMAGE_GRAYSCALE” {PY}

来自分类Dev

“ Emgu.CV.World.dll”中发生“ Emgu.CV.Util.CvException”-尝试进行预测时

来自分类Dev

如何向右移动和使用未使用的宽度空间?

来自分类Dev

使用cv :: imdecode后,cv :: Mat外部数据未修改

来自分类Dev

如何使用CoreMotion向左或向右移动精灵?

来自分类Dev

尝试使用flexbox从左向右移动2个元素

来自分类Dev

HTML表格向右移动

来自分类Dev

向右移动数组元素?

来自分类Dev

敌人不断向右移动