I'm trying to install opencv on my machine as explained in the book:
"Packtpub OpenCV Computer Vision with Python Apr 2013"
It says that in order to run kinect you need to compile openCV with some stuff in it, so I downloaded openCV .exe that extracts to a 3.2gb folder and proceeded with all the steps...
Used CMaker, used the compiler MinGW, and everything as the book said
Than it tells me to try running some examples... but when I try to run drawing.py as recommended by the book, and all the others, it says:
python drawing.py
OpenCV Python version of drawing
traceback< most recent call last>:
File "drawing.py", line 7, in
import cv2.cv as cv
ImportError: DLL load failed: Invalid access to memory location.
I saw a lot of people saying this problem is fixed by adding the path to the bin of openCV dlls to path...
how do I find out which dll name is missing so I can find the name of it and find the folder where it is?
I have a x64 computer but the book tells me to install everything x86 because it is harder to get some minor bugs, maybe a version incompatibility between openCV, compiler, cmaker, and python?
I've tried to add a lot of folders to "path" variable and it didn't work
please tell me how I find out which dlls are missing so I can search for them on the computer or some other way to solve this problem because I'm just out of ideas
I don't have a high enough rep to add a comment otherwise I would but something you can do is start python with the -v option.
doing that will add a bit more to the output console and it will cause the python VM to output where it is looking for things when it tries looking for things, especially when failures occur. I've found that to be helpful when trying to hunt problems such as path problems down.
It also sounds like you haven't got your paths setup correctly. Have you looked at ImportError: DLL load failed: %1 is not a valid Win32 application ? If a DLL was expected in a certain location but wasn't loaded or present but then 'called' via a LoadLibrary (without checking to see if it was actually loaded) that might cause such an error. It is probably the fault of the original DLL that failed to verify the subsequent DLL was loaded instead of just assuming the LoadLibrary call succeeded.
In addition to the python -v yourmodule.py
option you could also try running an strace (if you are on unix -- but it doesn't sound like you are). I used to use SoftICE on Windows for digging down deep. If you know the package or the DLL that is at the root of the problem, and have access to a dll export tool, you should be able to get a list of the dependencies the dll needs (external functions it relies on). Then you just need to know or find those functions it relies on from other DLLs. It's been awhile since I used to had do this sort of stuff all the time to locate functions in other DLLs but it is something that is entirely doable from a spelunkers perspective. But there are probably easier ways to go about it.
I'd start with the python -v approach first.
The DLLs you need are almost certainly the ones kept in opencv/build/x64/vc11/bin (this path will be different, but equivalent, based on whatever compiler you used). That's the only folder that needs to be added to your system path.
Make sure that if you have a 32-bit version of Python, you compile OpenCV with a 32-bit compiler. Open up Python and it tells you its architecture.
Also, try installing numpy+mkll instead of numpy from the link of binary packages binary package for numpy+mkll. I had the same error and this solution solved the problem for me.
if you have installed simple numpy, don't worry, open cmd in the directory where you downloaded the new package. use this:
pip install name_of_the_whl_file
or
pip3 install name_of_the_whl_file
it will automatically uninstall the old numpy and install numpy+mkll.
Also, always remmember to add import numpy statement in your code before import cv2 statement.
import numpy
import cv2
Hope it helps.
Related
I know there are ways of using Tensorflow in C++ they even have a documentation for it but I can seem to be able to get the library for it. I've checked the build from source instructions but it seems to builds a pip package rather than a library I can link to my project. I also found a tutorial but when I tried it out I ran out of memory and my computer crashed. My question is, how can I actually get the C++ library to work on my project? I do have these requirements, I have to work on windows with Visual Studio in C++. What I would love to is if I could get a pre-compiled DLL that I could just link but I haven't found such a thing and I'm open to other alternatives.
I can't comment so I am writing this as an answer.
If you don't mind using Keras, you could use the package frugally deep. I haven't seen a library myself either, but I came across frugally deep and it seemed easy to implement. I am currently trying to use it, so I cannot guarantee it will work.
You could check out neural2D from here:
https://github.com/davidrmiller/neural2d
It is a neural network implementation without any dependent libraries (all written from scratch).
I would say that the best option is to use cppflow, an easy wrapper that I created to use Tensorflow from C++ easily.
You won't need to install anything, just download the TF C API, and place it somewhere in your computer. You can take a look to the docs to see how to do it, and how to use the library.
The answer seems to be that it is hard :-(
Try this to start. You can follow the latest instructions for building from source on Windows up to the point of building the pip package. But don't do that - do this/these instead:
bazel -config=opt //tensorflow:tensorflow.dll
bazel -config=opt //tensorflow:tensorflow.lib
bazel -config=opt tensorflow:install_headers
That much seems to work fine. The problems really start when you try to use Any of the header files - you will probably get compilation errors, at least with TF version >= 2.0. I have tried:
Build the label_image example (instructions in the readme.md file)
It builds and runs fine on Windows, meaning all the headers and source are there somewhere
Try incorporating that source into Windows console executable: runs into compiler errors due to conflicts with std::min & std::max, probably due to Windows SDK.
Include c_api.h in a Windows console application: won't compile.
Include TF-Lite header files: won't compile.
There is little point investing the lengthy compile time in the first two bazel commands if you can't get the headers to compile :-(
You may have time to invest in resolving these errors; I don't. At this stage Tensorflow lacks sufficient support for Windows C++ to rely on it, particularly in a commercial setting. I suggest exploring these options instead:
If TF-Lite is an option, watch this
Windows ML/Direct ML (requires conversion of TF models to ONNX format)
CPPFlow
Frugally Deep
Keras2CPP
UPDATE: having explored the list above, I eventually found the following worked best in my context (real-time continuous item recognition):
convert models to ONNX format (use tf2onnx or keras2onnx
use Microsoft's ONNX runtime
Even though Microsoft recommends using DirectML where milliseconds matter, the performance of ONNX runtime using DirectML as an execution provider means we can run a 224x224 RGB image through our Intel GPU in around 20ms, which is quick enough for us. But it was still hard finding our way to this answer
All,
I'm working on a new C++ project for an embedded system. Part of the system is some legacy Python code that we'll need to interface too. I've already prototyped a C++ to Python interface using the various PyImport_ImportModule functions etc. provided by Python, and tested this on my host system (Ubuntu 64 bit 17.04).
However, the build system in the new project also tries to build all dependencies, so it builds Python 2.7.13 from source. The problem I am seeing is the interface code that used to work with the host system Python is not working with the newly built from source Python. The error I am seeing is "time.so: undefined symbol: PyExc_ValueError", and the .py file I'm trying to call from C++ does import time as one of the first few lines. I checked and time.so is present in the custom built Python and I did update LD_LIBRARY_PATH to include it, but this didn't help. At the end of the build for Python I do see these warnings, so perhaps one of them is relevant?
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
_tkinter bsddb185 bz2
dbm dl gdbm
imageop readline sunaudiodev
zlib
Can anyone suggest what to try next? We are not enabling any special options or using any non standard flags in the Python we're building from source (perhaps some extra settings are required)?
This is usually happening to either:
clean build required or
wrong libpython lib being linked. I would suggest to start with trying clean build and then double check your linking flags (make sure you build for Python-2.7 and link to Python-2.7 and not to say Python-3.* etc).
Also, please see this discussion, it looks like a very similar issue: https://www.panda3d.org/forums/viewtopic.php?t=13222
Edit: this also might be relevant: undefined symbol: PyExc_ImportError when embedding Python in C
I am trying to program in C++ using Eclipse. However, this requires Eclipse to work on different computers with a MinGW compiler installation everytime. I know that it will work if I install it on a computer and add the location to the PATH variable, but I want to know how to put the compiler onto my USB as well as the Eclipse program and make it work the same way.
It should be installed in such a way that Eclipse can find the compiler on my USB (without the PATH stuff and C drive installation) and compile my program successfully without giving a "Binary not found" error because it could not build my source code.
I've solved this problem with Eclipse Java and am completely able to write and compile Java code. However, I don't know how to do it for a C\C++ Eclipse. Can someone help me with this problem?
Thanks in advance!
You do not need to alter system-wide path variable to help Eclipse finding your compiler. Simply create a batch file, which modifies and exports PATH. For example, put the following in the same directory as eclipse executable:
set PATH=%PATH%;path-to-mingw-bin
your-eclipse-executable
Save it as, for example, StartEclipse.bat, and execute it. (of course your-eclipse-executable should be given relative to the working directory of the batch script, and path-to-mingw-bin must be an absolute path)
You can install your MinGW anywhere, not necessarily in C:\, so installing it shouldn't be a problem.
I'm trying to deploy my Qt application, and every I tried loading Qt5core.dll, and it gave me an error, saying something like "procedure entry point.... could not be found".
So I tried loading a different version that was on my machine, and all of them gave me a slightly different but similar error.
Any ideas anyone?
By the look of your question, I suspect you want to deploy your project on Windows as you have struggle to find the correct .dll files.
I usually use the Windows deployement tool from Qt (more info on their website here: windeployqt, it is located within the QTDIR/bin/ folder.
But it is very straightforward to use, I use it as follow:
windeployqt --release "C:\path\to\binary.exe"
You should then be able to deploy your app by copying the resulting output files from the previous command.
Got it! I was including Qt5Network.dll when I was trying something out, but forgot I no longer needed it. It was calling a procedure in Qt5Core.dll that wasn't in the version I was using.
I have embedded a Python 2.7.2 interpreter into a C++ application using the Python C API.
On the target machines, I can't guarantee a Python install, so I am trying to get the embedded interpreter to look at the folder where my application resides. So in the application diectory, I have the Lib, Libs and DLLs folder for Python.
In the code, I have used Py_SetPythonHome() an Py_SetProgramName() to get Python loaded and also to allow standard libraries to be installed.
One of the test scripts I'm using has:
import csv
import numpy
The csv line is now fine. Within the \libs directory I can see site-packages\numpy. But the import crashes on this line. I am using numpy 1.6.1 for this.
I think I might need to change the module search path - is this right and what is the best way to achieve this to allow third-party libraries like numpy to be accessible to my scripts? You can assume that I could produce an absolute path to the numpy directory if that would help.
EDIT: More information - I've managed to produce the traceback and the error I'm getting is in \numpy\core\_init_.py when it tries the line "import multiarray" with the error "ImportError: DLL load failed: The specified module connot be found". Checking the directory, I find a multiarray.pyd. Any thoughts?
I have exactly the same problem with you, when I use python C API to import numpy. Some .pyd modules cannot be imported. When I changed to boost.python, there is no problem. Maybe you can try boost.python also. Here is sample:
This turned out to be a DLL mismatch error. The numpy version that the code was looking had a slightly different compilation route to that of my C++ code that was embedding the interpreter.
The resolution was to recompile numpy against the Python distribution that I'd used in my application, but using exactly the same compiler settings. This cleared the problem.