关闭

Matlab生成棋盘格点图

780人阅读 评论(0) 收藏 举报

转自zhouyelihua**http://blog.csdn.net/zhouyelihua/article/details/46674191**

在摄像机标定过程中常常需要打印棋盘格程序,还有就是在投影仪标定当中常常需要投射和投影仪相同分辨率的

<code class="language--matlab hljs matlab has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">close all;
clear all;
clc;
width=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1024</span>  ;      <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern的宽</span>
height=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">768</span>     ;          <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern的高</span>
img_final=<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">zeros</span>(height,width);
reinforceconner=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>       ;<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%是否加强角点 </span>
row=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">10</span>;                 <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern中棋盘格的行数</span>
col=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">13</span> ;              <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern中棋盘格的列数</span>
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span>;           <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern中棋盘格的大小</span>
org_X=(height-row*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>)/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>;        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern关于纵轴方向的位置,默认放在中间</span>
org_Y=(width-col*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>)/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>;             <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%pattern关于横轴方向的位置,默认放在中间</span>
  color1=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>;
     color2=color1;
img=<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">zeros</span>(row*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>,col*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:(row-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)
    color2=color1;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:(col-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> color2==<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>
        img(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">i</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>,<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>:(<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">j</span>+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)=color2;
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%不加的话,可以注释掉</span>
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">%</span>
        color2=~color2;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
    color1=~color1;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">end</span>
img_final(org_X:org_X+row*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>,org_Y:org_Y+col*<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">length</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>)=img;
   img_final=~img_final;
     figure;imshow(img_final);   
     imwrite(img_final, <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'cheesBoard.bmp'</span>,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'bmp'</span>);</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"></ul>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:90515次
    • 积分:1275
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:139篇
    • 译文:6篇
    • 评论:7条
    文章分类
    最新评论