I want to make a program in python to manipulate an image. The problem is I want to get the image by user input on file dialog but when I use a variable string named file_path
it does not read on cv2.imread()
function.
I suppose the problem is with the two slash problem on python. When we try to read an image path with one slash like c:\XXX\X.png
, we get an error. The solution is c:\\XXX\\X.png
, but with a string variable I cannot get solution?
Is there a solution for this problem?
import cv2
import tkinter as tk
from tkinter import filedialog
import numpy as np
root = tk.Tk()
root.withdraw()
#where i get path of image
file_path = filedialog.askopenfilenames(title = 'Select File', filetypes = [('image files', '.png;.jpg'), ('image files!', '*.png;*.jpg')])
# i get bug here below. It does even not show error text
image = cv2.imread(file_path)
# ... REST OF CODE