質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

1695閲覧

wxpythonで他クラスの変数が取得できない

arima0119

総合スコア10

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2018/10/24 11:37

前提・実現したいこと

ここに質問の内容を詳しく書いてください。
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()

補足情報

分かりづらくて申し訳ございません。解決方法を教えていただけたら幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問