1

I've been trying to build pHash(http://phash.org/) on my windows machine and haven't been having any luck. I'm new to programming desktop applications. I will be using the pHash library with Python through ctypes. Could someone post the steps involved with building pHash?

What I tried, was opening pHash.sln with Visual Studio 2008 and chooing the Release(as opposed to debug) and building pHash. I wasn't sure where it was building to as I couldn't find the file. I tried looking in Visual Studio's projects folder but it wasn't there so I assumed it was building to pHash/release/pHash.dll, but when I load that dll with ctypes.cdll none of the functions listed in the pHash docs(http://phash.org/docs/howto.html) seem to be accessible, e.g. ph_dct_imagehash(), ph_dct_videohash.

Here is an example of my code:

import ctypes
import inspect

PHASHPATH = "C:\Users\me\Downloads\phash\release\pHash.dll"
phash_dll = ctypes.CDLL(PHASHPATH)
phash_dll['ph_dct_imagehash']

The response I get is:

Traceback (most recent call last):
  File "C:\Users\me\workspace\project\src\opencv.py", line 12, in <module>
    phash_dll['ph_dct_imagehash']
  File "C:\Program Files (x86)\Python27\lib\ctypes\__init__.py", line 371, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'ph_dct_imagehash' not found

I'm new at this, so please bear with me. Thanks.

EDIT: I'm running Python 2.7.

user594044
  • 255
  • 2
  • 4
  • 13

1 Answers1

3

Except for some dirent functions, no pHash functions are exported from pHash.dll. That can be verified with DependencyWalker http://www.dependencywalker.com/. Try adding __declspec(dllexport) in front of the function declarations in pHash.h (e.g. for ph_dct_imagehash) and recompile.

cgohlke
  • 9,142
  • 2
  • 33
  • 36
  • I did that with ph_dct_imagehash and it now shows up in dllexport list of functions. But now Python Ctypes is saying it can no longer find that module even though the file name and location has not changed. – user594044 Apr 05 '12 at 06:38
  • Is it still possible to build pHash in Windows? phash.org only lists a Linux download... arguably this might be built in the WSL, which did not exist when this question was answered - but even then, trying to link from outside WSL might be problematic. – Michael Apr 03 '18 at 01:37