halcon几个小知识点:通过点拟合椭圆;通过两个xld拟合椭圆


原图:

image.png

(图1)


想求出它的黑色边界,用来判断NG的部分。

如下图所示,蓝色线是勇哥想求的边界。红色箭头所指的是缺陷,它有两部分。

颜色较浅的灰色带和颜色深的黑色带,它们是两种类型的NG特征,其判断阈值是不同的。

image.png

(图2)


勇哥想到的几个方法:


(一) 通过边界xld拟合椭圆


设想是通过图3的两根xld,拟合出图4的椭圆。


image.png

(图3)


image.png

(图4)

dev_close_window()

read_image (Pic20200923105531Blockid9363, 'F:/blockId#9363.bmp')
gen_region_runs (ROI_0, [1295,1296,1297,1298,1299,1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1310,1311,1312,1313,\
1314,1315,1316,1317,1318,1319,1320,1321,1322,1323,1324,1325,1326,1327,1328,1329,1330,1331,1332,1333,1334,1335,1336,1337,\
1338,1339,1340,1341,1342,1343,1344,1345,1346,1347,1348,1349,1350,1351,1352,1353,1354,1355,1356,1357,1358,1359,1360,1361,\
1362,1363,1364,1365,1366,1367,1368,1369,1370,1371,1372,1373,1374,1375,1376,1377,1378,1379,1380,1381,1382,1383,1384,1385,\
1386,1387,1388,1389,1390,1391,1392,1393,1394,1395,1396,1397,1398,1399,1400,1401,1402,1403,1404,1405,1406,1407,1408,1409,\
1410,1411,1412,1413,1414,1415,1416,1417,1418,1419,1420,1421,1422,1423,1424,1425,1426,1427,1428,1429,1430,1431,1432,1433,\
1434,1435,1436,1437,1438,1439,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452,1453,1454,1455,1456,1457,\
1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471,1472,1473,1474,1475,1476,1477,1478,1479,1480,1481,\
1482,1483,1484,1485,1486,1487,1488,1489,1490,1491,1492,1493], [2611,2606,2571,2567,2561,2555,2549,2538,2534,2524,2520,\
2512,2507,2487,2483,2470,2470,2454,2452,2442,2437,2423,2418,2386,2382,2367,2366,2357,2349,2347,2345,2343,2340,2337,2335,\
2334,2334,2333,2331,2330,2330,2330,2329,2329,2329,2329,2329,2328,2328,2328,2328,2328,2328,2328,2328,2328,2328,2328,2328,2328,\
2328,2328,2328,2328,2328,2328,2328,2329,2329,2329,2329,2330,2331,2331,2331,2332,2332,2333,2333,2334,2334,2335,2336,2336,2337,\
2338,2338,2340,2341,2341,2342,2345,2348,2348,2355,2356,2356,2356,2357,2358,2358,2358,2358,2359,2359,2359,2360,2360,2361,2361,\
2363,2363,2363,2363,2363,2364,2365,2365,2366,2367,2367,2368,2368,2369,2369,2370,2371,2371,2371,2371,2372,2372,2373,2374,2375,\
2375,2376,2376,2377,2377,2378,2379,2380,2381,2381,2382,2383,2383,2384,2385,2385,2386,2386,2387,2387,2387,2388,2388,2389,2389,\
2386,2384,2384,2384,2384,2384,2384,2385,2385,2386,2386,2388,2390,2392,2395,2399,2401,2403,2404,2406,2408,2411,2413,2415,2417,\
2419,2421,2423,2425,2427,2430,2436,2444,2446,2457,2459,2468,2471,2490], [2639,2639,2639,2639,2639,2639,2639,2639,2639,2639,\
2639,2639,2639,2639,2639,2639,2639,2639,2639,2639,2639,2639,2638,2637,2636,2636,2634,2634,2634,2634,2634,2634,2634,2634,2634,\
2634,2634,2634,2634,2634,2634,2634,2634,2634,2634,2634,2634,2634,2634,2634,2633,2633,2632,2631,2628,2627,2627,2625,2625,2625,\
2625,2625,2624,2624,2624,2624,2624,2623,2622,2620,2619,2618,2616,2614,2613,2611,2610,2609,2609,2609,2608,2608,2607,2606,2605,\
2604,2603,2603,2603,2602,2602,2602,2602,2602,2601,2601,2601,2600,2600,2600,2600,2599,2598,2598,2597,2597,2597,2596,2596,2596,\
2596,2596,2596,2596,2596,2595,2595,2595,2595,2595,2594,2594,2594,2594,2594,2594,2594,2593,2593,2593,2593,2593,2592,2592,2592,\
2592,2591,2591,2591,2591,2590,2590,2590,2590,2590,2589,2589,2589,2589,2589,2588,2588,2588,2588,2587,2587,2587,2586,2586,2585,\
2585,2584,2584,2583,2583,2582,2582,2581,2580,2580,2579,2579,2578,2577,2576,2576,2575,2574,2574,2573,2573,2572,2571,2570,2569,\
2568,2568,2567,2566,2566,2565,2565,2564,2563,2561,2558,2557,2553,2551])

reduce_domain(Pic20200923105531Blockid9363, ROI_0, ImageReduced)

dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
dev_set_draw('margin')

dev_display(ImageReduced)

fast_threshold(ImageReduced, Region, 110, 255, 88)
reduce_domain(Pic20200923105531Blockid9363, Region, ImageReduced1)
edges_sub_pix(ImageReduced1, Edges, 'canny', 1, 7, 80)

*合并相邻的xld
union_cotangential_contours_xld(Edges, UnionContours, 5, 2, 0.685398, 5, 2, 2, 'attr_forget')
select_contours_xld(UnionContours, SelectedContours, 'contour_length', 65, 66200, -0.5, 0.5)

*合并图3所示的两根xld
union_cocircular_contours_xld(SelectedContours, UnionContours1, 322.5, 550.1, 0.2, 230, 310, 310, 'true', 1)
*拟合椭圆
fit_ellipse_contour_xld(UnionContours1, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row1, Column1, Phi1, Radius11, Radius2, StartPhi, EndPhi, PointOrder)
disp_ellipse(WindowHandle, Row1, Column1, Phi1, Radius11, Radius21)

这个设想其实效果并不好,因为无法精确控制筛选xld。


(二) 使用采样点拟合椭圆

这个是假设蓝色线是个椭圆。


通过fast_threshold算子后得到我们想要的图2所示的蓝色边界。

如下图

image.png

(图5)


然后通过个几个采样点生成轮廓,再由轮廓拟合出椭圆。

采样点手工通过几个测量框生成,实际使用可以考虑自动生成。


image.png

xary:=[1376.96,1366.67,1357.64,1327.61,1327.5,1330.55,1334.79,1344.74]
yary:=[2363.29,2378.38,2394.81,2508.98,2532.1,2557.15,2576.1,2597.18]
*通过点拟合出Contour,再拟合出椭圆
gen_contour_polygon_xld(Contour, xary, yary)
fit_ellipse_contour_xld(Contour, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius21, StartPhi1, EndPhi1, PointOrder1)

disp_ellipse(WindowHandle, Row, Column, Phi, Radius1, Radius21)


下图是拟合出来的椭圆。

接下来我们把图割出来,就可以得到我们样的NG区域了。

image.png



--------------------- 

作者:hackpig
来源:
www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!



本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864