duancenxiao0482 2016-10-16 02:00
浏览 94
已采纳

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 2016-10-16 02:32
    关注
    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测