Image scaling Macro
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Image scaling Macro
I made a Macro for easy scaling of images in Image workbench. It works for images imported as planar image in the 3D space.
You need two points in the image that you know the distance between for the real object:
* run the Macro - a dialogue pops up
* click on the two points in the image that you know the true distance between
* Select the Image Plane in the tree view
* Enter the true distance in mm between the points in the text field of the dialogue and click OK
*The image is scaled and the dialogue closes.
(I have tried to make this version more user guiding and mistake safe than the earlier version I mentioned in an another forum tread)
You need two points in the image that you know the distance between for the real object:
* run the Macro - a dialogue pops up
* click on the two points in the image that you know the true distance between
* Select the Image Plane in the tree view
* Enter the true distance in mm between the points in the text field of the dialogue and click OK
*The image is scaled and the dialogue closes.
(I have tried to make this version more user guiding and mistake safe than the earlier version I mentioned in an another forum tread)
Re: Image scaling Macro
I tested the macro and it seems to work. I am not 100% sure of the use cases or if i am doing things as i should therefore you might share more info on that.
P.S. Thanks for sharing it.
P.S. Thanks for sharing it.
Re: Image scaling Macro
I made it as I found a drawing of the Pi Camera and wanted to make a camera house to attach a lens for macro photos. To do that I had to scale the image containing the drawing to the correct size in FreeCAD 3D pace. When the drawing is imported it is scaled 1 pixel equals 1 mm, way too large.
As I thought this will be a common task using the Image Workbench I took the time to write a general solution (rather than just calculating xSize and ySize by hand).
With the macro I:
import the camera image in Image Workbench 3D plane
Start the macro
mouse click upper left corner of the camera board
mouse click upper right corner of the camera board
Select the Image Plane in the tree view
Enters 25 (as the camera board is 25 mm across)
Presses Ok and the Image is scaled
Switches to Part design workbench and starts modeling
So the intended use is to scale imported drawings or images as base for modeling.
Possible improvements:
I did try to draw a line between the first point and the mouse pointer using DraftTracker when selecting points but got an DraftToolbox not found exception and skipped the attempt (rather than taking the time to figure out how it should be done...). It would be nice with a line thou.
Change the input to accommodate user preferenced units not only mm. How?
As I thought this will be a common task using the Image Workbench I took the time to write a general solution (rather than just calculating xSize and ySize by hand).
With the macro I:
import the camera image in Image Workbench 3D plane
Start the macro
mouse click upper left corner of the camera board
mouse click upper right corner of the camera board
Select the Image Plane in the tree view
Enters 25 (as the camera board is 25 mm across)
Presses Ok and the Image is scaled
Switches to Part design workbench and starts modeling
So the intended use is to scale imported drawings or images as base for modeling.
Possible improvements:
I did try to draw a line between the first point and the mouse pointer using DraftTracker when selecting points but got an DraftToolbox not found exception and skipped the attempt (rather than taking the time to figure out how it should be done...). It would be nice with a line thou.
Change the input to accommodate user preferenced units not only mm. How?
Re: Image scaling Macro
Thanks for additional explanation.
http://www.freecadweb.org/wiki/index.ph ... g_function
Should get you user set unit. As this is simple dialog therefore you could do the conversion yourself and appropriate unit mm/inch can be added when the dialog is created.
http://www.freecadweb.org/wiki/index.ph ... ing_a_lineIt would be nice with a line thou
http://www.freecadweb.org/wiki/index.ph ... g_function
Change the input to accommodate user preferenced units not only mm. How?
Code: Select all
unit = App.ParamGet("User parameter:BaseApp/Preferences/Units")
unit.GetInt("UserSchema")
Re: Image scaling Macro
Yes found these earlier. So you create a line object if you want a line between the last clicked point to the mouse-pointer. Then delete the object afterwards. Is that how I should do it?
Thanks! Now found the unit class. There is no standard unit handling function converting user units to internal mm? How about handling decimal formats (. or ,)?Should get you user set unit. As this is simple dialog therefore you could do the conversion yourself and appropriate unit mm/inch can be added when the dialog is created.
Edit: Used QLocale for format localisation.
-
- Veteran
- Posts: 2611
- Joined: Tue Feb 21, 2012 8:07 pm
- Location: Torino - Italy
Re: Image scaling Macro
Thanks,JAndersM wrote:I made a Macro for easy scaling of images in Image workbench.
I think that can be created the page "Macro_Scale_image" in the wiki
Re: Image scaling Macro
Another idea you probably could use Draft Dimension for this exact purpose.
Re: Image scaling Macro
Here is a new version using DraftTracker to create a line between the measurement points.
I do not understand, sorry.renatorivo wrote:I think that can be created the page "Macro_Scale_image" in the wiki
Re: Image scaling Macro
I tested it and it works as advertised.
http://www.freecadweb.org/wiki/index.ph ... os_recipes
You can apply for Wiki account and after publish the macro in Wiki section.JAndersM wrote:I do not understand, sorry.renatorivo wrote:I think that can be created the page "Macro_Scale_image" in the wiki
http://www.freecadweb.org/wiki/index.ph ... os_recipes
Re: Image scaling Macro
Ok, thanks