Just started working on creating a shapefinder application in a WPF app and I’m stuck at the first step!
I’m attempting to allow the user select a rectangle containing the part of the image that they would like to train to recognise. What’s the correct way to do this using WPF?
Currently I have a DisplayCanvas and RectSelectOverlay in the same grid
The type DisplayCanvas is itself a container for the overlays that operate on image coordinates, therefore the RectSelectOverlay in your example goes inside the DisplayCanvas (which makes the Grid.ColumnSpan obsolete):
Is that all that is required to get the selected rectangle data bound to ‘SelectedRect’? Are there any other steps that are required? I currently don’t have any hardware to capture an image but currently no rectangle is shown on the screen. I have set the stroke/strokethickness values on the RectSelectOverlay. a rough breakdown of the steps would be great if possible.
One thing to keep in mind is that the Display and DisplayCanvas use the information about the currently displayed (-)image to scale the overlays correctly (the overlays are displayed in image coordinates, see also https://forum.commonvisionblox.com/t/how-to-use-overlay-and-mouse-click-with-wpf-display-c/611). Conversely this means that if there is no image currently set on the Display.Image or DisplayCanvas.Image you won’t see anything because the display/display canvas does not actually know how to scale your overlay.
I’ve put together a very quick and even more dirty demo that shows the concept. Note that it’ll need TwoWay binding on the selected rectangle to work properly. SimpleDemo.zip (466.4 KB)
Really sorry, I keep on failing on what i presume is basic stuff, is there any other documentation I can look at for using shapefinder other than looking for other forum posts?
Please don’t be!!! First of all we don’t have anything yet in terms of tutorials or source code samples for the Stemmer.Cvb.ShapeFinder.dll, second the error reporting is not yet that great (what you saw was a Trace statement that fired…) and third you did in fact run into a bug! So it should in fact be me who is sorry.
I have built an updated version of the Stemmer.Cvb.ShapeFinder.dll (Version 1.8.0.x, 21.3 KB) for you - put it into your %CVB%\Lib\Net directory (replacing the previous version 1.6.0.x). Make sure to remove the obj and bin folder of your project - otherwise Visual Studio might cling to the older version of the DLL. I cannot promise that this was the last bug - test coverage for ShapeFinder is currently still fairly low for the preview build.
There is in fact also one thing I’d like to point out about your code which might be unintenional. The Learn method’s third parameter (teachWindow) is measured relative to the second parameter (position), which means that usually the rect’s Left and Top member are negative values which does not seem to be the case in your code.
One final remark: The Stemmer.Cvb.ShapeFinder.Classifier object is an animal that is rarely used because it is much less versatile than its sibling Stemmer.Cvb.ShapeFinder2.Classifier - the latter is capable of measuring rotation and scale (which the former will not report easily) and does report positions at a far better accuracy. ShapeFinder.Classifier might still have its place where every millisecond counts and pixel-accurate results are sufficient but most applications would benefit from the additional features of ShapeFinder2.Classifier.
Could you also send me the 1.30.0.0 version of the Stemmer.Cvb.dll as well please as I’m getting this error with the updated shapefinder dll. Thanks for the Learn method rectangle correction, I’ll make those changes.
Assembly 'Stemmer.Cvb.ShapeFinder' with identity 'Stemmer.Cvb.ShapeFinder, Version=1.8.0.0, Culture=neutral, PublicKeyToken=fe6400df9f0e0609' uses 'Stemmer.Cvb, Version=1.30.0.0, Culture=neutral, PublicKeyToken=bff841d173155285' which has a higher version than referenced assembly 'Stemmer.Cvb' with identity 'Stemmer.Cvb, Version=1.26.0.0, Culture=neutral, PublicKeyToken=bff841d173155285
Sorry @joseph.kirk, I built the fix versus the most recently released version of the CVB.Net wrappers (see download link from @parsd). The 1.26.0.0 version of the Stemmer.Cvb.dll dates back to March 2018 - I’d recommend getting the latest build instead (with which my update should work out of the box). I could send the more recent DLL of course, but then you’d also need a more up-to-date Stemmer.Cvb.Wpf.dll, Stemmer.Cvb.Extensions.dll and maybe more - you’re going to be at the point where updating would have been easier fairly quickly.
Hi @illusive, I’m finally working on the ShapeFinder2 application again and i’m coming back to the same trouble I was having before, training a classifier. I’m getting an empty exception when the ClassifierFactory tries to learn. See below;
Thanks for the update. I’ve added a hint to the exception message for the 13.2 release so that the exception won’t look that empty. Thanks for pointing it out!