2012年6月22日星期五

Loading official python wrapper of OpenCV 2.4 on windows

In the last few days I have spent quite a few time on using OpenCV in a project. For verifying the algorithm rapidly I try to utilize the python binding on OpenCV.

I got the latest OpenCV  trunk with official svn (so I guess its some version just after the 2.4.1) unfortunately after buiding and installing with VS2008 on my win7 64 laptop, I always  got
ImportError: DLL load failed: The specified module could not be found
when I try to use "import cv2".

After looking around the Internet, most of the related pages only mentioned that I should include the path contains cv2.pyd into the PYTHONPATH variable. Considering that the installation process has already copied needed pyd files into PYTHON_ROOT/lib/site_packages, the solution definitely doesn't make any sense for me.
Because when there is no cv2.pyd under PYTHON_ROOT/lib/site_packages the import cv2 reports that "no modules named cv2", definitedly the python interpreter has found the cv2.pyd and has tried to load it but failed. Then what are the things cv2.pyd depends on but missing? the tool dependency walker shows that cv2.pyd depends on a groupd opencv dlls. So here we got the answer, the interpreter failed to find these dlls because the path hold them was not listed within PATH variable. After adding the path to PATH, the import cv2 works.
P.S. Dependency walker is a good tools, but on win7 it also report some information may misleading the analysis. E.g, it also report that some other system/ms vc runtime dlls, such as gpsvc.dll, ieshims.dll, sysntfy.dll were missing when checking the cv2.pyd. Those error messages waste me hours to find out that those things do nothing with the real problem.