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

来源:互联网 发布:算法的乐趣 epub 编辑:程序博客网 时间:2024/06/07 00:08
I = imread('/home/wgb/Desktop/matlab_code/0009_color.jpg');imshow(I)% axis([0 1000 0 1000]);hold onfid = 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');endfclose(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 0
原创粉丝点击