Getting file location of user-selected file
Hello everyone,
In Image-Pro10.0.4 Build 6912, I am attempting to load a file directly to the "Global Recipe" as in the following post on this forum to automate smart segmentation.
https://forums.mediacy.com/discussion/comment/444#Comment_444
However in my case there is a need to change the input .isg file due to differences in the image sets examined (different lighting conditions, coloring, for instance). I could have users generate their own .isg file in the correct folder and rename it so the macro can find it, but I would prefer if I could use a dialog box to locate the file and get the file address somehow.
How could I go about doing this?
In Image-Pro10.0.4 Build 6912, I am attempting to load a file directly to the "Global Recipe" as in the following post on this forum to automate smart segmentation.
https://forums.mediacy.com/discussion/comment/444#Comment_444
However in my case there is a need to change the input .isg file due to differences in the image sets examined (different lighting conditions, coloring, for instance). I could have users generate their own .isg file in the correct folder and rename it so the macro can find it, but I would prefer if I could use a dialog box to locate the file and get the file address somehow.
How could I go about doing this?
0
Best Answer
-
Hi cjhung,
Yes, applying a recipe or measurement options require an image, so it should be done in LoopOn macro, but the selectiton of the file name can be done only once in RunBefore macro, like this:Public OptionsFileName As String ' global variable that contains file name and that is used by RunBefore and LoopOn macros Public Sub RunBefore() With Measure.Measurements.OptionsCommands.Open(Nothing) .FileName = "" .FilterIndex = 1 .Run(Nothing) OptionsFileName=.FileName'read selected file name Debug.Print(OptionsFileName)'just for checking End With End Sub Public Sub LoopOn() With Measure.Measurements.OptionsCommands.Open(Nothing) .FileName = OptionsFileName'use global file name set in RunBefore .FilterIndex = 1 .Run(ThisApplication.ActiveImage) End With 'add other steps to execute Count using the options loaded from OptionsFileName End Sub
Yuri0
Answers
If you are trying to apply a recipe from file to the active image, you can use RecoipeCommads.Open with empty FileName property, it will invoke File Open dialog:
Also, instead of ISG I would recommend using IQO files (Measurement Options) as it includes the recipe and all other segmentation properties, so you should resave your active recipes to IQO files (Measurements - Save options button) and then use this command to open IQO file with a prompt:
Public Function LoadSegmentationOptions() As SimpleScript LoadSegmentationOptions = New SimpleScript Dim doc1 With Application.DocumentCommands.Active(LoadSegmentationOptions) .Run(doc1) End With With Measure.Measurements.OptionsCommands.Open(LoadSegmentationOptions) .FileName = "" .FilterIndex = 1 .Run(doc1) End With End Function
Regards,
Yuri
In the "Run Before" step in batch processing, I am trying to load the ISG to the "Global Recipe" (I didn't know about IQO, will have to try it out) before having an image open like in the referenced forum post. I then call on Measure.SmartSegmentation.RecipeCommands.ApplyGlobal() in the "Loop On" macro.
In "Run Before", I am currently trying to use Measure.SmartSegmentation.RecipeCommands.Open() and Measure.SmartSegmentation.RecipeCommands.SetGlobal() to do this, but it doesn't seem to run properly without an image open.
To get around this, I tried to use the following as it works without an open image.
With Automate.ScriptingCommands.CodeCommand(Script) If .Run() Then ' load recipe to Global Dim globalRecipe As MediaCy.Addins.LearningSegmentation.SegmRecipe=MediaCy.Addins.LearningSegmentation.Globals.m_SegmRecipe Dim FileName As String=ThisApplication.Path(mcPathType.mcptConfigurationFiles) & "ISG.isg" globalRecipe.Load(FileName,MediaCy.Addins.LearningSegmentation.McLearningSegmentation.ThisAddin.LS.Options) End If End With
But I'm running into issues with the FileName since that may change. My thought is if I can have the user identify an ISG file, I could then feed the address into the above script.cjhung --
O:\ALCES\Media Cy Forum Misc\2024-04-30-172126 -- ISG FILE NAME QUESTION\
COOKIE.isg
O:\ALCES\Media Cy Forum Misc\2024-04-30-172126 -- ISG FILE NAME QUESTION\COOKIE.isg
I was able to make it work with the global variable. Thanks!