The Right Way for Building Latest OpenCV for Python 2 x86

asked 2018-09-10 22:36:43 -0600

fifo_thekdi gravatar image

updated 2018-09-14 01:57:51 -0600

LBerger gravatar image

I've been building and using OpenCV with Java, Python,... bindings for more than a year without any problem. I've recently started working on a project where I need to build OpenCV for Python 2.7 x86 due to some old dependencies. I have Windows 10 with Visual Studio 2017. Where can I exactly make the switch to x86? I should make a new folder called build86 for example and use another compiler? Or create the Visual Studio solutions as usual and add x86/Win32 configuration?

What about other dependencies that I build before OpenCV (QT, VTK, Tesseract and Leptonica)? Should I build x86 versions before building OpenCV?

And last: how do you propose having DLL's for both 32 and 64 bit versions side by side?

edit retag flag offensive close merge delete

Comments

About 32 bits exe with 64 bits dll answer is here : you need to compile everything in 32 bits.

To compile opencv in 32 bits

select VS 15 2017

(Not VS 15 2017 win64)

LBerger gravatar imageLBerger ( 2018-09-11 01:00:59 -0600 )edit

I have always selected VS 15 2017, without the Win64 part and it has always produced a 64bit version

I can see that in the build configuration in Visual Studio, in the generated pyd file name,

and when I try installing and running the file with a 32bit version of Python.

It would simply give me an error about incompatible packages.

fifo_thekdi gravatar imagefifo_thekdi ( 2018-09-11 01:23:19 -0600 )edit

I try and result is

2>------ Build started: Project: ippiw, Configuration: Release Win32
3>------ Build started: Project: opencv_core_AVX, Configuration: Release Win32
4>------ Build started: Project: opencv_core_SSE4_2, Configuration: Release Win32 
5>------ Build started: Project: zlib, Configuration: Release Win32 
6>------ Build started: Project: ittnotify, Configuration: Release Win32
7>------ Build started: Project: opencv_imgproc_AVX, Configuration: Release Win32
8>------ Build started: Project: opencv_imgproc_SSE4_1, Configuration: Release Win32 
9>------ Build started: Project: libwebp, Configuration: Release Win32
LBerger gravatar imageLBerger ( 2018-09-11 02:00:43 -0600 )edit

in vs2017 python3 project check if platform is x86 in linker option. I think you will need a 32 bits version of python when you run cmake

LBerger gravatar imageLBerger ( 2018-09-11 02:05:18 -0600 )edit

You are right it did show x86. I added Python 2 paths to the configuration but for sum reason it did not appear in the summary of the CMake GUI. https://pastebin.com/81LCkTBm

And when I try to compile with Visual Studio I get the following errors: 14>opencv_core400.lib(persistence_cpp.obj) : error LNK2019: unresolved external symbol "public: void __thiscall cv::DefaultDeleter<struct cvfilestorage="">::operator()(struct CvFileStorage *)const " (??R?$DefaultDeleter@UCvFileStorage@@@cv@@QBEXPAUCvFileStorage@@@Z) referenced in function __catch$??$_Setpd@PAUCvFileStorage@@U?$DefaultDeleter@UCvFileStorage@@@cv@@@?$shared_ptr@UCvFileStorage@@@std@@AAEXPAUCvFileStorage@@U?$DefaultDeleter@UCvFileStorage@@@cv@@@Z$0 14>opencv_core400.lib(persistence_cpp.obj) : error LNK2019: unresolved external symbol

fifo_thekdi gravatar imagefifo_thekdi ( 2018-09-13 15:32:59 -0600 )edit

@berak can you read comments ? edit button for the question are on the right side

image description

LBerger gravatar imageLBerger ( 2018-09-14 01:15:01 -0600 )edit

@LBerger, lol, you broke it !

buggy layout is buggy.

already the title "hangs over"

berak gravatar imageberak ( 2018-09-14 01:31:41 -0600 )edit

and here is a related issue (to the question): https://github.com/opencv/opencv/issu...

berak gravatar imageberak ( 2018-09-14 01:32:59 -0600 )edit

I could compile it and run it sucessfully after the latest updates The biggest problem I faced was picking up the right version of Python since I had both 32bit and 64bit versions of Python 2 and 3 It looks like implicitly specifying the paths for include and lib was not enough as it was still looking for the paths in the PATH variable. I kept only one Python version in the PATH and everything worked as exptected Now I tried compiling with Intel performance libraries, specifically MKL, but I can't seem to find the 32bit version of the libraries. Do they exist?

fifo_thekdi gravatar imagefifo_thekdi ( 2018-09-15 18:28:37 -0600 )edit

So I reinstalled both the 32 and 64-bit version of Intel performance libraries and they were detected successfully and compiled without any problem thanks a lot!

fifo_thekdi gravatar imagefifo_thekdi ( 2018-09-15 19:36:38 -0600 )edit