Published on

Twincat Vision Edge Detection Performance and CPU sizing

Authors
  • avatar
    Name
    Kassym Dorsel
    Twitter

Introduction

With Beckhoff's new built in Vision system, all metrology can be done directly on the IPC itself. Sizing IPC power correctly is even more critical as some vision functions can take a lot of CPU cycles and depending on a machine's cycle time might not be able to complete in alloted time.

See this first vision post for an introduction about TwinCAT Vision and how I did initial setup.

Test Setup

These tests were run on a ThinkPad P52 running Windows 10 v1809 with TwinCAT 4024.12 and Tc3_Vision 4.0.1.0. Using an i7-8750H and 16GB ram. While running the tests the i7 was running at a speed of 4 GHz. The system was configured to use a total of 3 shared cores with a 90% limit. One core for the base vision task and one core for a vision job pool task. The third core ran the remaining tasks. The vision task was set to 200ms cycle.

CPU usage

The image is from a 5MP Smart Camera from Banner Engineering using an Opto-e telecentric lens.

All tests were run sequentially 100 times and minimum, average and maximum computation times were recorded for each dimension in micro seconds as well as its measurement result in pixels. Here are the five dimensions being measured in the image and their specific configurations. The pixel count is based on the inspection region, gap and lines. It is calculated as pixel = (to - from - gap) * lines.

NameStart PointEnd PointSearch GapSearch LinesLine DistancePixel Count
d201[115, 1290][640, 1290]420291330555
d209[245, 795][245, 1770]7804949555
d222[760, 875][760, 1700]6604547425
od[2260, 970][2260, 1650]680121420570
gripper[860, 450][1850, 450]792161531878
Test 4 results with erf

The tests were done using the F_VN_MeasureEdgeDistanceExp function. Here's the documentation on all the parameters used.

Tests with TCVN_EDA_APPROX_ERF

Test 1

Settings used.

NameValue
Min Strength50
Max Thickness10
Precision0.001
Subpixel Iteration10
AlgorithmTCVN_EDA_APPROX_ERF

Here are the results. The two vision cores where at approximately 10% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2014478480158650.16812.82
d2091525170022140.18959.33
d2221346151519530.20808.45
od3511390450760.19664.49
gripper6505711281220.22965.83

Test 2

Settings used.

NameValue
Min Strength50
Max Thickness10
Precision0.001
Subpixel Iteration100
AlgorithmTCVN_EDA_APPROX_ERF

Here are the results. The two vision cores where at approximately 45% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2012958530927355171.01812.46
d2091130211963138301.25957.96
d222972710362120271.39807.06
od2666527951308711.36662.95
gripper6782271886772612.25963.64

Test 3

Settings used.

NameValue
Min Strength50
Max Thickness10
Precision0.001
Subpixel Iteration1000
AlgorithmTCVN_EDA_APPROX_ERF

Here are the results. The two vision cores where at approximately 60% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2013431935816392841.17812.11
d2091441115085168071.58957.76
d2221199412568137761.69806.95
od3298433315375401.62662.92
gripper94861973241025033.05958.19

Test 4

Settings used.

NameValue
Min Strength50
Max Thickness10
Precision0.0001
Subpixel Iteration1000
AlgorithmTCVN_EDA_APPROX_ERF

Here are the results. The two vision cores where at approximately 85% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2015552857726620731.89812.11
d2092344524563277802.57957.76
d2222721428389312643.82806.95
od7579479117831043.85662.92
gripper1386091500591588364.71958.18
Test 4 results with erf

Tests with TCVN_EDA_INTERPOLATION

Test 1

Settings used.

NameValue
Min Strength50
Max Thickness10
Subpixel Iteration10
AlgorithmTCVN_EDA_INTERPOLATION

Here are the results. The two vision cores where at approximately 1% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2011316141620140.05812.32
d20934540310050.04958.71
d2222804126500.06807.82
od66978911680.04663.80
gripper1102126117370.04964.64

Test 2

Settings used.

NameValue
Min Strength50
Max Thickness10
Subpixel Iteration25
AlgorithmTCVN_EDA_INTERPOLATION

Here are the results. The two vision cores where at approximately 3% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2012027220330030.07812.32
d20956467611760.07959.20
d22250268413990.09808.36
od1251146124820.07664.32
gripper1794214131930.07964.93

Test 3

Settings used.

NameValue
Min Strength50
Max Thickness10
Subpixel Iteration50
AlgorithmTCVN_EDA_INTERPOLATION

Here are the results. The two vision cores where at approximately 5% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2013147336247120.11812.32
d2091021113515720.12959.19
d222917102015640.14808.36
od2095230934560.11664.46
gripper3059341347860.11965.00

Test 4

Settings used.

NameValue
Min Strength50
Max Thickness10
Subpixel Iteration100
AlgorithmTCVN_EDA_INTERPOLATION

Here are the results. The two vision cores where at approximately 10% spike load as seen in the Twincat real time online tab.

NameMin (us)Avg (us)Max (us)Avg / Pixel (us)Result in Pixels
d2015462586082000.19812.32
d2091792211130920.22959.19
d2221641191027660.26808.36
od3732428158200.21664.46
gripper5484620883130.19965.00
Test 4 results with interpolation

Analysis CPU

There is a lot of information to analyze, and this is only the tip of the vision iceberg. I only did edge finding and distance calculation using two different algorithms. Beckhoff vision has hundreds of different functions that can be used. In a future application once initial testing is completed the vision task cycle time should be set to be 10-20% larger than the maximum time a function takes to finish. This will reduce dead time waiting for the task to complete a cycle before getting the results back.

When sizing an IPC for vision application this is where the Average time / Pixel can be used to make an educated guess. Based on inspection requirements you will know camera resolution and thus approximate pixel count used in inspection. Keep in mind that these times are using two cores running at 4 GHz. Core speed should be pretty linear with a 2 GHz core taking twice the time. Core count (Job Pool Tasks) are perfectly linear given the overhead of parallelizing the jobs, but for sizing purposes can be taken as linear. Using a single core would therefore take twice the time.

Analysis Measurement

Each set of tests started with parameters which required less iterations, less CPU and potentially were less accurate. There is a reason I stopped increasing the iteration of the tests after four tries. If you look at the Result in Pixels column for the test you will see there is no difference between the third and fourth test. That is we have hit the limit of resolution that the original image allows. Increasing parameters from this point would give no benefit at all. I would also consider that the best accuracy of the system has been reached at that point.

The values I ended up with for subpixel iteration were 5-10 times larger than Beckhoff's highest recommended value and precision matched Beckhoff's highest recommended value.

Let's compare test 4 measurements of the two algorithms. I will disregard the difference for the gripper measurement since it is outside the telecentric field of depth and also has two gripper fingers on different planes. All the other measurements are done on the test piece.

Algorithmd201d209d222odgripper
TCVN_EDA_INTERPOLATION812.32959.19808.36664.46965.00
TCVN_EDA_APPROX_ERF812.11957.76806.95662.92958.18
Difference0.211.431.411.546.82

In this specific application the px mm ratio is 47.354px = 1mm. Between the two algorithms that would give a maximal difference of 0.03mm. This approximately follows the rule of thumb saying that a vision system's resolution should be 10 times better than the dimension resolution. In this application dimensions have 0.1mm tolerances.

Taking dimensions d209, d222 and od the delta between differences is 0.11px = 0.002mm. The px/mm ratio will be setup with one algorithm, meaning that for interpolation the ratio is 47.354 and for erf the ratio is 47.282. This gives another way to look at this is deviation over the measurements for each algorithm. This would more closely follow how it would be used since only one algorithm would be used in production.

See this blog about Beckhoff Vision and how it is not robust for why I left out d201 in the last number crunching. Spoiler, it's way off.

Conclusion

Even with a higher than recommended sub pixel iteration count, the Interpolation algorithm is an order of magnitude faster than the ERF algorithm. This is expected, but now it is quantifiable. The time / pixel for the ERF algorithm will likely be influenced by the edge quality in the image, while the interpolation less so.

There are many other edge finding algorithms out there, and Beckhoff does implement a few of them as specific methods and not part of dedicated metrology methods. This is an area of further investigation. As with everything, it will come down to the specific application.

Beckhoff's documentation states that ERF is more robust than Interpolation. This is an area that would need further investigation in a real world scenario. The testing done here was on a single static image. Thankfully both algorithms always gave the exact same results with the same input parameters over many runs on the same image. In production, there will be some differences in part alignment for each image and it would be interesting to see those results.

Good suppliers are always keen about helping you out with testing and verification of a process before any purchase when it comes to vision applications. I would highly recommend that this be done and develop the software algorithms from with the test images provided.