S
S
saveliy_zhuravlev2015-06-01 15:04:47
Python
saveliy_zhuravlev, 2015-06-01 15:04:47

How to open files with cyrillic in path in python cv2?

I'm trying to open a file like this

frame = cv2.imread(u'C:/Users/%username%/image/1.png'.encode('utf-8'))
print frame
>>> None
frame = cv2.imread('G:/1.png')
print frame
>>>тут Numpy array

I tried to remove the encode, but it did not help, either an error, or frame = None
Is it possible to somehow open a file with Russian letters in the path through cv2.imread?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Selyck, 2021-05-26
@Selyck

import cv2
import numpy as np
file_path = 'C:/Users/%username%/image/1.png'
stream = open(file_path, 'rb')
bytes = bytearray(stream.read())
array = np.asarray( bytes, dtype=np.uint8)
bgrImage = cv2.imdecode(array, cv2.IMREAD_UNCHANGED)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question