# Parsing the line count out of a StreamImage from a Linea camera

**URL:** <https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797>\
**Category:** .Net API\
**Tags:** acquisition, gigevision\
**Created:** [May 29, 2019, 9:57am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797 "2019-05-29T09:57:03Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [June 5, 2019, 6:33pm UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/21 "2019-06-05T18:33:44Z")

</div>

@Theo told me that the Linea overwrites data pixels with the meta information. So this is normal.

Linear Access does not really work well in this case. Marshal is a bit slow. Pointer access (unsafe) would be faster.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.commonvisionblox.com/u/Ben)\
**Post date:** [June 6, 2019, 5:38am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/22 "2019-06-06T05:38:12Z")

</div>

> [@parsd](#):
>
> @Theo told me that the Linea overwrites data pixels with the meta information. So this is normal.

❤

> [@parsd](#):
>
> Linear Access does not really work well in this case. Marshal is a bit slow. Pointer access (unsafe) would be faster.

Where do I find the pointer, starting from the Image? Do you mean the Access.BasePtr, or something else?

* * *

I think I’ve just had a eureka moment. The data that I’m seeing ‘between’ the pixels (when I access with Marshal) is the data from the other Planes. Is that correct?

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [June 6, 2019, 7:58am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/23 "2019-06-06T07:58:19Z")

</div>

Basically pointer access on :cvb: images looks like this:

```auto
unsafe
{
  var pBase = (byte*)access.BasePtr;
	
  var line = 42;
  var pLine = pBase + line * (long)access.YInc;
}

```

As the metadata overwrites the actual pixel data, you can “jump” one line below the metadata to access and subtract the metadata size (was it 8 bytes?):

```auto
[StructLayout(LayoutKind.Sequential, Pack = 4)]
struct MetaData
{
  public uint FrameCounter;
  public uint CameraID;
	
  public static unsafe MetaData FromLine(LinearAccessData access, int line)
  {
    var pData = (byte*)access.BasePtr + (line + 1) * (long)access.YInc - sizeof(MetaData);
    return *(MetaData*)pData;
  }
}

```

This is only correct, though, if there is no additional padding. But the data you provided shows that there is none.

```auto

```

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.commonvisionblox.com/u/Ben)\
**Post date:** [June 6, 2019, 8:01am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/24 "2019-06-06T08:01:05Z")

</div>

I don’t think I can mark two answers in one topic as an answer, but … this is an answer 🙂

I don’t actually need every line as I’m just looking at FrameCount (at the moment), but this could come in handy later, and in any case for someone else it will probably be exactly what they need. Thanks. Again.

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [June 6, 2019, 8:26am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/25 "2019-06-06T08:26:00Z")

</div>

So far none is marked 😉. Choose the one you prefer ❤.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.commonvisionblox.com/u/Ben)\
**Post date:** [June 6, 2019, 8:34am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/26 "2019-06-06T08:34:30Z")

</div>

There’s a slight bug actually, you need to multiply `sizeof(MetaData)` by access.IncX to get the right offset, so:

```
var pData = (byte*)access.BasePtr + (int)access.YInc 
                                     - (sizeof(MetaData) * (int)access.XInc);
```

---

<div class="post-metadata">

**Author:** ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)\
**Post date:** [June 6, 2019, 8:37am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/27 "2019-06-06T08:37:51Z")

</div>

That would imply either padding or that there is even more data to the right of the desired meta data.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://forum.commonvisionblox.com/u/Ben)\
**Post date:** [June 6, 2019, 8:40am UTC](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797/28 "2019-06-06T08:40:02Z")

</div>

You’re right, that’s strange, now I’ve got to work out why that works and the other one doesn’t for me ☹

* * *

OK, this is weird2, you’re right about the padding:

![image](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/b36f05a8a4708b63939582429b56659f7b3e187e.png)

`endOfLineMetadataPixelCount` says 8 pixels, but as you can see from the image above, even though the camera reserves 8 pixels for the meta data, it actually just offsets 8 pixels (so 8 x 3 bytes) from the end, and then writes the two uints directly into the data, so the FrameCounter and CameraId effectively occupy the first and second pixels, and two bytes of the third pixel.

```
              px1 px2 px3 px4 px5 px6 px7 px8
              R G B R G B R G B R G B R G B R G B R G B R G B
FrameCounter x x x x 
CameraId x x x x

```

This is confirmed by the fact that the code as above also correctly parses out the CameraId.

So it was just ‘coincidence’ that `sizeof(MetaData)` and `endOfLineMetaDataPixelCount` were both 8, but one is 8 _bytes_ and the other is 8 _pixels_.

[Previous page](https://forum.commonvisionblox.com/t/parsing-the-line-count-out-of-a-streamimage-from-a-linea-camera/797.md?page=1)
