【问题标题】:Finding shape of image within another image在另一个图像中查找图像的形状
【发布时间】:2020-11-22 05:22:05
【问题描述】:

我正在尝试确定在图像中查找形状位置的最佳方法。 我有一张带有白色轮廓的拼图图片。

我需要以某种方式在另一个给定图像中找到相同的白色轮廓,并能够输出边界框的位置。

最好的方法是什么? OpenCV、emgucv、ML?

例如。一块拼图 https://imgur.com/a/PJJ6ixL

谢谢

【问题讨论】:

  • 可以分享图片吗?
  • 添加样片

标签: c# opencv computer-vision emgucv


【解决方案1】:

对于我的回答,我假设您要检测的其他部分将具有与给出的示例部分相同的精确白色轮廓。我只是用emgucv中的find contours方法得到了拼图的轮廓。

//Read in the image
Mat puzzlePiece = CvInvoke.Imread("Puzzle\Piece\path", ImreadModes.AnyColor);

//Create a grayscale version of the image
Mat puzzlePieceGray = new Mat();
CvInvoke.CvtColor(puzzlePiece, puzzlePieceGray, ColorConversion.Bgr2Gray);

//Black image to draw contours on
Image<Bgr, byte> output = new Image<Bgr, byte>(puzzlePiece.Width, puzzlePiece.Height, 
    new Bgr(Color.Black));

VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

//Find and draw the found contours
CvInvoke.FindContours(puzzlePieceGray, contours, null, RetrType.External, 
    ChainApproxMethod.ChainApproxSimple);
CvInvoke.DrawContours(output, contours, -1, new MCvScalar(255, 0, 0));

//Display the found contours
CvInvoke.Imshow("Contours Drawn", output);
CvInvoke.WaitKey(0);

原图

带有轮廓的图像

由于只有您提供的输入图像,我无法将轮廓的大小与其他部分进行比较,但这里有一些示例代码,说明它是如何工作的。

if (contours[0].Size == contoursTwo[0].Size)
{
    //do stuff
}

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2015-07-17
    • 2012-02-05
    • 2023-03-12
    相关资源
    最近更新 更多