Search code examples
pythonopencv

"FAX注文0004.tif" does not read from opencv but "FAX0004.tif" can be readbale


Error while reading japanese character name file. Without japanese characters the file can be read.

import matplotlib.pyplot as plt
import cv2

image_path = r"FAX注文0004.tif"    
image = cv2.imread(image_path)

plt.imshow(image)
plt.axis('off')  
plt.show()

Note: After renaming file from FAX注文0004.tif to FAX0004.tif the file is easily read.

Error: TypeError: Image data of dtype object cannot be converted to float

Solution

  • you can use cv2.imdecode() to decode the image.this will help you.

    image_path = "FAX注文0004.tif"
    with open(image_path, 'rb') as f:
        image_bytes = f.read()
    image = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), cv2.IMREAD_UNCHANGED)