Skip to content

C#

C# 1

```csharp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using HalconDotNet;

class FreeRunLineGrabber2Phase
{
    static void Main()
    {
        const string IFace = "GigEVision2";
        const string Device = "RULER3200_01";    // <- Name/ID/IP obtained from enumeration
        const int    NumLines = 100;
        const string SavePath = @"C:\temp\stacked.tiff";

        HTuple acq = null;
        HObject[] lines = new HObject[NumLines];
        HObject concatenated = null;
        HObject tiled = null;

        try
        {
            // --- open & free-run ---
            HOperatorSet.OpenFramegrabber(
                IFace, 0,0,0,0,0,0, "default", -1, "default", -1, "false",
                "default", Device, 0, -1, out acq);
            HOperatorSet.SetFramegrabberParam(acq, "TriggerMode", "Off");
            HOperatorSet.GrabImageStart(acq, -1);

            // --- Phase 1: Acquisition only (held in an array) ---
            for (int i = 0; i < NumLines; i++)
            {
                HObject img;
                HOperatorSet.GrabImageAsync(out img, acq, -1);  // Assumes a 1-line image
                lines[i] = img; // Just hold it here without processing
            }

            // --- Phase 2: Concat & tile in a batch ---
            // 2-1) Concatenate into a multi-object with concat_obj
            HOperatorSet.GenEmptyObj(out concatenated);
            for (int i = 0; i < NumLines; i++)
            {
                HObject tmp;
                HOperatorSet.ConcatObj(concatenated, lines[i], out tmp);
                concatenated.Dispose();
                concatenated = tmp;
                lines[i].Dispose(); // Release each time
            }

            // 2-2) Stack vertically with tile_images (Rows=NumLines, Cols=1)
            HOperatorSet.TileImages(concatenated, out tiled, NumLines, 1);

            // --- Save ---
            HOperatorSet.WriteImage(tiled, "tiff", 0, SavePath);
            Console.WriteLine($"saved: {SavePath}");
        }
        finally
        {
            if (tiled != null) tiled.Dispose();
            if (concatenated != null) concatenated.Dispose();
            if (acq != null) HOperatorSet.CloseFramegrabber(acq);
        }
    }
}