ここでMATLABの初心者。フォルダから画像を読み込むクラスを作成しようとしています。これが私が持っているものです。
classdef ImageLoader
%IMAGELOADER Summary of this class goes here
% Detailed explanation goes here
properties
currentImage = 0;
filenames={};
filenamesSorted={};
end
methods
function imageLoader = ImageLoader(FolderDir)
path = dir(FolderDir);
imageLoader.filenames = {path.name};
imageLoader.filenames = sort(imageLoader.filenames);
end
function image = CurrentImage(this)
image = imread(this.filenames{this.currentImage});
end
function image = NextImage(this)
this.currentImage = this.currentImage + 1;
image = imread(this.filenames{this.currentImage});
end
end
end
これは私がそれを呼んでいる方法です:
i = ImageLoader('football//Frame*');
image=i.NextImage;
imshow(image);
ファイルの名前はFrame0000.jpg、Frame0001.jpg ...などです。コンストラクターにすべてのファイル名をロードして、を呼び出すだけで次のファイルを取得できるようにしたいのですが、i.NextImage
動作させることができません。
動作しました。
クラス:
classdef ImageLoader
%IMAGELOADER Summary of this class goes here
% Detailed explanation goes here
properties(SetAccess = private)
currentImage
filenames
path
filenamesSorted;
end
methods
function imageLoader = ImageLoader(Path,FileName)
imageLoader.path = Path;
temp = dir(strcat(Path,FileName));
imageLoader.filenames = {temp.name};
imageLoader.filenames = sort(imageLoader.filenames);
imageLoader.currentImage = 0;
end
function image = CurrentImage(this)
image = imread(this.filenames{this.currentImage});
end
function [this image] = NextImage(this)
this.currentImage = this.currentImage + 1;
image = imread(strcat(this.path,this.filenames{this.currentImage}));
end
end
end
電話:
i = ImageLoader('football//','Frame*');
[i image]=i.NextImage;
imshow(image);