brandonmpetty / Doxa

A Local Adaptive Thresholding framework for image binarization written in C++, with JS and Python bindings. Implementing: Otsu, Bernsen, Niblack, Sauvola, Wolf, Gatos, NICK, Su, T.R. Singh, WAN, ISauvola, Bataineh, Chan and Shafait.
https://brandonmpetty.github.io/Doxa/WebAssembly
Creative Commons Zero v1.0 Universal
167 stars 37 forks source link

building with Pybind11 on Windows #14

Closed SB2020-eye closed 3 years ago

SB2020-eye commented 3 years ago

Hi again, @brandonmpetty!

You helped me get the 'R' version going back in August, and then recently kindly chimed in on an old issue I raised on @paulbauriegel's cython doxa (https://github.com/paulbauriegel/doxa_cython). (Ty!)

I am trying to build doxa with pybind11 per the readme in your repo.

When i get to the cmake .. step (in Windows 10, Visual Studio Code), I get The term 'cmake' is not recognized as the name of a cmdlet, function, script file, or operable program I tried adding the cmake extension. But no difference. (Disclaimer: any time I've tried to do anything with c-anything, I've had little success -- typically more complicated than I really know how to do, hours spent, and very little results. I'm more at the level of "pip install" and the like. :) )

paulbauriegel commented 3 years ago

You need to install cmake: https://cmake.org/download/

brandonmpetty commented 3 years ago

You can also grab a free version of Visual Studio 2017 and above... it comes with CMake, NMake, etc. You can then open the x64 Native Tools Command Prompt for Visual Studio to run the commands. Also, for better or for worse, I am shipping the windows pyd file here: https://github.com/brandonmpetty/Doxa/tree/master/Bindings/Python/dist

I put together a python demo showing how one could use it, in this repo. That might be useful if you only want to use the library, not add to it or refactor it in anyway. In that case, you would need to get the build down. Let me know if you are still running into issues and I can look into getting it working with VSCode.

SB2020-eye commented 3 years ago

Once again, thank you so much @paulbauriegel and @brandonmpetty.

Prior to seeing your comment, @brandonmpetty, I tried downloading cmake, which then evidently needed, well, more. (This has been my previous bane with anything c. Granted, the problem is me + a lot of info out there + little individualized training or guidance.) Given my searches online (probably faulty themselves), the best route "seemed" to be to work with msys2, and then mingw. I got them installed (after hours). But then came across other errors when trying to go through the doxa steps. (I recall something about "CXX", for example, but there was much more -- a long message...yet still little comprehended by me. ha!)

I decided to go the visual studio route. (I saw this some along the way, but avoided it up to this point given past befuddlement with it, as well.) Things went much more smoothly, relatively speaking. I got through the steps in the doxa pybind "readme" with no errors. (Caveat: I don't understand what the "release" statements are at beginning and end, even though I tried looking that up. So I just left them out.)

Now I'm trying to run the demo. After installing PIL and numpy, I still get this: ModuleNotFoundError: No module named 'doxapy' Do you know why this is? I did cd into the demo folder, but still am getting this. (Is this just one of those things where I need to add some kind of .. or a fuller address to the import line in the demo.py file, perhaps? Idk, of course. But I've had something along those lines with other github packages.)

PS I am only seeking to use doxa, @brandonmpetty, not add or refactor it. I sure wish I had something to add! But I think you can gather that that is not exactly my wheelhouse. :)

paulbauriegel commented 3 years ago

@SB2020-eye What worked for me is adding the path to the pyd to the path:

import sys
sys.path.append('C:\\Users\\Paul\\Documents\\Doxa\\Bindings\\Python\\build\\Release')
import doxapy

Also, the build version in dist is 3.7. So if you have a different Python version you need to build it yourself.

brandonmpetty commented 3 years ago

You can also copy the pyd file into the demo folder. For example, to run the demo, look at the setup.sh script. It will copy over a few sample images and the .pyd file. If you have the pyd file in the same folder as your python script, it will pick it up automatically.

As for "Release", that was taken from the Pybind11 documentation. I assume it tells the system to do a "Release" build which may turn on optimizations and strip out debug symbols.

brandonmpetty commented 3 years ago

I may remove the .pyd file from the repo. I was under the impression that different minor versions of python could still use it. Apparently it is possible if you build with py_LIMITED_API set. Sadly, this is not supported in Pybind11, which this repo is using: https://github.com/pybind/pybind11/issues/1755

SB2020-eye commented 3 years ago

Thanks, guys.

I added my path to demo.py. (That makes sense, @paulbauriegel!) And I changed to Python 3.7. (It added 3.7.9, if that makes any difference.) But I get the same output.

SB2020-eye commented 3 years ago

@brandonmpetty, does your 2nd comment mean I shouldn't try moving the pyd file? I'm going to give it try now. But I'd also like to know for the long run, in case the repo changes, etc.

SB2020-eye commented 3 years ago

copying the .pyd file to demo->python folder seems to have worked (or at least avoided that error). now i get FileNotFoundError: [Errno 2] No such file or directory: '2JohnC1V3.png' Do i need to add the full path? (and if so, just for me knowing more for the future, why don't these things 'talk to each other'?)

SB2020-eye commented 3 years ago

full address worked. thx!

brandonmpetty commented 3 years ago

Awesome! I think I'll change a few things around to make it easier to run the demo given the feedback. Basically, you should look at the setup.sh script in the demo folder. You want to run something like those commands to copy the images into the demo folder, along with the pyd file. The images need to be copied into the folder because the python script is looking for them in that folder using relative pathing. If you do that, you don't have to add the full path. The same thing applies the the pyd file. It is a library that Python does not know about, so for Python to pick it up you have to do one of three things. 1. Tell Python exactly where it is, as @paulbauriegel pointed out. 2. Copy it into the same folder as your script because Python will try to automatically look for any modules there. 3. Register it somewhere with Python so that it is accessible globally.