Forum

Author Topic: How to use external python libraries in PhotoScan?  (Read 14853 times)

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
How to use external python libraries in PhotoScan?
« on: February 06, 2015, 04:44:57 PM »
Hi,
   could you tell me what is needed to setup and use external python libraries in photoscan scripts. More precisely, we are interested to use opencv.

Thank you in advance.

Best regards,
Srdjan

nickc

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #1 on: February 06, 2015, 08:14:04 PM »
You cant access external libraries for Photoscan, the scripts need to be executed from the Photoscan console with the application opened.

I was able to create a work around for this... Write your script and set it up so that the script is in the "start directory" and assign a hot key for it...( run at start directory is usually; user\AppData\Local\Agisoft\PhotoScan Pro\scripts) then write another script to open agisoft and press the hot key associated with the start up script. i used win32 library for the hot key selection. This allows you to do things before and after Photoscan does its thing.

hope that helps...
« Last Edit: February 06, 2015, 08:22:36 PM by nickc »

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #2 on: February 10, 2015, 10:26:36 AM »
Thanks, but that is not what I need. I need to use opencv from python scripts, so since PhotoScan comes with their own python (ver 3.3) I need to know where to copy the library (pyd) and what else I need to do to use opencv from the script

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #3 on: February 10, 2015, 11:49:32 AM »
Hello smihic,

You can try copying unpacked (or installed) external libraries/modules to the following folder (if you are using Windows):
C:\Program Files\Agisoft\PhotoScan Pro\python\
Best regards,
Alexey Pasumansky,
Agisoft LLC

smihic

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #4 on: February 10, 2015, 01:15:06 PM »
Hi Alexey,
   thank you for the help. This folder you've mentioned has two subfolders: DLLs and Lib (on Windows). So where do I have to copy and what to copy? Is it enough to just pyd file or I need to copy DLL as well (in same directory DLLs?)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #5 on: February 10, 2015, 01:22:19 PM »
Hello smihic,

Just create new folder next to DLLs and Lib and put the corresponding files there.

Haven't tried it with OpenCV though, but some modules I've tested were working in this way (like sql-alchemy, tcl and etc.).
Best regards,
Alexey Pasumansky,
Agisoft LLC

Harybald

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #6 on: March 03, 2015, 01:04:38 PM »
I was able to create a work around for this... Write your script and set it up so that the script is in the "start directory" and assign a hot key for it...( run at start directory is usually; user\AppData\Local\Agisoft\PhotoScan Pro\scripts) then write another script to open agisoft and press the hot key associated with the start up script. i used win32 library for the hot key selection. This allows you to do things before and after Photoscan does its thing.
You can check out our latest Testking ibm certification and written by our ielts exam to help

ClaytonJohnson

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #7 on: May 11, 2015, 05:16:50 AM »
Hi Smihic,

I was just wondering if you have succeeded in using OpenCV in Photoscan. Hopefully you can save me a lot of trouble  :D

Cheers,
Clayton

simon_29

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #8 on: July 01, 2016, 03:40:14 PM »
Hi everybody,

I have been trying to add some external packages to the PhotoScan Python distribution. I managed to add a package called "utm" but I haven't been able to add the numpy package. In attachment I put some printscreens that point out the error I get from PhotoScan.

It seems like my numpy package is incomplete or that Photoscan can't find some files. I downloaded my numpy package directly from the numpy website "http://www.numpy.org".

If anyone knows why it is not working for the numpy package and could help me, I will be very grateful.

Thanks in advance.

Simon

william

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #9 on: September 21, 2016, 12:35:16 AM »
For my part, I was able to include external python packages by simply replacing the folder ~/photoscan-pro/python/lib/python3.3 with a symbolic link to my own python3.3 installation: ~/anaconda3/envs/agisoft/lib/python3.3.

I haven't encountered any issues so far, although I will report here if I do. Of course a symbolic link is not necessary; you could just copy your whole python3.3 folder.

(I am using conda environments to manage my python, but I bet one could do the same with vanilla python. Just find that corresponding python3.3 folder! I do think the easiest way to do this is likely by means of conda environments, though.)

Needless to say you'll need to install into your own environment the packages needed by PhotoScan, for this to work.

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #10 on: September 21, 2016, 10:45:30 AM »
I succeeded installing Numpy into Photoscan and it is actually fairly easy. You just have to know how packages are installed.

So the idea is to use a distinct Python 64 bit (same version as embedded by Photoscan, 3.3 at the moment) to prepare the required packages as they need to be compiled. This step is straightforward on linux but not on Windows if there is no wheel on Pypi for the appropriate version of Python but you can use the repo of the mingwpy project (https://anaconda.org/carlkl/repo?type=pypi) to install some packages for Python 3.3.
Once the package is installed, simply copy the associated files from the Python/virualenv install from PYTHON/Lib/site-packages/ to Photoscan folder PHOTOSCAN/python/Lib/site-packages/ and voilĂ .

Guilhem

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #11 on: November 27, 2017, 11:51:30 AM »
I had the same problem and William's solution worked for me ! I had to install the exactly same Python version (3.5.2 today) and replaced the python folder in "photoscan-pro" folder by a link to the external python install.

To get external python folder, in a terminal :
python3.5 (or yours)
import sys
sys.path

and then create a link (in ubuntu)

ln -s FROM_PATH TO_PATH

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #12 on: November 27, 2017, 12:02:25 PM »
Hello Guilhem,

With the versions 1.3 and 1.4 it should be easier to install the external modules to PhotoScan Python, please check the following article:
https://agisoft.freshdesk.com/solution/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge
Best regards,
Alexey Pasumansky,
Agisoft LLC

photoscan_user

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #13 on: May 14, 2018, 06:19:34 PM »
Get this errors on Ubuntu 14.04 and photoscan-pro-1.4.1:

./photoscan-pro-1.4.1/python/bin/python3.5 -m pip install numpy
Collecting numpy
  Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) - skipping
  Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

./photoscan-pro-1.4.1/python/bin/python3.5 -m pip install -U pip
Cache entry deserialization failed, entry ignored
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) - skipping
Requirement already up-to-date: pip in /home/user/photoscan-pro-1.4.1/python/lib/python3.5/site-packages

photoscan_user

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: How to use external python libraries in PhotoScan?
« Reply #14 on: May 15, 2018, 07:16:27 PM »
Copying site-packages works:

conda create -n py3.5.2 python=3.5.2 anaconda
source activate py3.5.2
pip install numpy

(py3.5.2) $ python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.14.3'

rm -r  /home/user/photoscan/python/lib/python3.5/site-packages
cp -r /home/user/anaconda3/envs/py3.5.2/lib/python3.5/site-packages /home/user/photoscan/python/lib/python3.5/site-packages