前提・実現したいこと
ここに質問の内容を詳しく書いてください。
python + wxpythonで簡単な画像フィルターGUIを制作しています。
発生している問題・エラーメッセージ
class MyFrame内のdef LUT内でドラッグ&ドロップした他クラスの画像のパスが格納されている変数をimread内で取得したいのですができません。
該当のソースコード
import wx
import cv2
import numpy as np
class ImagePanel(wx.Panel):
def init(self, parent, panel_size):
wx.Panel.init(self, parent)
self.panel_size = panel_size
self.load_image()
def load_image(self, input_image=''): if input_image == '': image = 'sample.png' else: image = input_image img = wx.Image(image) Newimg = img.Scale(self.panel_size[0], self.panel_size[1], wx.IMAGE_QUALITY_HIGH) wx.StaticBitmap(self, -1, wx.Bitmap(Newimg))
class MyFileDropTarget(wx.FileDropTarget):
def init(self, window):
wx.FileDropTarget.init(self)
self.window = window
def OnDropFiles(self, x, y, filenames): dd_input_image_path = filenames[0] self.window.load_image(dd_input_image_path) return True
class MyFrame(wx.Frame, ImagePanel):
def __init__(self): wx.Frame.__init__(self, None, title="umistagram", size=(650, 650)) p = wx.Panel(self) sizer = wx.BoxSizer(wx.VERTICAL) input_image_panel = ImagePanel(p, panel_size=(650, 400)) sizer.Add(input_image_panel, 0, wx.ALL, 5) p.SetSizer(sizer) dt = MyFileDropTarget(input_image_panel) input_image_panel.SetDropTarget(dt) button1 = wx.Button(p, label="filter1", pos=(15, 480), size=(100, 20)) button2 = wx.Button(p, label="filter2", pos=(115, 480), size=(100, 20)) button3 = wx.Button(p, label="filter3", pos=(215, 480), size=(100, 20)) button4 = wx.Button(p, label="filter4", pos=(315, 480), size=(100, 20)) button5 = wx.Button(p, label="filter5", pos=(415, 480), size=(100, 20)) button6 = wx.Button(p, label="filter6", pos=(515, 480), size=(100, 20)) button7 = wx.Button(p, label="filter7", pos=(15, 520), size=(100, 20)) button8 = wx.Button(p, label="filter8", pos=(115, 520), size=(100, 20)) button9 = wx.Button(p, label="filter9", pos=(215, 520), size=(100, 20)) button10 = wx.Button(p, label="filter10", pos=(315, 520), size=(100, 20)) button11 = wx.Button(p, label="filter11", pos=(415, 520), size=(100, 20)) button12 = wx.Button(p, label="filter12", pos=(515, 520), size=(100, 20)) button13 = wx.Button(p, label="end", pos=(580, 560), size=(40, 20)) self.Bind(wx.EVT_BUTTON, self.LUT, button1) self.Bind(wx.EVT_BUTTON, self.LUT, button2) self.Bind(wx.EVT_BUTTON, self.LUT, button3) self.Bind(wx.EVT_BUTTON, self.LUT, button4) self.Bind(wx.EVT_BUTTON, self.LUT, button5) self.Bind(wx.EVT_BUTTON, self.LUT, button6) self.Bind(wx.EVT_BUTTON, self.LUT, button7) self.Bind(wx.EVT_BUTTON, self.LUT, button8) self.Bind(wx.EVT_BUTTON, self.LUT, button9) self.Bind(wx.EVT_BUTTON, self.LUT, button10) self.Bind(wx.EVT_BUTTON, self.LUT, button11) self.Bind(wx.EVT_BUTTON, self.LUT, button12) self.Bind(wx.EVT_BUTTON, self.closebutton, button13) p.SetSizer(sizer) self.Center() self.Show() def closebutton(self, event): self.Close(True) def LUT(self, event): gamma = 1.8 lookUpTable = np.zeros((256, 1), dtype='uint8') for i in range(256): lookUpTable[i][0] = 255 * pow(float(i) / 255, 1.0 / gamma) img = cv2.imread('sample.png') img_gamma = cv2.LUT(img, lookUpTable) cv2.imshow("lookup_umi.png", img_gamma) yesno_dialog = wx.MessageDialog(self, "保存しますか?", "message", wx.YES_NO | wx.ICON_QUESTION) try: if yesno_dialog.ShowModal() == wx.ID_YES: cv2.imwrite("lookup_umi.png", img_gamma) cv2.destroyAllWindows() finally: cv2.destroyAllWindows() return True
if name == 'main':
app = wx.App()
MyFrame()
app.MainLoop()
補足情報
分かりづらくて申し訳ございません。解決方法を教えていただけたら幸いです。
あなたの回答
tips
プレビュー