Additional features in Visual Verification

Jun 17, 2009 at 7:43 AM

Hello,

I've played a bit with the tool and found that some additional features related to Visual Verification, Image comparison etc would be useful:

- Excluding particular colour (or set of colours) from comparison, i.e. upon comparing 2 images I'd like to ignore some colour(s), so if there is a difference between pixels and one of them has the colour from Ignore List then the difference doesn't fail verification;

- Having analogue of .Contains(Snapshot sShot) method, means that you have 1 image and you need  to know whether it contains another sub-image (sizes are different).

Please let me know if I've missed something and all these already implemented or there are workarounds.

 

 

 

Jun 17, 2009 at 12:12 PM

Hello,

 

We don't explicitly support these scenarios right now, but fortunately there's no blockers for them either. I'll bring them up for discussion with the testapi team today. In the meantime:

 

For #1 - I see three styles of approaches here, which are all potential workarounds:

  • Roll your own- You could extend/create a comparison class which accepts a list of ignored colors.
  • Color based "Masking" - We support the notion of creating Mask images which can be AND'ed or Or'ed with an image to produce a new image.
    • You can create a new mask image which will excludes pixels from the actual image contained in your ignore list - this would look like a black and white image, with the ignored regions in black
    • You run a diff of the two images
    • You then post-process the diff with the mask: AND the mask against a diff image to only have a diff covering colors you cared about
  • (hacky but fast) You could overwrite ignore color pixels with colors from the actual image

 

For #2 - Containment - we haven't offered a solution to this yet. As a first cut, if you are purely talking about a purely translated sub-region you may want to implement a "contains" style comparison class which could do a brute force scan, while breaking out of each cycle when a given "location sequence" is clearly a mismatch. 

 

Thanks

Jun 18, 2009 at 7:16 AM

Thank you for the quick response and thanks a lot for your detailed suggestions, I'll definitely try them.

Jun 21, 2009 at 7:19 PM

NLord,

Thanks much for your suggestions. We are finalizing our next release (TestApi 0.3) right now, I have added your feature requests to the backlog for the next release (0.4).

Ivo

Apr 15, 2010 at 2:02 PM
Edited Apr 15, 2010 at 2:46 PM

As for the  "Having analogue of .Contains(Snapshot sShot) method, ..." - I wrote a proof-of-concept snippet, which might be useful, please find below:

		/// <summary>
		/// Searches for the sub-image inside the image using specified tolerance.
		/// Attention! Might be slow.
		/// </summary>
		/// <param name="image">
		/// Image to search in.
		/// </param>
		/// <param name="subImage">
		/// Sub-image to search for..
		/// </param>
		/// <param name="verifier">
		/// The <see cref="SnapshotVerifier"/> to use during the search.
		/// Allows to specify tolerance.
		/// </param>
		/// <returns>
		/// True if the image contains the sub-image.
		/// </returns>
		public bool IsImageContainsSubImage(Snapshot image, Snapshot subImage, SnapshotVerifier verifier)
		{
			int imgH = image.Height;
			int imgW = image.Width;
			int subH = subImage.Height;
			int subW = subImage.Width;

			if (subW > imgW || subH > imgH)
			{
				return false;
			}

			Snapshot temp1;
			Snapshot temp2;

			for (int row = 0; row < imgH - subH; row++)
			{
				for (int column = 0; column < imgW - subW; column++)
				{
					//// If current image pixel doesn't agree with the 1-st pixel of the sub-image then go further.
					temp1 = image.Crop(new Rectangle(column, row, 1, 1));
					temp2 = subImage.Crop(new Rectangle(0, 0, 1, 1));

					if (VerificationResult.Pass == verifier.Verify(temp1.CompareTo(temp2)))
					{
						//// If we've got 1 agreed pixel then let's verify the rest.
						temp1 = image.Crop(new Rectangle(column, row, subW, subH));
						if (VerificationResult.Pass == verifier.Verify(temp1.CompareTo(subImage)))
						{
							return true;
						}
					}
				}
			}
			
			return false;
		}

May 4, 2010 at 9:27 PM

Hello!

This is an elegant solution, and has you using whichever verifier you want, which is a really good idea.

We're going to finally share a FindSubImage method in TestAPI 0.5. It's geared for speed, so it doesn't re-crop the image, which requires a copy of image bits, and it's got an early bailout on any pixel mismatch. We're using it internally, right now, in fact. : D

Jun 22, 2010 at 8:04 AM

I've had a look at TestAPI 0.5 and new Find() methods in Snapshot and they look create. Thank you for the tasty piece!