Getting attribute error while trying load multiple images from a directory using OpenCv












0















I am trying to load four images into my python file from a directory for further processing.



import cv2 as cv
import pandas as pd
import matplotlib.pyplot as plt
import glob
import numpy as np
cv_img=
acne_string=
trust_score=


def avg(lst):
return sum(lst) / len(lst)



for img in glob.glob("/home/centura/Desktop/Centura Tech/p1-Diseases/New_acne_grades/Transformed images/API-testing/images/*.jpg"):


u = cv.imread(img, cv.IMREAD_COLOR)
smoothing=cv.GaussianBlur(u.copy(),(5,5),cv.BORDER_DEFAULT)
img_grey = cv.cvtColor(smoothing.copy(), cv.COLOR_BGR2GRAY)

plt.imshow(img_grey)
plt.axis("off")
plt.show()


The python script basically does threshold and gray scale conversion.
The problem is i am getting an error like this.



File "/home/centura/Desktop/Centura Tech/p1-Diseases/All grades test/t_t.py", line 40, in engine
u = cv.imread(img, cv.IMREAD_COLOR)
AttributeError: 'float' object has no attribute 'imread'


I am using python3 and opencv 3.4.3. I have to use OpenCV for reading in images i cannot use PIL. Any work around










share|improve this question

























  • I just edited some of indent errors in your code. I can run your code normally. Could you provide some images?

    – Ha Bom
    Nov 15 '18 at 9:06













  • @HaBom i found the fault, my code is about 400 lines in between the code i have accidentally assigned cv as another variable.So python read it with the new value instead of image.

    – user10573543
    Nov 15 '18 at 10:07
















0















I am trying to load four images into my python file from a directory for further processing.



import cv2 as cv
import pandas as pd
import matplotlib.pyplot as plt
import glob
import numpy as np
cv_img=
acne_string=
trust_score=


def avg(lst):
return sum(lst) / len(lst)



for img in glob.glob("/home/centura/Desktop/Centura Tech/p1-Diseases/New_acne_grades/Transformed images/API-testing/images/*.jpg"):


u = cv.imread(img, cv.IMREAD_COLOR)
smoothing=cv.GaussianBlur(u.copy(),(5,5),cv.BORDER_DEFAULT)
img_grey = cv.cvtColor(smoothing.copy(), cv.COLOR_BGR2GRAY)

plt.imshow(img_grey)
plt.axis("off")
plt.show()


The python script basically does threshold and gray scale conversion.
The problem is i am getting an error like this.



File "/home/centura/Desktop/Centura Tech/p1-Diseases/All grades test/t_t.py", line 40, in engine
u = cv.imread(img, cv.IMREAD_COLOR)
AttributeError: 'float' object has no attribute 'imread'


I am using python3 and opencv 3.4.3. I have to use OpenCV for reading in images i cannot use PIL. Any work around










share|improve this question

























  • I just edited some of indent errors in your code. I can run your code normally. Could you provide some images?

    – Ha Bom
    Nov 15 '18 at 9:06













  • @HaBom i found the fault, my code is about 400 lines in between the code i have accidentally assigned cv as another variable.So python read it with the new value instead of image.

    – user10573543
    Nov 15 '18 at 10:07














0












0








0








I am trying to load four images into my python file from a directory for further processing.



import cv2 as cv
import pandas as pd
import matplotlib.pyplot as plt
import glob
import numpy as np
cv_img=
acne_string=
trust_score=


def avg(lst):
return sum(lst) / len(lst)



for img in glob.glob("/home/centura/Desktop/Centura Tech/p1-Diseases/New_acne_grades/Transformed images/API-testing/images/*.jpg"):


u = cv.imread(img, cv.IMREAD_COLOR)
smoothing=cv.GaussianBlur(u.copy(),(5,5),cv.BORDER_DEFAULT)
img_grey = cv.cvtColor(smoothing.copy(), cv.COLOR_BGR2GRAY)

plt.imshow(img_grey)
plt.axis("off")
plt.show()


The python script basically does threshold and gray scale conversion.
The problem is i am getting an error like this.



File "/home/centura/Desktop/Centura Tech/p1-Diseases/All grades test/t_t.py", line 40, in engine
u = cv.imread(img, cv.IMREAD_COLOR)
AttributeError: 'float' object has no attribute 'imread'


I am using python3 and opencv 3.4.3. I have to use OpenCV for reading in images i cannot use PIL. Any work around










share|improve this question
















I am trying to load four images into my python file from a directory for further processing.



import cv2 as cv
import pandas as pd
import matplotlib.pyplot as plt
import glob
import numpy as np
cv_img=
acne_string=
trust_score=


def avg(lst):
return sum(lst) / len(lst)



for img in glob.glob("/home/centura/Desktop/Centura Tech/p1-Diseases/New_acne_grades/Transformed images/API-testing/images/*.jpg"):


u = cv.imread(img, cv.IMREAD_COLOR)
smoothing=cv.GaussianBlur(u.copy(),(5,5),cv.BORDER_DEFAULT)
img_grey = cv.cvtColor(smoothing.copy(), cv.COLOR_BGR2GRAY)

plt.imshow(img_grey)
plt.axis("off")
plt.show()


The python script basically does threshold and gray scale conversion.
The problem is i am getting an error like this.



File "/home/centura/Desktop/Centura Tech/p1-Diseases/All grades test/t_t.py", line 40, in engine
u = cv.imread(img, cv.IMREAD_COLOR)
AttributeError: 'float' object has no attribute 'imread'


I am using python3 and opencv 3.4.3. I have to use OpenCV for reading in images i cannot use PIL. Any work around







image-processing python-3.6 opencv3.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 11:54









Ha Bom

1,3032519




1,3032519










asked Nov 15 '18 at 8:17









user10573543user10573543

367




367













  • I just edited some of indent errors in your code. I can run your code normally. Could you provide some images?

    – Ha Bom
    Nov 15 '18 at 9:06













  • @HaBom i found the fault, my code is about 400 lines in between the code i have accidentally assigned cv as another variable.So python read it with the new value instead of image.

    – user10573543
    Nov 15 '18 at 10:07



















  • I just edited some of indent errors in your code. I can run your code normally. Could you provide some images?

    – Ha Bom
    Nov 15 '18 at 9:06













  • @HaBom i found the fault, my code is about 400 lines in between the code i have accidentally assigned cv as another variable.So python read it with the new value instead of image.

    – user10573543
    Nov 15 '18 at 10:07

















I just edited some of indent errors in your code. I can run your code normally. Could you provide some images?

– Ha Bom
Nov 15 '18 at 9:06







I just edited some of indent errors in your code. I can run your code normally. Could you provide some images?

– Ha Bom
Nov 15 '18 at 9:06















@HaBom i found the fault, my code is about 400 lines in between the code i have accidentally assigned cv as another variable.So python read it with the new value instead of image.

– user10573543
Nov 15 '18 at 10:07





@HaBom i found the fault, my code is about 400 lines in between the code i have accidentally assigned cv as another variable.So python read it with the new value instead of image.

– user10573543
Nov 15 '18 at 10:07












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315034%2fgetting-attribute-error-while-trying-load-multiple-images-from-a-directory-using%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315034%2fgetting-attribute-error-while-trying-load-multiple-images-from-a-directory-using%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma