Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Hướng dẫn mình cách làm và những gì cần tìm hiểu

10:39 21-03-2018 475 lượt xem 10 bình luận 01:31 27-03-2018

Tìm hình ảnh mẫu trong kho dữ liệu (200.000 bức ảnh) hoặc trong 1 video đã quay trước đó.

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
K9 SuperAdmin, KquizAdmin, KquizAuthor đã bình luận 11:23 21-03-2018

đầu tiên cần làm ra 1 hàm tìm 1 ảnh có tồn tại trong ảnh hay k

Sau đó duyệt hết kho hình để ra kết quả

Video thì video có frame. lấy ra từng frame của video để so như so hình

Chi Hoang đã bình luận 01:31 27-03-2018

Em cám ơn m.n ạ !

C# learner đã bình luận 17:27 22-03-2018

Sao để lấy được 1 frame của Video?

whynotme8998 đã bình luận 18:52 24-03-2018

Cách 2. Nó so sánh không nhanh như cách 1 sử dụng biến con trỏ

 

byte[] image1Bytes;
byte[] image2Bytes;

using(var mstream = new MemoryStream())
{
    image1.Save(mstream, image1.RawFormat);
    image1Bytes = mstream.ToArray();
}

using(var mstream = new MemoryStream())
{
    image2.Save(mstream, image2.RawFormat);
    image2Bytes = mstream.ToArray();
}

var image164 = Convert.ToBase64String(image1Bytes);
var image264 = Convert.ToBase64String(image2Bytes);

return string.Equals(image164, image264);
whynotme8998 đã bình luận 18:51 24-03-2018
private Bitmap image1;

private Bitmap image2;

public Form1()
{
    this.InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
    using (var openDialog = new OpenFileDialog())
    {
        if (openDialog.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        this.DisposeImage1();
        this.image1 = new Bitmap(openDialog.FileName);
    }

    this.pictureBox1.Image = this.image1;
}

private void button2_Click(object sender, EventArgs e)
{
    using (var openDialog = new OpenFileDialog())
    {
        if (openDialog.ShowDialog() != DialogResult.OK)
        {
            return;
        }

        this.DisposeImage2();
        this.image2 = new Bitmap(openDialog.FileName);
    }

    this.pictureBox2.Image = this.image2;
}

private void button3_Click(object sender, EventArgs e)
{
    MessageBox.Show(Compare(this.image1, this.image2) ? "Same Image." : "Different Image.");
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
    this.DisposeImage2();
    this.DisposeImage1();
}

private static bool Compare(Bitmap bmp1, Bitmap bmp2)
{
    // Test to see if we have the same size of image
    if (bmp1.Size != bmp2.Size)
    {
        return false;
    }

    var rect = new Rectangle(0, 0, bmp1.Width, bmp1.Height);
    var bmpData1 = bmp1.LockBits(rect, ImageLockMode.ReadOnly, bmp1.PixelFormat);

    try
    {
        var bmpData2 = bmp2.LockBits(rect, ImageLockMode.ReadOnly, bmp1.PixelFormat);

        try
        {
            unsafe
            {
                var ptr1 = (byte*)bmpData1.Scan0.ToPointer();
                var ptr2 = (byte*)bmpData2.Scan0.ToPointer();
                var width = 3 * rect.Width; // for 24bpp pixel data

                for (var y = 0; y < rect.Height; y++)
                {
                    for (var x = 0; x < width; x++)
                    {
                        if (*ptr1 != *ptr2)
                        {
                            return false;
                        }

                        ptr1++;
                        ptr2++;
                    }

                    ptr1 += bmpData1.Stride - width;
                    ptr2 += bmpData2.Stride - width;
                }
            }
        }
        finally
        {
            bmp2.UnlockBits(bmpData2);
        }
    }
    finally
    {
        bmp1.UnlockBits(bmpData1);
    }

    return true;
}

private void DisposeImage1()
{
    if (this.image1 == null)
    {
        return;
    }

    this.pictureBox1.Image = null;
    this.image1.Dispose();
    this.image1 = null;
}

private void DisposeImage2()
{
    if (this.image2 == null)
    {
        return;
    }

    this.pictureBox2.Image = null;
    this.image2.Dispose();
    this.image2 = null;
}

Câu hỏi mới nhất