Forum

Author Topic: How to import OpenCV  (Read 5219 times)

soerentsch

  • Newbie
  • *
  • Posts: 4
    • View Profile
How to import OpenCV
« on: June 09, 2016, 11:48:04 AM »
Hey Forum,

Has anyone figured out how to import OpenCV?

Currently i failed by the import of numpy, seems i have to build a x64 numpy >_<

Cheers

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: How to import OpenCV
« Reply #1 on: March 01, 2017, 02:39:34 PM »
I have the same problem here, does anyone know where I can get a version of numpy that I can just copy to /lib/site-packages on Windows x64?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: How to import OpenCV
« Reply #2 on: March 01, 2017, 02:41:41 PM »
Hello stephan,

If you are using PhotoScan Pro 1.3, you can install the external modules running python.exe from PhotoScan Pro installation folder with the following parameters (for example, fr numpy module):

Code: [Select]
/Agisoft/PhotoScan Pro/python/python.exe -m pip install numpy
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: How to import OpenCV
« Reply #3 on: March 01, 2017, 03:19:35 PM »
Wow, that was quick and easy, thanks Alexey :)

v4ven27

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to import OpenCV
« Reply #4 on: May 30, 2017, 11:17:48 PM »
Hi Alexey,

I'm trying to add numpy with Photoscan version 1.3.2 on Ubuntu 16.04 by running the following command in the photoscan-pro/python/bin directory: 

Code: [Select]
./python3.5 -m pip install numpy
But I get the following error while:

Quote
Traceback (most recent call last):
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/runpy.py", line 133, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/site-packages/pip/__init__.py", line 16, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/site-packages/pip/vcs/subversion.py", line 9, in <module>
    from pip.index import Link
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/site-packages/pip/index.py", line 30, in <module>
    from pip.wheel import Wheel, wheel_ext
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/site-packages/pip/wheel.py", line 39, in <module>
    from pip._vendor.distlib.scripts import ScriptMaker
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/site-packages/pip/_vendor/distlib/scripts.py", line 14, in <module>
    from .compat import sysconfig, detect_encoding, ZipFile
  File "/home/ubuntu/photoscan-pro/python/lib/python3.5/site-packages/pip/_vendor/distlib/compat.py", line 66, in <module>
    from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler'

How can I resolve this issue? Thanks!

v4ven27

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to import OpenCV
« Reply #5 on: May 30, 2017, 11:32:49 PM »
I solved this issue by creating a symlink from the distribution numpy installation /usr/local/lib/python3.5/dist-packages/numpy to ~/photoscan-pro/python/lib/site-packages

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: How to import OpenCV
« Reply #6 on: February 15, 2018, 06:46:32 PM »
Hi all,

You can read about how to install numpy or other packages on the following page:
https://agisoft.freshdesk.com/solution/articles/31000136860-how-to-install-external-python-module-to-photoscan-professional-pacakge
 
It is impossible to use precompiled opencv-python package from PhotoScan on Linux, because opencv-python is compiled with Qt 4.8, while PhotoScan uses Qt 5.6, and this Qt versions conflict leads to crash on importing cv2 from PhotoScan.
 
But you can compile and add cv2 module to PhotoScan with this script:
https://gist.github.com/PolarNick239/fc02a69ae3082e72704d220e77abf4a0

Also you can refer to this post regarding the following questions:
- how to pass image from PhotoScan project to OpenCV,
- how to fix incorrect channels order (PhotoScan RGB to OpenCV BGR),
- how to display OpenCV image in window.
« Last Edit: February 19, 2018, 12:17:43 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC