protected void addImage_Click(object sender, EventArgs e) { DigestRaw raw = new DigestRaw(); ph_image_digest(pathName.Text, 1, 1, ref raw, 180); Digest d = Digest.fromRaw(raw); ulong hash = 0; ph_dct_imagehash(pathName.Text, ref hash); string title = imageTitle.Text; string author = imageAuthor.Text; if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(author) && !title.Equals("Enter Title...") && !author.Equals("Enter Author...")) { ImageFingerprint image; if (!String.IsNullOrEmpty(d.id)) image = new ImageFingerprint(title, author, d.id.ToString(), d.coeffs, hash); else image = new ImageFingerprint(title, author, null, d.coeffs, hash); if (image.insertNewImage()) addImageResult.Text = "Image successfully added. Thank you for your contribution"; else addImageResult.Text = "Error in inserting image. Please try again later"; } else { addImageResult.Text = "Please fill in the appropriate fields to add an image into our database."; } addImageResult.Visible = true; }
public static Digest fromRaw(DigestRaw raw) { Digest d = new Digest(); d.id = raw.id; d.coeffs = new byte[raw.size]; Marshal.Copy(raw.coeffs, d.coeffs, 0, raw.size); return(d); }
protected void addImage_Click(object sender, EventArgs e) { DigestRaw raw = new DigestRaw(); ph_image_digest(pathName.Text, 1, 1, ref raw, 180); Digest d = Digest.fromRaw(raw); ulong hash = 0; ph_dct_imagehash(pathName.Text, ref hash); string title = imageTitle.Text; string author = imageAuthor.Text; if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(author) && !title.Equals("Enter Title...") && !author.Equals("Enter Author...")) { ImageFingerprint image; if (!String.IsNullOrEmpty(d.id)) { image = new ImageFingerprint(title, author, d.id.ToString(), d.coeffs, hash); } else { image = new ImageFingerprint(title, author, null, d.coeffs, hash); } if (image.insertNewImage()) { addImageResult.Text = "Image successfully added. Thank you for your contribution"; } else { addImageResult.Text = "Error in inserting image. Please try again later"; } } else { addImageResult.Text = "Please fill in the appropriate fields to add an image into our database."; } addImageResult.Visible = true; }
protected void scanFile_Click(object sender, EventArgs e) { waiting.Visible = false; addImage.Visible = false; imageTitle.Visible = false; imageAuthor.Visible = false; addImageResult.Visible = false; if (uploadedfile.HasFile) { String fileName = uploadedfile.FileName; savePath += fileName; uploadedfile.SaveAs(savePath); string fileExtension = Path.GetExtension(savePath); if (fileExtension.Equals(".jpg") || fileExtension.Equals(".png")) { // Retrieve all fingerprint for comparison ImageFingerprint image = new ImageFingerprint(); ArrayList fingerprint = image.retrieveAllHashes(); int pcc = 0; ImageFingerprint matchingPictures = null; int highestPcc = 30; // Retrieve digest of input image for comparison DigestRaw raw = new DigestRaw(); ph_image_digest(savePath, 1, 1, ref raw, 180); Digest d = Digest.fromRaw(raw); // Compare fingerprint for (int i = 0; i < fingerprint.Count; i++) { // Generate a struct for comparison from database Digest d2 = new Digest(); d2.id = ((ImageFingerprint)fingerprint[i]).getDigestId(); d2.coeffs = ((ImageFingerprint)fingerprint[i]).getDigestCoeffs(); d2.size = 40; // Compare the results pcc = computeSimilarities(d.coeffs, d2.coeffs); if (pcc >= highestPcc) { matchingPictures = (ImageFingerprint)fingerprint[i]; highestPcc = pcc; } } // Compute hash values ulong hasha = 0; ph_dct_imagehash(savePath, ref hasha); if (matchingPictures == null) { int minHammingDistance = 20; for (int i = 0; i < fingerprint.Count; i++) { // Compute Hamming Distance int hammingDistance = computeHammingDistance(hasha, ((ImageFingerprint)fingerprint[i]).getHash()); if (hammingDistance < minHammingDistance) { matchingPictures = (ImageFingerprint)fingerprint[i]; minHammingDistance = hammingDistance; } } if (minHammingDistance <= 10) { result.Text = "An image has been identified with the following information:<br/><br/>" + "Title: <b>" + matchingPictures.getImageTitle() + "</b><br/>" + "Author: " + matchingPictures.getImageAuthor() + "<br/>" + "Hamming Distance: " + minHammingDistance + "<br/>"; } else { result.Text = "<b>No pictures has been identified in our database.</b><br/><br/>You can contribute by adding this image into our database."; pathName.Text = savePath; addImage.Visible = true; imageAuthor.Visible = true; imageTitle.Visible = true; imageTitle.Text = "Enter Title..."; imageAuthor.Text = "Enter Author..."; imageTitle.Attributes.Add("onfocus", "if(this.value == 'Enter Title...') this.value='';"); imageTitle.Attributes.Add("onblur", "if(this.value == '' || this.value == ' ') this.value='Enter Title...'"); imageAuthor.Attributes.Add("onfocus", "if(this.value == 'Enter Author...') this.value='';"); imageAuthor.Attributes.Add("onblur", "if(this.value == '' || this.value == ' ') this.value='Enter Author...'"); } } else { result.Text = "An image has been identified with the following information:<br/><br/>" + "Title: <b>" + matchingPictures.getImageTitle() + "</b><br/>" + "Author: " + matchingPictures.getImageAuthor() + "<br/>" + "Similarities with copyrighted image: " + (highestPcc / 40.0) * 100 + " %<br/>"; } result.Visible = true; } else { waiting.Text = "Incorrect file format has been used. Only jpg and png files will be accepted."; waiting.Visible = true; } } else { waiting.Text = "No file has been selected for analysis"; waiting.Visible = true; } }
public static extern int ph_image_digest(string file, double sigma, double gamma, ref DigestRaw digest, int N);
public static Digest fromRaw(DigestRaw raw) { Digest d = new Digest(); d.id = raw.id; d.coeffs = new byte[raw.size]; Marshal.Copy(raw.coeffs, d.coeffs, 0, raw.size); return d; }