I'm using openCV to process an image that is chosen by the user. For OpenCV I just need to get the path to the image, but I'm unable to find anything in the API which lets me just pick a file path (filtering for image file types, preferably) using the built in file browser.
I've tried registering an operator like so, but when I call it in my script the execution doesn't wait until it returns, so I get an error from the next function complaining that the path is None, while the file browser window is still open.
class SelectImageOperator(bpy.types.Operator, ImportHelper):
bl_idname = "image.select_image"
bl_label = "Select Image"
filename_ext = "*.png;*.jpg;*.jpeg;*.bmp;*.tga;*.tiff;*.exr"
filter_glob: StringProperty(
default="*.png;*.jpg;*.jpeg;*.bmp;*.tga;*.tiff;*.exr",
options={'HIDDEN'}
)
def execute(self, context):
print( "Selected file: " + self.filepath)
return self.filepath