用matlab在图像上画矩形框,并保存坐标到文本中

I = imread('/home/wgb/Desktop/matlab_code/0009_color.jpg');
imshow(I)
% axis([0 1000 0 1000]);
hold on
fid = fopen('wgb_2.txt','wt');
[x1,y1]=ginput(1);
plot(x1,y1,'+');
[x2,y2]=ginput(1);
plot(x2,y2,'+');
[x3,y3]=ginput(1);
plot(x3,y3,'+');
[x4,y4]=ginput(1);
plot(x4,y4,'+');
% plot([x1 x2],[y1 y2]);
wgb = [[x1,y1];[x2,y2];[x3,y3];[x4,y4]];
[row, col] = size(wgb);
for i = 1:row
    for j = 1:col
        fprintf(fid, '%g\t', wgb(i,j));
    end
    fprintf(fid, '\n');
end
fclose(fid);
vertColor = 'r';
horizColor ='g';
rectPts = wgb;
hold on;
h(1) = line([rectPts(1,1) rectPts(2,1)], [rectPts(1,2) rectPts(2,2)],'Color',vertColor);
h(2) = line([rectPts(2,1) rectPts(3,1)],[rectPts(2,2) rectPts(3,2)],'Color',horizColor);
h(3) = line([rectPts(3,1) rectPts(4,1)],[rectPts(3,2) rectPts(4,2)],'Color',vertColor);
h(4) = line([rectPts(4,1) rectPts(1,1)],[rectPts(4,2) rectPts(1,2)],'Color',horizColor);
hold off




% plot([x1 x2],[y1 y2]);
% plot([x2 x3],[y2 y3]);
% plot([x3 x4],[y3 y4]);
% plot([x4 x1],[y4 y1]);
% button=1
% while(button==1)
%     [x1,y1]=ginput(1);
%     plot(x1,y1,'+');
% %     [x2,y2,button]=ginput(1);
% %     plot(x2,y2,'+');
% %     plot([x1 x2],[y1 y2]);
% end

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值