UV Unproject camera resection script: now version 0.9.3

UV Unproject is a Blender script for camera resection (camera matching). The script itself and a tutorial are available from my webpage.

The latest release of the script (0.9.2) is still for Blender 2.49 only; apart from any essential bugfixes, it should be the last release for that version. Porting to Blender 2.5x is planned to follow shortly.

Improvements over the previous (first) version include support for both off-centre perspective cameras (e.g. cropped photos, perspective drawings) and orthographic cameras, and finer control over optional mesh scaling.

Edit: 0.9.3 released

Best wishes,
Matthew

Hy MCollett,

Great thanks for your job! It’s a goog think for an architect like me!

But i have a traceback:
Compiled with Python version 2.6.2.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “C:\Users\Patrick\AppData\Roaming\Blender Foundation\Blender.blender\scr
ipts\UV Unproject\uv_unproject.py”, line 28, in <module>
import camera_resection
ImportError: No module named camera_resection

What do you mean about, please?

I have installed SciPy R 0.8.0 - 12/12/2011 for Python 2.6 (is installed on my laptop)
And NumPy too.

Very useful looking script! Can’t wait to see it in 2.5!

You’re welcome - thanks for the feedback.

ImportError: No module named camera_resection

Did you download and install both script files from the web page? The one called ‘uv_unproject’ is just the Blender interface; the real work is done in ‘camera_resection’, so both have to be present.

Best wishes,
Matthew

Hi MCollett,

Did you download and install both script files from the web page?

Yes

I have the solution: both must be in the scripts folder not in a folder xxx in the one!

When i run the script then the interface is displayed but if i choose and press ok, the console run and stop…

Compiled with Python version 2.6.2.
Checking for installed Python… got it!
Warning: invalid value encountered in divide
Warning: invalid value encountered in divide
Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “C:\Program Files\Blender Foundation\Blender.blender\scripts\camera_resection\uv_unproject.py”, line 106, in <module>
uvUnproject()
File “C:\Program Files\Blender Foundation\Blender.blender\scripts\camera_resection\uv_unproject.py”, line 97, in uvUnproject
scale=make_camera(model,(rescaleX.val,rescaleY.val,rescaleZ.val),offset.val,ortho.val,name.val)
File “C:\Program Files\Blender Foundation\Blender.blender\scripts\camera_resection\uv_unproject.py”, line 70, in make_camera
else: return perspective(r2,r3,rescale,offset,name)
File “C:\Program Files\Blender Foundation\Blender.blender\scripts\camera_resection\uv_unproject.py”, line 41, in perspective
f,shift,ext,scale = camera_resection.estimate(r2,r3,rescale,offset,False)
File “C:\Program Files\Blender Foundation\Blender.blender\scripts\camera_resection.py”, line 192, in estimate
int,ext,scale = closestCamera(renormal(centre2,scale2)Prenormal(centre3,scale3).I,offset)
File “C:\Python26\lib\site-packages
umpy\matrixlib\defmatrix.py”, line 850, in getI
return asmatrix(func(self))
File “C:\Python26\lib\site-packages
umpy\linalg\linalg.py”, line 445, in inv
return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
File “C:\Python26\lib\site-packages
umpy\linalg\linalg.py”, line 328, in solve
raise LinAlgError, ‘Singular matrix’
numpy.linalg.linalg.LinAlgError: Singular matrix

Where the problem is with my Blender 2.49a?
Pat

EDIT2: Eureka! I have understand why!
->Now ensure that you have syncing of edit mode and UV selection turned off. Select just the vertices you located correctly on the image
->you must add in your explaination: Select just the vertices “in the UV window!

Very well! i hope you can to Blender release 250 to update your script…

Byby
Pat

EDIT3: Chromoly can certainly help you about Blender system!
He is a strong coder for Blender Foundation…
www.youtube.com/user/chromolytube#p/u

Yes, I will do that; thank you for the constructive feedback. I’m glad the script is now working for you.

I suppose the script could be made to work on the vertices selected in the 3D view, but for consistency it should then be on the Mesh menu instead of the UV menu.

Best wishes,
Matthew

I suppose the script could be made to work on the vertices selected in the 3D view, but for consistency it should then be on the Mesh menu instead of the UV menu.

No, they are a bug in my release 2.55a rev33870.

Warning (difficult to explain):
In edit mode, nothing is displayed in the UV window when sync button isn’t checked, you must select all the point in the 3D view window to displayed the uv map but the points are not automatically selected in the uv window
So i had not selected all the points in the uv windows and too in the 3D view window before to run your script.

Voilà! I believe my explaination is clear now.

Best wishes,
Pat

Thank you very much for your script,

Congratulations and best wishes for this new year 2011,
Pat

MCollett, congratulations on the great script!
I’ve made some tests with recovering the camera information from the internal Blender camera and it gives pretty close results (less than unit of deviation which is normal).
Also works great with photos.
In the way it generates cameras it could be used for accurate image based modeling of buildings and other objects.
May I propose the following additional fetures:

  1. To check if a camera with the given name exists just to replace it’s position (maybe as an option to check)
    This will give the ability to use sequence of images and to key the camera’s parameters in separate frames instead of populating the scene with cameras.
  2. To orient the object instead of the camera (also as an option to toggle) with the same presumption if the object exists only to update it’s transformation.
    Maybe the second one is more difficult. But it seems you’re skilled programmer :slight_smile:
    I would really like to see a v1 in 2.49 before porting to 2.5.
    In any case this is one of the best scripts’ I’ve seen for the good old Blender 2.49.
    Thanks!

If I understand you correctly, this is just how unsynced UV selection mode has always worked and is (I assume) intended to work: only those points selected in the 3D viewer are displayed in the UV editor, and then all/some/none of those may be selected in the editor.

Best wishes,
Matthew

Thanks.

In the way it generates cameras it could be used for accurate image based modeling of buildings and other objects.

That’s mainly what I had in mind when writing it.

May I propose the following additional fetures:

  1. To check if a camera with the given name exists just to replace it’s position (maybe as an option to check)
    This will give the ability to use sequence of images and to key the camera’s parameters in separate frames instead of populating the scene with cameras.
  2. To orient the object instead of the camera (also as an option to toggle) with the same presumption if the object exists only to update it’s transformation.

As it happens, your first suggestion had occurred independently to me just shortly before reading your post, though not in the context of animation. I was using some generated cameras as sources for UVProject modifers, and realised that it would be nice not to have to reenter the camera name in the modifier every time I tweaked the camera position with the script.
No, there wouldn’t be anything very difficult about moving the object instead of the camera. You would still have to change the internal parameters of the camera though (i.e. focal length, offset if used).
So thank you, those are both good ideas and I will definitely look at including them (though I don’t want the option list to get too long :wink: ).

Best wishes,
Matthew

If I understand you correctly, this is just how unsynced UV selection mode has always worked and is (I assume) intended to work: only those points selected in the 3D viewer are displayed in the UV editor, and then all/some/none of those may be selected in the editor.

Yes but you say:
“In the UV editor, select just the vertices you have located correctly on the image”
There MORE THAN SIX if not the script scratch!
Before there, I thought six vertices only for the object.
Excuse my error but I found the solution.

Best wishes,
Pat

Version 0.9.3 of the UV Unproject script is now available from my webpage. This is still for Blender 2.49 only.

Changes from the previous version (0.9.2) include:-

  • An existing camera of the specified name is reused instead of a new one being created.
  • The camera clipping limits are automatically extended if needed to make the model visible.
  • A new option (as suggested by Syziph) to fix the camera and move the model instead.
  • More consistent treatment of existing object-level transforms (details below).
  • Better error handling.

Note that ‘more consistent’ is not the same as ‘perfect’. The primary function of placing a camera should now work correctly for a model with any combination of local and inherited object-level location, rotation and scaling. However, moving the model instead of the camera will not work reliably in the presence of anisotropic object scaling, and conversely scaling will not work reliably in the presence of object rotations; these limitations are unavoidable given the way object transforms compose in Blender.

Best wishes,
Matthew

Great!
Thanks for update and for considering my proposal!
Here is a quick model of Taj Mahal with some modifications :slight_smile:
I am sorry for the crappy render :slight_smile:
The original here:
http://picasaweb.google.com/lh/photo/DaJSgwowV4J7fQafU8icGw
Although this photo canot provide easyly at least 5 points on rectangle the script did amaizing job and the proportions are very close to the original image.

I didn’t quite understand about

More consistent treatment of existing object-level transforms

Is that mean the object rotation an scaling should be applied before running the script?

Nice example.

Although this photo canot provide easyly at least 5 points on rectangle the script did amaizing job and the proportions are very close to the original image.

I think I would have started with the box formed by the corner towers, assumed the base was square and just scaled in the Z-direction.

I didn’t quite understand about

[QUOTE]More consistent treatment of existing object-level transforms

Is that mean the object rotation an scaling should be applied before running the script?[/QUOTE]
Not any more :). In the previous version, object rotation and scaling sometimes caused errors in the camera resection, so it was always advisable to apply them. In this version, the camera parameters should be calculated correctly even if the object transforms have not been applied. (However, it is still best to apply any existing rotation before scaling the model, and vice versa.)

Best wishes,
Matthew