Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

imaq C byte alignment

Hello,

 

I am using a linear CCD camera which enables 8, 10 and 12 bits acquisition. The camera is currently set to 12 bits, and I am retrieving the data from a C program, compiled against imaq.lib, with the functions defined in niimaq.h.

 

However, I can't figure out exactly how the data is encoded in the output array. The call is to imgGrab(Sid, &ImaqBuffer, TRUE), where ImaqBuffer is Int8 *, and therefore the 2048 pixels of the camera are encoded in a 4096 times 8 bits array.

Now I was assuming that the 12 bits are encoded such that ImaqBuffer[2*i] corresponds to the MSBs, and ImaqBuffer[2*i+1] to the LSBs, and therefore (((ImaqBuffer[2*i] << 😎 | ((ImaqBuffer[2*i+1])) ) >> 4) & 0xFFF would represent the actual pixel value.

 

But all values retrieved this way are multiple of 4, which means that either I'm doing it wrong, or the output is only 8 bits.

I haven't found this information in the docs, but perhaps I got a bit lost in it.... so any help would be greatly appreciated.

 

Thanks,

 

0 Kudos
Message 1 of 6
(5,145 Views)

Try treating the value as a 16 bit value to begin with.  Get rid of the shift on the LSB and the and with 0xFFF.  Take a look at those values and you will be able to figure out how it work.  I would expect 8 bits of data in the LSB and 4 in the MSB, which is the opposite of how you did it.

 

Bruce

Bruce Ammons
Ammons Engineering
Message 2 of 6
(5,133 Views)

@BruceAmmons wrote:

Try treating the value as a 16 bit value to begin with.  Get rid of the shift on the LSB and the and with 0xFFF.  Take a look at those values and you will be able to figure out how it work.  I would expect 8 bits of data in the LSB and 4 in the MSB, which is the opposite of how you did it.

 

Bruce


Thanks for your answer.

I get apparently good values by using only a 8 bits shift of the MSB followed by a OR on the LSB with (ImaqBuffer[2*i] << 😎 | ImaqBuffer[2*i+1].

However, I systematically get overflows when too much power reaches the camera (signal is returning to 0). But I hardly see why the numbers don't fit on these two 8 bits registers (the camera is supposed to support 10 and 12 bits per pixels). Any clue?

0 Kudos
Message 3 of 6
(4,977 Views)

I don't quite understand.  It sounds like you are getting good values most of the time.

 

What do you mean "too much power reaches the camera"?  Are you talking about the power supply for the camera?  Are you talking about too much light?  It just doesn't make sense.

 

Maybe you need to swap the high and low bytes?  Very hard to diagnose without pictures or data.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 4 of 6
(4,969 Views)

@BruceAmmons wrote:

I don't quite understand.  It sounds like you are getting good values most of the time.

 

What do you mean "too much power reaches the camera"?  Are you talking about the power supply for the camera?  Are you talking about too much light?  It just doesn't make sense.

 

Maybe you need to swap the high and low bytes?  Very hard to diagnose without pictures or data.

 

Bruce


Hello,

 

Sorry for the unclear comment. I meant "optical power".

You were right, the low and high bytes had to be swapped, and the following works: (ImaqBuffer[2*i+1] << 😎 | (ImaqBuffer[2*i] & 0xFF)

Not too sure why the & 0xFF is required here, though.

 

Thank you,

0 Kudos
Message 5 of 6
(4,961 Views)

Like Bruce's original suggestion, why bother with bytes at all? Why not allocate or cast the pointer as an array of 16-bit integers instead so you don't need to do any of this manipulation? It is certainly going to be slower your way.

0 Kudos
Message 6 of 6
(4,955 Views)