0
이 코드가 실행되면 프로그램은 matlabcontrol 라이브러리를 사용하여 MATLAB을 열고 eval() 내부의 주어진 행을 실행합니다. 문제는 첫 번째 줄에 있습니다. 즉, m.eval("image1=imread('D:/My Hand Gestures/f.jpg');");
은 고정 된 문자열 값을 입력으로 사용합니다. 하지만 여기에 변수에 경로를 저장하고 imread()
함수에 전달하고 싶습니다. 어떻게해야 하죠? 어떤 도움을 주셔서 감사합니다. 여기에 코드가 있습니다.변수 값을 eval 함수에 전달
package Interface;
import matlabcontrol.MatlabConnectionException;
import matlabcontrol.MatlabInvocationException;
import matlabcontrol.MatlabProxy;
import matlabcontrol.MatlabProxyFactory;
/**
*
* @author Rajdeep
*/
public class Output {
private static String check;
private static String path;
Output(){
//default constructor
}
Output(String s,String p){
check = s;
path=p;
}
//GrayScale Conversion Function
public static void grayScale(String p,MatlabProxy m)throws MatlabConnectionException, MatlabInvocationException{
m.eval("image1=imread('D:/My Hand Gestures/f.jpg');");
m.feval("image1","imread(path)");
m.eval("figure,imshow(image1);");
m.eval("image_gray=rgb2gray(image1);");
m.eval("figure,imshow(image_gray);");
m.eval("final_image=imresize(image_gray,0.03125);");
m.eval("figure,imshow(final_image);");
m.eval("imwrite(final_image,'C:/Users/Desktop/f.jpg');");
//Disconnect the proxy from MATLAB
m.disconnect();
}
//Median Filtering Function
public static void Filter(String p, MatlabProxy m)throws MatlabConnectionException, MatlabInvocationException{
m.eval("I=imread('D:/gestures/f.jpg');");
m.eval("J = medfilt2(I, [4 4]);");
m.eval("figure,imshow(J);");
m.eval("imwrite(J,'C:/Users/Rajdeep/Desktop/f.jpg');");
//Disconnect the proxy from MATLAB
m.disconnect();
}
/**
*
* @param args
* @throws MatlabConnectionException
* @throws MatlabInvocationException
*/
public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
//Create a proxy, which we will use to control MATLAB
MatlabProxyFactory factory = new MatlabProxyFactory();
MatlabProxy proxy = factory.getProxy();
Output out=new Output("GrayScale","D:/My Hand Gestures/f.jpg");
if(check == "GrayScale") {
grayScale(path, proxy);
}
if(check== "Filter"){
Filter(path,proxy);
}
}
}
여기서는 미리 정의 된 경로가있는 경로 변수를 만들었습니다. 위의 프로세스에서와 같이 경로를 제공하는 대신이 변수를 사용하고 싶습니다.
감사합니다. 너는 나를 곤경에 빠뜨렸다. – Rajdeep
그게 간단했습니다. 나는 결코 그렇게 생각하지 않았다. – Rajdeep