Question: I'm in the feasibility stage of a project and wanted to know whether the following was doable using `Machine Vision`:

If I wanted to see if two files were **identical**, I would use a hashing function of sorts (e.g. `sha1` or `md5`) on the files and store the results in a database. 

However, if I have two images where say `image 1` is 90% quality and `image 2` is 100% quality, then this will not work as they will have different hashes.

Using machine vision, is it possible to "look" at an image and create a signature from it, so that when another image is encountered, we can say "have we already got this image in the system", and if so, disregard the new image, and if not, save the image?

I know that you are able to perform Machine Vision comparison between two known images, e.g.:

<https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/>

(there's a lot of code in there so I cannot simply paste in here for reference, unfortunately)

but an image by image comparison would be extremely expensive.

Thanks

Answer: 
If your enumeration will never stop producing results, it would be better to require the developer to be explicit about what is the maximum amount to be generated, so that you remove the risk of an infinite loop when the developer uses a `for each` syntax with your enumerable. e.g.

```
IEnumerable<T> ProvideCopies<T>(T original, int howMany) where T: IMyCloneable<T>
{
    return Enumerable.Range(1, howMany).Select(x => original.Clone());
}

```

or, if you're old school:

```
IEnumerable<T> ProvideCopies<T>(T original, int howMany) where T: IMyCloneable<T>
{
    for (var i = 0; i < howMany; i++)
        yield return original.Clone();
}

```

That way, the developer is **not** obligated to consume the entire enumeration and can stop at any time (i.e you're still *yielding* as you go) but you know it will stop at some point, rather than introduce the possibility of your code blocking forever in production because of a bug in the code.

---

If you truly can't tell how many copies will be needed and need to keep generating copies until something else tells you to stop, then `IObservable<T>` would be better suited for that scenario, as it's intended to be "listening" forever until you `Dispose()` of it.

> 
> [IObservable Interface](https://learn.microsoft.com/en-us/dotnet/api/system.iobservable-1?view=netframework-4.7.2)
> 
> 
>
Yes, I think it is bad practice indeed. Thread will not be able to process any other code paths. And this can put lot of burden on the processor.