1.遇到的问题:从MATLAB中导出jar包,然后导入java中调用,该jar包的功能为对一个图像集进行拼接,其中使用了vlfeat这一插件,报错如下
2.MATLAB及JAVA源码:
function []=stitch_func(res,des)
path=res;
%% params
focus=1000;
Full360=0;
unordered=0;
size_bound=400.0;
%%
full=Full360;
f=focus;
run('lib/vlfeat-0.9.20/toolbox/vl_setup'); %在这一行出错,这一行应该是使vlfeat这个插件运行起来
disp(['creating panorama for ',res]);
s=imageSet(fullfile(path)); %创建一个imageSet对象
img=read(s,1); %读取图像集合里的第一张图像
size_1=size(img,1);
if size_1>size_bound
img=imresize(img,size_bound/size_1);
end
imgs=zeros(size(img,1),size(img,2),size(img,3),s.Count,'like',img);
t=cputime;
for i=1:s.Count
new_img=read(s,i);
if size_1>size_bound
imgs(:,:,:,i)=imresize(new_img,size_bound/size_1);
else
imgs(:,:,:,i)=new_img;
end
end
disp(['resizing:',int2str(cputime-t),' sec']);
if unordered %若图像无序,对图像库中的图像进行排序
t=cputime;
disp('ordering unordered images');
imgs=imorder(imgs);
disp([int2str(cputime-t),' sec']);
end
panorama=create( imgs, f, full);
imwrite(panorama,[des,'.jpg']);
if unordered
imwrite(panorama,[des,'from unordered.jpg']);
end
package stitch;
import com.mathworks.toolbox.javabuilder.*;
import stitch_func.Stitcher; //此为MATLAB调用的函数的类
public class StitchTest {
public static void main(String[] args) {
try {
Stitcher stitch = new Stitcher();
stitch.stitch_func("D:\\Work\\program\\pictures\\picture_dehaze\\",
"D:\\Work\\program\\pictures\\picture_stitch\\");//参数为(图像集地址,拼接图像保存地址)
} catch (MWException e) {
e.printStackTrace();
}
}
}
3.问题补充:此代码在MATLAB上可以正常运行;在打包的时候界面如下