|
发表于 2016-12-4 19:41:44
|
显示全部楼层
根据你的图形,选择电路板外的区域容易定位,分别找出其横竖坐标,交叉定位。你的网格粗细不一,所以结果如果按照相邻合并才会是6个。如果有变形,可以多选几个点计算斜率后定位。
- import win.ui;
- /*DSG{{*/
- var winform = win.form(text="定位演示";right=850;bottom=644;parent=...)
- winform.add(
- button={cls="button";text="定位";left=236;top=602;right=607;bottom=636;db=1;z=1};
- picGray={cls="plus";left=12;top=22;right=840;bottom=578;aw=1;db=1;dr=1;dt=1;edge=1;repeat="scale";z=2}
- )
- /*}}*/
- var calGray = function(num){
- var b,g,r = gdi.getRgb(num);
- return (77 * r + 151 * g + 28 * b) >> 8;
- }
- import console;
- import gdip;
- import inet.http;
- winform.button.oncommand = function(id,event){
- var bmp = gdip.bitmap(inet.http().get("http://www.smtstencil.cn/pictures/2016/12/MsIPaH.png") ,"*.png");
- var bmpdata = bmp.lockData32();
-
- tab_v = {};
- tab_h = {};
-
- var bits = bmpdata.bits;
- for(h=1;bmp.height){
- var row = bits.rows[h];
- for(w=1;bmp.width){
- var gray = calGray(row.pixels[w]);
- if(gray<120 and (h==5 or h==30)){
- tab_v[w]=1;
- }
- if(gray<120 and (w==10 or w=50)){
- tab_h[h]=1;
- }
- }
- }
-
- for(h=1;bmp.height){
- var row = bits.rows[h];
- for(w=1;bmp.width){
- if(tab_v[w] or tab_h[h]){
- row.pixels[w] = 0xffffffff;
- }
- }
- }
- for(m,n in tab_v){
- for(k,v in tab_h){
- console.log("交叉点:",m,k);
- }
- }
-
- bmp.unlockData(bmpdata);
-
- winform.picGray.setBackground( bmp )
- }
- winform.show();
- win.loopMessage();
复制代码 |
|