AttributeError: partially initialized module 'cv2' has no attribute 'imread' - python

Till 1 hour back my opencv code was working perfectly fine. it could run my script without error. but I don't know why some time back suddenly it started giving me this error:
AttributeError: partially initialized module 'cv2' has no attribute 'imread' (most likely due to a circular import)
Traceback (most recent call last):
File "FACEDETECTION.PY", line 1, in <module>
import cv2
File "C:\Users\Lenovo\anaconda3\envs\CAM\lib\site-packages\cv2\__init__.py", line 5, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
So what could be the error?
update: Here is my code-
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
path = "text.png"
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
text = pytesseract.image_to_string(img)
print(text)
cv2.imshow("name", img)
cv2.waitKey(7000)

Related

How to resolve "AttributeError: 'HandDetector' object has no attribute 'findPosition'"?

I am getting an error:
Traceback (most recent call last):
File "d:\buh\DynamicTextReader.py", line 68, in <module>
lmList, bboxInfo = detector.findPosition(img)
AttributeError: 'HandDetector' object has no attribute 'findPosition'
When running the program:
import cv2
from cvzone.HandTrackingModule import HandDetector
from time import sleep
import numpy as np
import cvzone
from pynput.keyboard import Controller
lmList, bboxInfo = detector.findPosition(img) # The Error Is In This Line
img = drawAll(img, buttonList)
(I removed many parts of the code)
My python version is 3.9.0.
I tried to change the versions of cvzone but the error couldn't resolve.

AttributeError: module 'face_recognition' has no attribute 'load_image_file'

 I have succefully installed a library to perform face recognition; I have tried to use this on a program but I get an attribute error.
# Import the face_recognition library
import face_recognition
import face_recognition_models
# Load a sample image
image = face_recognition.load_image_file(r'C:\Users\WAJIH\Desktop\code\face')
# Detect faces in the image
face_locations = face_recognition.face_locations(image, model="cnn")
# Print the number of faces detected
print(f"{len(face_locations)} faces detected")
out:
Traceback (most recent call last):
File "c:\Users\WAJIH\Desktop\Face-recognition-python-project-main\ss.py", line 1, in
import face_recognition
File "C:\Users\WAJIH\AppData\Local\Programs\Python\Python39\lib\site-packages\face_recognition_init_.py", line 7, in
from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance
File "C:\Users\WAJIH\AppData\Local\Programs\Python\Python39\lib\site-packages\face_recognition\api.py", line 3, in
import PIL.Image
File "C:\Users\WAJIH\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL_init_.py", line 15, in
from . import _version
ValueError: source code string cannot contain null bytes

module 'pytesseract' has no attribute 'image_to_string'

I've been trying to solve this error for a long time. I have googled this error and find nothing to solve it.
error
Traceback (most recent call last):
File "tess.py", line 6, in <module>
print(pytesseract.image_to_string(Image.open(image_file)))
AttributeError: module 'pytesseract' has no attribute 'image_to_string'
Please also tell me, What would be the "pytesseract.pytesseract.tesseract_cmd = 'System_path_to_tesseract'" for ubuntu
code
from PIL import Image
from pytesseract import *
import pytesseract
image_file = '4.jpg'
print(pytesseract.image_to_string(Image.open(image_file)))
Help me to solve this error
Thanks in advance

Tifffile.imshow() KeyError: 'matplotlib.pyplot'

I used the Tifffile module's imshow () method to display the tiff image in Python 3.5.2.
The code is as follows:
import tifffile as tiff
IM_ID = '6120_2_2'
im_rgb = tiff.imread('/home/roy/image&csv/image/{}.tif'.format(IM_ID)).transpose([1, 2, 0])
im_size = im_rgb.shape[:2]
tiff.imshow(im_rgb)
But there is an error:
Traceback (most recent call last):
File "/home/roy/PycharmProjects/CSV2Ploy/csv2ploy.py", line 49, in <module>
tiff.imshow(im_rgb)
File "/usr/local/lib/python3.5/dist-packages/tifffile/tifffile.py", line 6349, in imshow
pyplot = sys.modules['matplotlib.pyplot']
KeyError: 'matplotlib.pyplot'
I think it must be my development environment missing the matplotlib.pyplot module. So I checked the matplotlib directory, but found that the directory does have pyplot.py file.
The terminal queries the pyplot.py file
I have a lot of information on the Internet, but most are import matplotlib.pyplot problems, some people can help me solve this problem?

No module named Image windows ananconda

from PIL import Image
from pytesser import *
image_file = 'D:\plate.jpg'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text
it gets me error that
C:\Users\KEN\Anaconda2\python.exe C:/Users/KENIL/PycharmProjects/plate/ocr.py
Traceback (most recent call last):
File "C:/Users/KEN/PycharmProjects/plate/ocr.py", line 2, in <module>
from pytesser import *
File "C:\Users\KEN\PycharmProjects\plate\pytesser.py", line 6, in <module>
import Image
ImportError: No module named Image
even though i have installed ananconda properly as well as pillow screenshot of package installed
The code you posted doesn't have the error. From the error message it seems that the error is in the module pytesser.py, where you probably use Image (in line 6 :-) ) without importing it.

Categories