Croping ForeHead only with Opencv python - python-3.x

i try to identify the forehead in my cropped image to identify the thermal image, Here are things i did
found a python code which uses "dlib" library
Dlib works only if i have cmake and cmake works only if i have visual studio
for installing dlib 19.19.0 and cmake 3.17.3 (They are obsolete compared with my python 3.8.2 ) i found errors during installation in
my windows 10 . error "c compiler identification unknown" (during dlib
installation) even though i had added cmake path to my env variable
i also tried pip install for dlib(not installed) and cmake (installed)
So are there any alternative solutions to fetch my " forehead only " python task ?

You can try anaconda to install python dlib. Then use face detection and eyebrow landmarks to crop forehead.
If you want to skip dlib then look into opencv facemark api but its in C++. In my last test with opencv 4.2.0 facemark LBF trained model was better then Kazemi for opencv. Further detail on LBF implementation,
https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
There is a python bindings repo for opencv facemark,
https://github.com/saiteja-talluri/GSoC-OpenCV
You can also look into python https://github.com/1adrianb/face-alignment, as it shows dlib was removed as requirement in commit log.

Related

Anaconda and upgrading to new M1 Mac

Background
I've just got a new M1 mac mini dev machine, and migrated from my old x86 mac using apple's migration assistant.
Doing that also copied over all my conda environments to the new machine (they were all in my home directory)
I installed the latest version of anaconda and anaconda plus all my python code and environments seem to work fine (this includes a bunch of wheel modules, notably numpy/scipy).
I did a bunch of googling for my questions below, but couldn't find any good answers anywhere - so I thought I'd ask SO as this seems like a quite common situation others will run into
Questions
Does anyone know the status of M1 native versions of python/numpy/scipy etc provided by conda forge?
I presume that all the binaries in my environments for python/numpy etc all still the old x86 versions, as they were all in environments in my home directory, and running via emulation. So, how do you go about changing/updating those to a M1 arm native
version if/when available?
A quick update as of July 2021.
TLDR
The conda-forge group have a M1 native conda installer here.
Installation is simple - run the installer, and you have conda up and running.
This will install an M1 native conda, and that conda's default environment will by default install M1 native python versions and M1 native versions of modules (if available).
There seem to be native osx M1 native wheels for most common modules now available on the conda-forge channel.
Current status
It seems Anaconda still do not have a native M1 version, nor does Miniconda. ...I can't figure out why it's taken so long and neither still seem to have native M1 support, but that's a separate issue.
Alternative
However, as steff above mentioned, conda-forge (as in the group responsible for maintaining the conda-forge channel) do have a installer for their version of conda that is itself both native M1, and also sets up your environment to pull M1 native wheels where available. This they call Miniforge.
Their github is here.
Various installers for their Miniforge (via direct download, curl or homebrew) can be found on their github page (above) - the direct link to the ARM native miniforge installer is here.
A quick search on conda-forge show's almost all common modules do now have native M1 wheels available. (look for supporting platform 'osx-arm64` eg numpy)
Caveats
I've not tested this too extensively yet, and I'm not sure exactly what happens if a non-M1 wheel is available (I believe it will default to downloading a no-arch version).
I'm also not sure/haven't tested whether you can mix and match M1 wheels with x86 mac wheels. (I'm guessing this would work, but haven't tried).
I also have only done minimal testing using the conda's pip, and how well it recognizes/tries to download/resolves M1 vs x86 pip packages.
The answer here is going to evolve over time, so here is the most up-to-date knowledge I have as of 27 Jan 2021.
Installing conda in emulation mode works completely fine. All you need to do is to install it in a Terminal run in emulation mode, or else install it using a Terminal emulator that has not been ported over yet.
Once your conda environments are up and running, everything else looks and feels like it did on x86 Macs.
If you'd like a bit more detail, I blogged about my experience. Hopefully it helps you here.
I got my M1 about 2 weeks ago and managed to install absolutely everything I need natively from conda-forge and pip. The installer you can download here.
As of 5Feb Homebrew is also officially supported on osx-arm64.
2022/03/02 answers
Native M1 installations are pretty simple now. Here are a few options for Miniforge and Miniconda.
(1) Using Apple's instructions for Tensorflow with Miniforge
This uses the same Miniforge solution mentioned above but includes an M1-optimized Tensorflow install, meaning TF has access to the M1 GPU cores.
Look for the "arm64: Apple Silicon" section at:
https://developer.apple.com/metal/tensorflow-plugin/
(2) Running native M1 with Miniforge and Rosetta with Miniconda side-by-side (Jeff Heaton's tutorial from 2021/11)
Jeff basically uses Apple's solution above for the native Miniforge install.
https://www.youtube.com/watch?v=w2qlou7n7MA
(3) Using native M1 Miniconda
There was a native M1 Miniconda installer published in 2021/11: Miniconda3 macOS Apple M1 64-bit bash (Py38 conda 4.10.1 2021-11-08)
https://docs.conda.io/en/latest/miniconda.html
My Experiences
I successfully ran the side-by-side installation from Jeff's tutorial with a few changes. It was very easy and I verified that in the native M1 Miniforge environment that Numpy is using the optimized BLAS/LAPACK linear algebra libraries and that Tensorflow has GPU access. I will update here after I run the Miniconda native M1 installer.
I installed the native version of python3 through miniforge (Apple version) and Spyder (Intel version) through homebrew and everything is working just fine for me with one exception, I've observed one strange behaviour when setting the "graphics backend" option to "automatic" instead of "inline".
Spyder >>> Prefernces >>> IPython Console >>> Graphics >>> Graphics Backend >>> inline, or automatic
When I start Spyder with the "inline" option and switch to "automatic", the opened kernels function just as expected. However, if I open new consoles they don't work at all. The issue also persists after restarting Spyder. The only way I manage to plot graphics in a separate window is to start Spyder with IPython console "graphics backend" set to "inline" and then change it to "automatic".
If I run python3 through terminal, plotting graphics works just fine as well.
My installation commands were:
brew install --cask miniforge
conda init zsh
conda activate
brew install --cask spyder
brew install PyQt#5
pip3 install matplotlib
You can check out this anouncement by Anaconda. You can now use Anaconda on your M1 MAC direclty.
"The 2022.05 release of Anaconda Distribution features native compiling for Apple M1’s ARM64 architecture (boasting 20% faster compute), Anaconda Navigator 2.1.4, conda 4.12.0, as well as several new and updated packages. 2022.05 is also the last release that will support win32."

Getting Error When installing Kivy Modules

So to be honest I started to learn to code like two weeks ago. If anyone could help me with this problem that would be great!
so Basically when I try to install kivy-deps.angle, kivy-deps.glew, or kivy-deps.gstreamer I get a message like the one below.
ERROR: Could not find a version that satisfies the requirement kivy-deps.angle-dev==0.2.0 (from versions: none)
ERROR: No matching distribution found for kivy-deps.angle-dev==0.2.0
enter image description here
enter image description here
I Tried everything I could think of and of course the proposed solutions are a joke i get the same Error in the terminal, I have the latest version of pip
$ pip --version
pip 20.1.1 from /Users/colemanschnaak/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)
Since Im using a mac I already have python 2.7 pre installed I tried switching the python3 to the default.(which wasted my time)
I saw online that some people just have to type
$ python3 -m pip install [kivy module name]
but that still didnt work.
since i just started getting in to coding thats all I can think of.
The current version kivy-deps.angle-dev 0.2.0 provides wheels for Python 3.6-3.8 for w32 and w64 only. No other wheels and no source code at PyPI.
If you need kivy-deps.angle-dev for a different Python or a different OS you have to compile from sources. If there is something to compile — I downloaded a wheel and didn't find any code inside it.

openCV in python on Linux bombs out at show image [duplicate]

I'm having an error running simple code using cv2 module.
It's just:
import cv2
img = cv2.imread('sudoku.png',0)
cv2.imshow('image',img)
And it fails with the following error:
QObject::moveToThread: Current thread (0x1b74720) is not the object's thread (0x1e57d70).
Cannot move to target thread (0x1b74720)
I googled this error and tried a lot of things but it doesn't help. I tried installing without pip, I tried using step-by-step installation (from official OpenCV) but nothing helps.
When I run:
cv2.__version__
It returns 3.4.3
As noted already, the basis for this problem is discussed in opencv-python issue 46, and results from the duplication of the following libraries both on the host and the opencv-python distro libQtDBus libQtCore and libQtGui.
It has been lately addressed in the newest release of opencv-python. It is not a fix to the source code, rather the fix is to force pip to compile the newly available source via
pip install --no-binary opencv-python opencv-python
This will cause opencv-python to use the same libraries as the host, so the conflict no longer exists.
According to this issue posted on the OpenCV GitHub, this is a known issue that the developer states is damn near impossible to fix. It is apparently caused by a conflict in any Qt installations on the system with the Qt that is shipped with OpenCV. There are some suggestions floating around to remove the libqt5x11extras5 package from the system. This may fix it for some but anyone running these libraries on a Linux distribution that uses a window manager based on Qt will render their desktop environment unusable by removing this package (having tried it myself).
You can try building OpenCV from source using the WITH_GTK=ON option when running cmake which will use GTK instead of Qt, circumventing the conflict. However, this is hard to make use of in Python when using virtual environments.
I haven't spent the time to fully appreciate this problem, but as I understand this is caused by multiple conflicting versions of some plugin in the environment. I tried installing building opencv-python but there were errors with that approach. Another suggestion is to change your import order, but I've had mixed success with that, and I couldn't get it to work on a project today.
But I found a workaround that worked for me. Install opencv-python-headless instead of opencv-python. This will avoid installing the conflicting plugins. It may not work for you depending on what features of opencv you need.
$ pip uninstall opencv-python
$ pip install opencv-python-headless
The error was fixed on my system, by simply updating one library.
To find out where it is coming from, assuming Linux, try the following,
LD_DEBUG=files python -c "import cv2"
or,
LD_DEBUG=files python -c "import cv2 ; img = cv2.imread('myimage.png',0) ; cv2.imshow('image',img) ; cv2.waitKey(0)"
On my machine, it failed in one of the blas libraries. I updated that library and the code now runs without error.
This is an old bug you can find it discussed in a number of online communities.
My test code is as follows. Notably the error has not reoccurred, and apparently has nothing to do with Qt.
import cv2
img = cv2.imread('sudoku.png',0)
cv2.imshow('image',img)
cv2.waitKey(0)
To me, the solution to this problem was removing Anaconda, then installing pip followed by installing OpenCV with a simple pip install command.

Is it compulsory to download Visual Studio for spacy?

I have tried installing spacy, but it is throwing the below error:
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft
Visual C++ Build Tools":
http://landinghub.visualstudio.com/visual-cpp-build-tools
I don't want to install Visual Studio. Is there other way to resolve this?
At the moment, installing spaCy requires a compiler. On Windows, this is included in the Visual C++ Build Tools. (Not to be confused with Visual Studio – you definitely don't need the whole thing.)
If you install spaCy from conda, you should be able to install binary wheels, which don't require a compiler:
conda install -c conda-forge spacy
Providing binary wheels for pip is definitely on the spaCy roadmap – you can follow the discussion and work in progress in this thread.
I stumbled upon the same thing but however managed to do it without MS Build Tools. However the process requires a bit of manual effort, but that's worthy if you don't want to waste space for MS Build Tools.
Visit Unofficial Windows Binaries for Python Extension Packages. Here you can get many binary wheels of a number of python packages for various python versions and both for 32/64 architectures.
Next search and download ujson, cymem, murmurhash, preshed, cytoolz, thinc and finally spaCy.
Install each wheel in the downloaded order using pip install some-package.whl
Hopefully spaCy will be installed successfully. If not, please leave a comment and I'll try my best to help you out.

How to install VTK5 on Archlinux?

I need to run a program which use VTK5 on my Archlinux PC, but I found it really hard to install VTK5, there is only VTK6(not compatible with VTK5) in official repo, and when I try to install it from AUR, it returns "Makepg was unable to build vtk5", then I try to install through source code, the result is that I was unable to install the VTK Python module...
Is there anybody who has any experience or idea about it?
I have not installed on Archlinux specifically, but on different linux machines. If you compile from source and are interested in python, remember to select the option python wrapping when running cmake. Btw, once built, you will have to update both the pythonpath and the ldlibrarypath.
You can also have a try at enthought canopy, which distributes a complete installation with numpy, scipy, vtk http://docs.enthought.com/canopy/quick-start/install_linux.html

Resources