0

i am newbie to python. I am trying to create a Python Program to image dehazing using dcp. I have an image that need to view at console at first and need to do some dehazing method. unfortunately, here i unable to upload or view the image and it saying Image data cannot be converted to float. I am getting the following error when I try running it.

import cv2 
import math 
import numpy as np
import matplotlib.pyplot as plt

def DarkChannel(im,sz):
    b,g,r = cv2.split(img)
    dc = cv2.min(cv2.min(r,g),b)
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (sz,sz))
    dark = cv2.erode(dc,kernel)
    return dark
img = cv2.imread("C:/Users/User/Documents/sypder/img/bird.jpg", 1)
plt.imshow(img)

1

2 Answers 2

1

It seems your file path is wrong since your sample code worked perfectly for me. If you are struggling with file paths you can pass it as a raw string.

img = cv2.imread(r"C:\Users\User\Documents\sypder\img\bird.jpg", 1) 

If you fix it like this, it should work. I copied the object name from properties while doing it.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you. but its still showing error.
Your object name should be different from the one I wrote. You should copy the file name from the settings,security, object name. Or if you don't want to bother with that just put the image file in the directory where the code is running. It should work that way.
0

try to read this post : https://www.pythonfixing.com/2021/10/fixed-typeerror-image-data-can-not.html

it's jupiter based article but you can change them accordingly

I'm a newbie too that come across your question but those might be a help

goodluck!

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.