Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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# 将一组四个点中的两个图像对齐_C#_Image_Image Processing_Accord.net_Image Registration - Fatal编程技术网

C# 将一组四个点中的两个图像对齐

C# 将一组四个点中的两个图像对齐,c#,image,image-processing,accord.net,image-registration,C#,Image,Image Processing,Accord.net,Image Registration,我在C#中的accord.net中玩,并试图对齐两个图像。我是计算机视觉新手,想知道accord.net是否能做到这一点,或者我是否必须自己写点东西 我有两张图片,每张图片我有四个点。从左上角so(TL、TR、BR、BL)开始,围绕图像逆时针分配点 例如: 图1 Point 1(221, 156) Point 2(4740, 156) Point 3(4740, 3347) Point 4(221, 3347) 图2 Point 1(157, 213) Point 2(4572, 32) P

我在C#中的accord.net中玩,并试图对齐两个图像。我是计算机视觉新手,想知道accord.net是否能做到这一点,或者我是否必须自己写点东西

我有两张图片,每张图片我有四个点。从左上角so(TL、TR、BR、BL)开始,围绕图像逆时针分配点

例如:

图1

Point 1(221, 156)
Point 2(4740, 156)
Point 3(4740, 3347)
Point 4(221, 3347)

图2

Point 1(157, 213)
Point 2(4572, 32)
Point 3(4697, 3221)
Point 4(282, 3402)

在两幅图像中,图像1的点1与图像2的点1相关,与其余点相同

所以我想做的是对齐两个图像,这样两个图像之间的比例、旋转和对齐匹配,最后叠加两个图像时,应该像这样:

到目前为止,我有这个,它可以用于旋转和对齐,但不缩放图像。从我的理解来看,RANSAC似乎对这份工作太过火了,因为我已经在关联这些要点了?另外,我想单独输出图像,以便进行进一步的图像处理

// Images
var img1Path = Path.Combine(filePath, "image1.jpg");
var image1 = new[] { new PointF(221, 156), new PointF(4740, 156), new PointF(4740, 3347), new PointF(221, 3347) };

var img2Path = Path.Combine(filePath, "image2.jpg");
var image2 = new[] { new PointF(157, 213), new PointF(4572, 32), new PointF(4697, 3221), new PointF(282, 3402) };

// Create Bitmaps
var img1 = new Bitmap(img1Path);
var img2 = new Bitmap(img2Path);

var ransac = new RansacHomographyEstimator(0.001, 0.99);
var homographyMatrix = ransac.Estimate(image1, image2);

var blend = new Blend(homographyMatrix, img1) { Gradient = false };
var result = blend.Apply(img2);

result.Save("out.jpg", ImageFormat.Jpeg);
谢谢

嗯, 假设你有4个精确对应的点-解决方案非常简单。您必须使用4个对应关系计算图像之间的单应透视变换(简称单应)。然后可以使用计算出的单应性扭曲第二个图像,使其正好位于第一个图像上。 您可以使用EmguCV轻松完成此操作。您有一个关于如何计算单应性并将其应用于图像的极好示例:
在这里,您可以将图像2视为源图像,将图像1视为目标图像。

答案是,有几个点是错误的,导致图像内容不缩放,这是一个愚蠢但值得庆幸的简单错误

其次,要让accord.net将输出保存为单独的图像,请使用以下代码:

var filter = new Rectification(homographyMatrix);
var result = filter.Apply(image);
result.Save("out.jpg", ImageFormat.Jpeg);
多亏了ezfn,我在emguCV中也得到了这个工作,但论坛帖子还没有完成,我找到了这个缺失的代码,现在完成了:

var srcImagePath = Path.Combine(FilePath, "image2.jpg");
var dstImagePath = Path.Combine(FilePath, "image1.jpg");

var srcImage = new Image<Bgr, int>(srcImagePath);
var dstImage = new Image<Bgr, int>(dstImagePath);

float[,] srcPoints = { { 221, 156 }, { 4740, 156 }, { 4740, 3347 }, { 221, 3347 } };
float[,] dstPoints = { { 371, 356 }, { 4478, 191 }, { 4595, 3092 }, { 487, 3257 } };

var srcMat = new Matrix<float>(srcPoints);
var dstMat = new Matrix<float>(dstPoints);

var homogMat = new Matrix<float>(3, 3);
var invertHomogMat = new Matrix<float>(3, 3);
var maskMat = new IntPtr();

var s = new MCvScalar(0, 0, 0);

// .Ptr?
CvInvoke.cvFindHomography(srcMat, dstMat, homogMat, HOMOGRAPHY_METHOD.DEFAULT, 3.0, maskMat);
CvInvoke.cvInvert(homogMat, invertHomogMat, SOLVE_METHOD.CV_LU);
CvInvoke.cvWarpPerspective(srcImage, dstImage, invertHomogMat, (int)INTER.CV_INTER_NN, s);

dstImage.Save("2.jpg");
var srcImagePath=Path.Combine(FilePath,“image2.jpg”);
var dstmagepath=Path.Combine(FilePath,“image1.jpg”);
var srcImage=新图像(srcImagePath);
var dstImage=新图像(dstImagePath);
float[,]srcPoints={{221,156},{4740,156},{4740,3347},{221,3347};
浮点数={371356}、{4478191}、{45953092}、{4873257};
var srcMat=新矩阵(srcPoints);
var dstMat=新矩阵(dstMat点);
var homogMat=新矩阵(3,3);
var invertHomogMat=新矩阵(3,3);
var maskMat=new IntPtr();
var s=新的MCvScalar(0,0,0);
//Ptr先生?
CvInvoke.cvFindHomography(srcMat、dstMat、homogMat、HOMOGRAPHY_METHOD.DEFAULT、3.0、maskMat);
CvInvoke.cvInvert(homogMat,invertHomogMat,SOLVE_METHOD.CV_LU);
CvInvoke.cvWarpPerspective(srcImage,dstImage,invertHomogMat,(int)INTER.CV_INTER_NN,s);
dstmimage.Save(“2.jpg”);

谢谢大家的帮助

虽然我对accord.net不太确定,但你可以使用EmguCV,它基本上是流行的OpenCV.fHi Damjan的.net版本,你可能有一个链接或详细信息来说明我将如何使用EmguCV吗?我相信ezfn对一切都做了正确的解释:)谢谢ezfn,我今天下午会尝试一下。您知道如何在accord.net中实现这一点吗?你也说很简单,你能举个例子说明它有多简单吗?如前所述,我是计算机视觉新手,非常想了解它是如何工作的。嗨,我引用的例子将实际说明在你的情况下它是多么简单。这是一个两行的解决方案,一旦你有了相应的点。让我们知道任何斗争。我不熟悉accord.net-但对于计算机视觉,我相信EmguCV是合适的。嗨,ezfn,该论坛上发布的解决方案大部分都在那里,但实际上缺少一个关键行:CvInvoke.cvInvert(homogMat,invertHomogMat,SOLVE_METHOD.CV_LU);