Home>

I want to assign an image file name to a variable and open the image using the variable
I know that you can just substitute'lena.jpg'.
I want to assign it to a variable.
It may be difficult to understand, but thank you.

Image not assigned to im2
Corresponding source code
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QImage, QPalette, QPixmap
import datetime
from PIL import Image
import cv2
import tkinter.filedialog as fd
a = "'"
b = "lena.jpg"
c = "'"
im1 = a + b + c
print (im1)
im2 = cv2.imread (str (im1))
print (im2)
Output result

'lena.jpg'
None

  • Answer # 1

    It was because I was trash.
    b = lenna.jpg
    It was possible by substituting this b.
    Addition in vain
    It didn't have to be im1 ='lena.jpg'.
    I'm sorry I asked you a question like garbage.