[Python] Do not put Japanese in the path used by OpenCV

Introduction

As the title says. I was addicted to OpenCV because it didn't read the path, so I looked into what happened and found that if I put Japanese in the path, it wouldn't work properly.

Assumed file structure

C: ↓ user ↓ test01.jpg TestOpenCV.py

Bad example

TestOpenCV.py


import cv2
filename = "C:/user/test01.jpg " # ファイルパスの「user」がアウトで読み込んでくれない
img = cv2.imread(filename,0) # img =Become None

Solutions

Do not include Japanese in the path or use a relative path.

Good example

TestOpenCV.py


import cv2
filename = "C:/User/test01.jpg " #Change "User" to "User"
filename = "./test01.jpg " #TestOpenCV if you can't change the name.Make it a relative path as seen from py
img = cv2.imread(filename,0) #It loads the image properly

Recommended Posts

[Python] Do not put Japanese in the path used by OpenCV
Get the desktop path in Python
Put python, numpy, opencv3 in ubuntu14
Get the script path in Python
Read the file line by line in Python
Read the file line by line in Python
Collect Japanese tweets that do not include images, URLs or replies in Python
Receive the form in Python and do various things
Note the frequently used options in Python + Selenium + Chrome
Japanese can be used with Python in Docker environment
[Memorandum] Japanese keys cannot be used in python string.Template.substitute
Write letters in the card illustration with OpenCV python
What to do if the progress bar is not displayed in tqdm of python
Japanese output in Python
Do not pass self to ProcessPoolExecutor in the class
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
What to do if Python does not switch from the System version in pyenv
Python OpenCV tried to display the image in text.
python> link> dir_util.copy_tree ()> update = 1> Do not copy the acquired one?
Test.py is not reflected on the web server in Python3.
[Python] Open the csv file in the folder specified by pandas
Commands often used in the development environment during Python implementation
Pharmaceutical company researchers have summarized the operators used in Python
Solve the Japanese problem when using the CSV module in Python.
The websocket of toio (nodejs) and python / websocket do not connect.
Make the function of drawing Japanese fonts in OpenCV general
Visualize the correlation matrix by principal component analysis in Python
I wrote python in Japanese
Download the file in Python
Find the difference in Python
Naturally sort Path in Python
Make Opencv available in Python
I understand Python in Japanese!
Sort by date in python
Get Japanese synonyms in Python
[Python] A memo of frequently used phrases (by myself) in Python scripts
A Python one-liner that pretty prints json. Do not escape Japanese.
[Understanding in the figure] Management of Python virtual environment by Pipenv
Check if the password hash generated by PHP matches in Python
New Python grammar and features not mentioned in the introductory book
Read the standard output of a subprocess line by line in Python
All elements move (do not remain in the same position) shuffle
Sort the file names obtained by Python glob in numerical order
Read a file in Python with a relative path from the program
Object extraction in images by pattern matching using OpenCV with Python
The story that 2D list replacement did not work in python
[Beginner memo] How to specify the library reading path in Python
What to do when the value type is ambiguous in Python?
Play by hitting the Riot Games API in Python First half
Arrow keys do not work in zsh + python shell on mac
[Python] How to do PCA in Python
Getting the arXiv API in Python
File / folder path manipulation in Python
8 Frequently Used Commands in Python Django
Python in the browser: Brython's recommendation
Save the binary file in Python
Hit the Sesami API in Python
Until you put Python in Docker
Calculate free-space path loss in Python
Put the module in the Pepper app
[Python] Basic knowledge used in AtCoder