duancenxiao0482
duancenxiao0482
2016-10-16 02:00

php中的matlab函数输出

已采纳

Hello everyone please i need help with this issue.I have a matlab function that returns a value 'pourcentage' i want to retrieve this value in php file . here is my function

    function A=computeSIFT(input_img_path)
   fabric = imread(input_mg_path);
   I = rgb2gray(fabric);
   %I=histeq(I,255);
   %I=floor(I/8);
   maxi = max(I(:))
   seuil = maxi-50
   for k=1:size(I,1)
for j=1:size(I,2)
    if(I(k,j)<seuil)
        I(k,j)=0;
    else
        I(k,j)=255;
    end
end
end
[~, threshold] = edge(I, 'sobel');
fudgeFactor = .5;
BWs = edge(I,'sobel', threshold * fudgeFactor);
figure, imshow(BWs), title('binary gradient mask');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('dilated gradient mask');
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');
BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('cleared border image');
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('segmented image');
BWoutline = bwperim(BWfinal);
Segout = I;
Segout(BWoutline) = 255;
figure, imshow(Segout), title('outlined original image');
white=0;
black=0;
for z=1:size(I,1)
for m=1:size(I,2)
    if I(z,m)==0
        black=black+1;
    else
       white= white+1;
    end
end
end
black
white
pourcentage = (white/(size(I,1)*size(I,2)))*100
A=pourcentage;
end

and this is my php code :

$command = "matlab -nojvm -r \"A=computeSIFT('$target_path');exit\"";
system($command,$output);


 $response['message'] = 'yeeeeeeeeeeeeees'.$output;

how can i retrieve the pourcentage in $output??

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongqian7545 dongqian7545 5年前
    1. Your matlab function should output it's result to the console (using disp or fprintf).
      (You should try to run the function line in $command in your shell (cmd/linux shell) to see if you get any output.)

    2. php's system function returns only the last line of the output (and it's a return value, it's not the second parameter).
      If you ok with the last-line only, you can use


    $output = system($command);
    

    If you need the enitre output of the call you can the shell_exec function:

    $output = shell_exec($command);
    
    点赞 评论 复制链接分享

相关推荐