opencv and eigenface recognizer, python - python

I'm playing with openCV in python. I'd like to use the eigenface algorithm to guess who's in a picture.
I tried with
recognizer = cv2.createEigenFaceRecognizer()
and it complains that
'module' object has no attribute 'createEigenFaceRecognizer'
I read around in the internet and found that the submodule 'face' should be used starting form openCV 3, but as I run
recognizer = cv2.face.createEigenFaceRecognizer()
it complains with a
'module' object has no attribute 'face'
I'm puzzled..
Thanks
AC
edit - how I installed it:
1. download openCV from http://sourceforge.net/projects/opencvlibrary
2. unpack to ~/opencv
3. download opencv_contrib from https://github.com/Itseez/opencv_contrib
4. unpack to ~/opencv/contrib
5. >cd ~/opencv
6. >mkdir tmp; cd tmp
7. >cmake -D -DOPENCV_EXTRA_MODULES_PATH=~/opencv/contrib/modules CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ~/opencv
8. >make -j5
9. >sudo make install

You might need to rebuild opencv together with extra modules as described here - opencv_contrib, if you didn't do it yet.

cmake -D -DOPENCV_EXTRA_MODULES_PATH
that "-D" is the cause of the error

Related

"fatal error: Eigen/Core: No such file or directory" while installing OpenCV on Ubuntu

I'm installing opencv for Python in Ubuntu 18.04 LTS from the official OpenCV release here https://docs.opencv.org/4.1.0/d2/de6/tutorial_py_setup_in_ubuntu.html
after creating the build directory and entering cmake ../ the moment I enter the command to make it's giving me the following error -
Previously I've used OpenCV on Windows. I'm new in Ubuntu. Please help.
In file included from /home/avi/opencv/modules/core/test/test_precomp.hpp:12:0,
from /home/avi/opencv/build/modules/core/opencv_test_core_pch_dephelp.cxx:1:
/home/avi/opencv/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
# include <Eigen/Core>
^~~~~~~~~~~~
compilation terminated.
modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/opencv_test_core_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:1287: recipe for target 'modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_test_core_pch_dephelp.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
Go to /home/avi/opencv/modules/core/include/opencv2/core/private.hpp file.
Edit the line: # include <Eigen/Core> to # include <eigen3/Eigen/Core>
Read more about this error from here.
Seems like OpenCV did not find Eigen where it was expecting.
Supposing you installed Eigen:
sudo apt-get install libeigen3-dev
The most correct way would be for you to specify to OpenCV where you installed Eigen by setting the variable EIGEN_INCLUDE_PATH, usually to \usr\include, but check your system.
Another option, instead of editing the OpenCV code, is to create some links between where you installed Eigen, and where OpenCV expects it to be:
cd /usr/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
I didn't find the solution for me in this post so I may as well share it if somebody comes by.
Problem : The include was looking for an include called Eigen while I installed Eigen3.
Solution : Create a soft link to create a directory called Eigen that redirect to Eigen3.
sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
https://www.programmersought.com/article/44372970691/

compilation of vtk with python wrapper

I'm trying to build the VTK library with python wrappers. I want to develop a python program to post-process some CFD results in VTK format.
I'm compiling the source in a local folder.
Unfortunately I'm facing several issues: firstly during the compilation I get the following error message:
CMake Error at Common/Core/cmake_install.cmake:47 (file):
file INSTALL cannot find
"/home/riccardo/Software/VTK/build/lib/libvtkCommonCore-8.0.so.1".
I tried to disable the option of shared libraries as suggested here VTK install error cannot find libvtkCommonCore-6.3.so.1
in the cmake configuration
cmake ..\
-DCMAKE_INSTALL_PREFIX=/home/riccardo/Software/VTK/build \
-DBUILD_SHARED_LIBS:BOOL=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_USE_SYSTEM_ZLIB:BOOL=ON
In this case the compilation went fine but when I tried to import vtk in python I get this error:
from .vtkCommonCore import *
42 from .vtkCommonMath import *
43 from .vtkCommonMisc import *
~/Software/VTK/build/Wrapping/Python/vtk/vtkCommonCore.py in <module>()
7 # during build and testing, the modules will be elsewhere,
8 # e.g. in lib directory or Release/Debug config directories
----> 9 from vtkCommonCorePython import *
ImportError: No module named 'vtkCommonCorePython'
I really don't know how to fix it.
Any help would be more than welcome.
Many thanks in advance!!!
Have you tried to tell CMake the python version you want to wrap?
That is, add:
-D VTK_WRAP_PYTHON:BOOL=ON \
-D VTK_PYTHON_VERSION:STRING=3.5 # or your python version
-D PYTHON_EXECUTABLE:PATH=\usr\bin\python3 # or wherever your python exec is
In the CMake configuration and see what happens.

Installing megam for NLTK on Windows

I need to install megam for nltk classification routines in Python.
I followed the instruction by Milk Magic from this post:
0. Downloaded megam source from http://www.umiacs.umd.edu/~hal/megam/index.html
1. Installed cygwin with gcc, make and ocaml packages
2. changed the makefile
3. when trying to compile megam with a makefile I receive an error with the following content
make
ocamldep *.mli *.ml > .depend
ocamlc -g -custom -o megam str.cma -cclib -lcamlstr bigarray.cma -cclib -lbigarray unix.cma -cclib -lunix -I /lib/ocaml/caml fastdot_c.c fastdot.cmo intHashtbl.cmo arry.cmo util.cmo data.cmo bitvec.cmo cg.cmo wsemlm.cmo bfgs.cmo pa.cmo perceptron.cmo radapt.cmo kernelmap.cmo abffs.cmo main.cmo
sh: flexlink: command not found
File "fastdot_c.c", line 1:
Error: Error while building custom runtime system
make: *** [Makefile:101: megam] Error 2
Do you know what the problem might be?
Maybe somebody has solved the same problem recently and could help.
As the error is
sh: flexlink: command not found
you need to find the package that contains it
$ cygcheck -p flexlink
Found 5 matches for flexlink
flexdll-0.34-1 - flexdll: Creates DLLs with runtime symbol resolution (installed binaries and support files)
flexdll-0.35-1 - flexdll: Creates DLLs with runtime symbol resolution (installed binaries and support files)
flexdll-0.35-2 - flexdll: Creates DLLs with runtime symbol resolution
...
So you need to install the flexdll package.
$ cygcheck -l flexdll |grep bin
/usr/bin/flexlink

While running code I am getting "init done opengl support available" as oputput message but I am not getting output images

While running code I am getting "init done opengl support available" as output message but I am not getting output images i.e. erosion and dilation. How should I get it?
import cv2
import numpy as np
img = cv2.imread('threshold.png',0)
kernel = np.ones((5,5),np.uint8)
erosion = cv2.erode(img,kernel,iterations = 1)
dilation = cv2.dilate(img,kernel,iterations = 1)
cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
cv2.imshow('erosion',erosion)
cv2.imshow('dilation',dilation)
print (erosion)
print (dilation)
Asuming you are on linux and using OpenCV 3.X (mine was 3.2), here is how I solved it:
1 Uninstall your current OpenCV version (you have how to do it here)
2 Download OpenCV again:
git clone https://github.com/opencv/opencv.git
3 Use the following commands:
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_QT=OFF -D WITH_TBB=OFF ..
make
sudo make install
It worked for me working under Ubuntu 14.04 and Python 2.7. You can find more information at the official webpage

error on installation of opencv does not make sense

when I run brew install opencv I get the following error:
Error: undefined local variable or method `which_python' for #<Formula opencv (stable) /usr/local/Library/Formula/opencv.rb>
naturally I went to check this out by opening up /usr/local/Library/Formula/opencv.rb. That showed the following ruby declaration:
def which_python
"python" + `python -c 'import sys;print(sys.version[:3])'`.strip
end
so which_python is clearly defined. Just to check and make sure that works, I opened up ruby to see if there was something wrong:
1.9.3-p194 :005 > def which_python
1.9.3-p194 :006?> "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
1.9.3-p194 :007?> end
=> nil
1.9.3-p194 :008 > which_python
=> "python2.7"
This verifies that which_python is defined correctly. Can somebody please explain why this error is occurring and what I can do to get around this.
I resolved this with:
rm /usr/local/Library/Formula/opencv.rb
brew update
brew doctor
brew install opencv
I'm not sure if removing opencv.rb is needed.

Categories