简体   繁体   中英

Imread openCV can not read image in windows

I am runnning some test on my local windows and I just came up with couple of lines of codes to read an image from my windows drive but it appears it can not read the image

input_arr = cv2.imread("C:\Downloads\database\Imagens_e_Matrizes_da_Tese_de_Thiago_Alves_Elias_da_Silva\Desenvolvimento_da_Metodologia\SAUDÁVEIS\1000\Segmentadas\PAC_38_DN0-dir.png", flags=cv2.IMREAD_COLOR)
input_arr

I am not sure what is wrong with my codes?

I am not sure what is wrong with my codes?

The path. Windows uses backslashes, that must be escaped via \\ . Personally, though, I prefer r-strings:

cv2.imread(r"C:\Downloads\database\Imagens_e_Matrizes_da_Tese_de_Thiago_Alves_Elias_da_Silva\Desenvolvimento_da_Metodologia\SAUDÁVEIS\1000\Segmentadas\PAC_38_DN0-dir.png", flags=cv2.IMREAD_COLOR)
#          ^

(note the r" in the beginning)

Note: Windows also hates unicode characters. As it happens, in this case, together with the missing escaping, there's also a problem with the folder SAUDÁVEIS .

add r before beginning of path

input_arr=cv2.imread(r"C:\Downloads\database\Imagens_e_Matrizes_da_Tese_de_Thiago_Alves_Elias_da_Silva\Desenvolvimento_da_Metodologia\SAUDÁVEIS\1000\Segmentadas\PAC_38_DN0-dir.png", flags=cv2.IMREAD_COLOR)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM