# Issue with Unwrapping Blob Data into Float Array After Using blobFromImage

**URL:** <https://forum.opencv.org/t/issue-with-unwrapping-blob-data-into-float-array-after-using-blobfromimage/14311>\
**Category:** Android/Java\
**Tags:** dnn\
**Created:** [August 21, 2023, 1:47pm UTC](https://forum.opencv.org/t/issue-with-unwrapping-blob-data-into-float-array-after-using-blobfromimage/14311 "2023-08-21T13:47:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umair\_Mukati](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/umair_mukati/32/8572_2.png) [@Umair\_Mukati](https://forum.opencv.org/u/Umair_Mukati)\
**Post date:** [August 21, 2023, 1:47pm UTC](https://forum.opencv.org/t/issue-with-unwrapping-blob-data-into-float-array-after-using-blobfromimage/14311/1 "2023-08-21T13:47:12Z")

</div>

**Hello OpenCV experts!**

I’m currently working on an Android Kotlin project where I’m dealing with a CV Mat that I’ve converted into a blob using the `blobFromImage` function. The purpose of this is to create a linear array by unwrapping in the H,C,W format, as required by a subsequent block of code. The process involves permuting the dimensions and then unwrapping them.

Here’s a summary of my approach:

1. Convert a CV Mat into a blob using `blobFromImage`.
2. Permute the dimensions to obtain the H,C,W format.
3. Attempt to unwrap the blob data using the `get` function into a float array.

The issue I’m facing is that even though the blob seems to contain non-zero values (as I can see in the original CV Mat), when I use the `get` function to unwrap the data into a float array, all the elements in the float array remain as 0.

I’ve considered an alternative approach of looping through the blob values and unwrapping them one by one, but I’m unsure about how to access the individual values within a blob using OpenCV functions.

Could anyone shed some light on why the `get` operation is not working as expected? Additionally, any guidance on how to correctly access and unwrap the values within a blob would be greatly appreciated. Here’s a snippet of my code for reference:

```auto
// Convert CV Mat into blob
val input = FloatArray(1*256*256*3)
var temp = Dnn.blobFromImage(imageMat)
Core.transposeND(temp, MatOfInt(0,2,1,3), temp)
temp.get(0, 0, input)

```

Thank you in advance for your help and insights!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 21, 2023, 2:04pm UTC](https://forum.opencv.org/t/issue-with-unwrapping-blob-data-into-float-array-after-using-blobfromimage/14311/2 "2023-08-21T14:04:31Z")

</div>

> [@Umair\_Mukati](#):
>
> the H,C,W format, as required by a subsequent block of code.

can you please explain, what kind of network this is, what it does, and why it expects this weird input format ?

> [@Umair\_Mukati](#):
>
> why the `get` operation is not working as expected?

what is happening ?

> [@Umair\_Mukati](#):
>
> how to correctly access and unwrap the values within a blob

i would understand, if this is for the output, but you should not need to access the blob’s values for the input, why you need that ?

---

<div class="post-metadata">

**Author:** ![Umair\_Mukati](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/umair_mukati/32/8572_2.png) [@Umair\_Mukati](https://forum.opencv.org/u/Umair_Mukati)\
**Post date:** [August 21, 2023, 4:57pm UTC](https://forum.opencv.org/t/issue-with-unwrapping-blob-data-into-float-array-after-using-blobfromimage/14311/3 "2023-08-21T16:57:43Z")

</div>

I appreciate your response and would like to address your questions and concerns:

> can you please explain, what kind of network this is, what it does, and why it expects this weird input format ?

Indeed, the chosen input format is unconventional. The specific model in use is shared across our team, and modifying the model’s input dimensions wasn’t considered to avoid disrupting other workflows.

> what is happening ?

The issue I’m facing is that even though the blob seems to contain non-zero values (as I can see in the original CV Mat), when I use the `get` function to unwrap the data into a float array, all the elements in the float array remain as 0.

> i would understand, if this is for the output, but you should not need to access the blob’s values for the input, why you need that ?

My initial thought was to use the `get` operation, which didn’t yield the expected results. As a potential workaround, I think about accessing blob values to create a customized “get” operation.

---

<div class="post-metadata">

**Author:** ![dranzerstar](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@dranzerstar](https://forum.opencv.org/u/dranzerstar)\
**Post date:** [March 27, 2024, 2:08am UTC](https://forum.opencv.org/t/issue-with-unwrapping-blob-data-into-float-array-after-using-blobfromimage/14311/4 "2024-03-27T02:08:47Z")

</div>

I am getting the same problem for unwarpping the blob and getting array full of 0s,  
my code to get it is

```auto
        val a = Math.toIntExact( blob.total())
        val rbuffer = FloatArray( a )
        blob.get(0, 0, rbuffer)

```

I tried printing stats of the Mat and it returns reasonable values

```auto
        val mean = MatOfDouble()
        val stdDev = MatOfDouble()
        Core.meanStdDev(blob, mean, stdDev);
        val meanValue = mean[0, 0][0]
        val stdDevValue = stdDev[0, 0][0]
        Log.d("retina","blob channels "+ blob.channels()+ " type "+ blob.type() + " size "+blob.size()+ " dim "+blob.dims())
        Log.d("retina","blob size "+ blob.size(0)+ " "+ blob.size(1) + " "+blob.size(2)+ " "+blob.size(3))
        Log.d("retina","blob sum "+ Core.sumElems(blob))
        Log.d("retina","blob mean,std $meanValue, $stdDevValue")

```

Debugg prints

```auto
 D blob channels 1 type 5 size 3x1 dim 4
 D blob size 1 3 640 640
 D blob sum [-304352.546875, 0.0, 0.0, 0.0]
 D blob mean,std -0.247682736714681, 0.4440458841118953

```
