[英]Comapare two images using Emgu CV
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Util;
using Emgu.CV.GPU;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
Image<Bgr, Byte> modelImage = new Image<Bgr, byte>("box1_Same.png");//child
Image<Bgr, Byte> observedImage = new Image<Bgr, byte>("box2.png");//parent
Image<Bgr, Byte> observedImagae = modelImage.Cmp(observedImage, CMP_TYPE.CV_CMP_GE);
// Image<Bgr, Byte> Difference; //Difference between the two frames
//Difference = modelImage.AbsDiff(observedImage);
}
catch (Exception ex)
{
throw;
}
}
}
}
在上面的代碼中,我將CMP()方法用於兩個圖像的比較“如果傳遞兩個相同的圖像進行比較,則可以工作”。 如果傳遞兩個不同的圖像,則會出現以下異常“ OpenCV:src.depth()== dst.depth()&& src.size == dst.size”,我嘗試通過更改枚舉CMP_TYPE.CV_CMP_GE來解決,但給出了相同的問題
該錯誤消息告訴您,您將兩個大小不同的圖像放入了一個函數,該函數要求兩個輸入圖像都具有相同的尺寸。
如果您考慮此功能的作用,那么它應該很有意義。 該功能按像素比較兩個圖像。 您如何比較價值與沒有價值? 沒有定義,因此該函數不允許這種情況。
該函數斷言此表達式為true:
src.depth() == dst.depth() && src.size == dst.size
在其他任何事情發生之前。 在您的情況下,這是錯誤的,並且您的臉上會拋出異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.