module object has no attribute imread and imshow - python

I have installed OpenCV in Python 3.6(64 bit), but whenever I compile the below code, it is throwing an error of module object has no attribute imread and imshow.
This happens while doing in the python idle but when trying in the command-line interpreter with windows 10 it is working. Moreover while getting opencv version, the command-line code is working but not with idle.
Please give the possible solution for this problem.
Python IDLE:
import numpy as np
import cv2
img = cv2.imread("H:\python project\watch.jpg",0)
cv2.imshow("image",img)
python IDLE error msg:
Traceback (most recent call last):
File "H:\python project\cv2.py", line 3, in <module>
import cv2
File "H:\python project\cv2.py", line 5, in <module>
img = cv2.imread("H:\python project\watch.jpg",0)
AttributeError: module 'cv2' has no attribute 'imread'

Try to import cv2 package in command line. If it executes without any error than it should work.
Have you pasted the cv2.pyd file in lib/site-packages folder?

Related

Ursina.build can't find modules?

I was reading This, when it said I was supposed to use the command python -m ursina.build to compile my project. When I launched the .bat file I got this error
package_folder: C:\Users\sbahr\OneDrive\Documents\programming\Python\MeshGame\build\python\lib\site-packages\ursina
asset_folder: src
screen resolution: (1920, 1080)
Traceback (most recent call last):
File "C:\Users\sbahr\OneDrive\Documents\programming\Python\MeshGame\main.py", line 3, in <module>
from mesh import ChunkManager
File "C:\Users\sbahr\OneDrive\Documents\programming\Python\MeshGame\mesh.py", line 19, in <module>
from noise import generateSaveNoise
File "C:\Users\sbahr\OneDrive\Documents\programming\Python\MeshGame\noise.py", line 3, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I ran pip install numpy and it said numpy was already installed.
This used to be automatic, but broke in a newer version of Python. Therefore you'll have to provide a list of extra modules to copy, if you're using any.
From ursina's documentation (https://www.ursinaengine.org/building.html):
Make sure to include any extra modules with --include_modules PIL,numpy for example.

AttributeError: partially initialized module 'face_recognition' has no attribute 'face_encodings'

I am trying to make face recognition script in python with the help of below given link found on google.
https://www.mygreatlearning.com/blog/face-recognition/
I have installed:
OpenCV
dlib and
face_recognition
libraries.
Also, installed Visual C++ for CMake.
And now I am trying to "extract features from Face" using code given in above link.
While running script, I am getting below error:
Traceback (most recent call last):
File "C:\Users\ajay.arora2\AppData\Local\Programs\Python\Python38-32\extract_features_from_face.py", line 2, in <module>
import face_recognition
File "C:\Users\ajay.arora2\AppData\Local\Programs\Python\Python38-32\face_recognition.py", line 32, in <module>
encodings = face_recognition.face_encodings(rgb)
AttributeError: partially initialized module 'face_recognition' has no attribute 'face_encodings' (most likely due to a circular import)
I have tried re-installing face_recognition module.
Please suggest any workaround.
Thanks in advance.
Most probably you have named your file the same as the library "face_recognition".
Circular import happens when you want to import something from the same file.

Module is in correct folder, but still says that it cannot be found

I have pygame and numpy in the same folder. I can import pygame, but I can only import numpy in the terminal, not even in the IDLE. If I try to import numpy anywhere else, I get this message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
I can also still import pygame into the terminal. Also, python in the terminal is version 3.7.5, but in the IDLE it's 3.6.6. Not sure if that's related.
All of my modules are in the default path folder.

Module name not found for cv2

Currently, I'm using this to guide me with my project " https://github.com/hanyazou/TelloPy/blob/develop-0.7.0/tellopy/examples/video_effect.py "
but I have some issues running it, but to my knowledge, I believed I have cv2 installed in my PC. I'm using Windows 10-64bits if that helps..
The error was:
Traceback (most recent call last):
File "video_effect.py" , line 5, in module
import cv2.cv2 as cv2 # for avoidance of pylint error
ImportError: No module found cv2

AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'

From this question in SO I understand the error should be solved by having opencv contrib, but the thing is that when I first built opencv using cmake using this guide by pyimagesearch , I had also built opencvcontrib. If I must rebuild it, how exactly should I do it?
This is the error:
import cv2
cv2.createLBPHFaceRecognizer()
Traceback (most recent call last):
File "stdin", line 1, in module
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
Also:
import cv2
help(cv2.face.createLBPHFaceRecognizer)
Traceback (most recent call last):
File "stdin", line 1, in module
AttributeError: 'module' object has no attribute 'face'
Mac OS, Python 2.7, Opencv 3.2
After searching high and low, I found that using cv2.face.LBPHFaceRecognizer_create() just do the trick for opencv 3.3.0 with opencv contrib. Hope you find it useful.
createLBPHFaceRecognizer() is in the sub-module cv2.face in python. To access it you should use cv2.face.createLBPHFaceRecognizer().
I have executed this command: pip install opencv-contrib-python
it has install opencv version : 3.4.0,
and it works with this formula:
import cv2
recognizer = cv2.face.LBPHFaceRecognizer_create()

Categories

Resources